summaryrefslogtreecommitdiff
path: root/tests/tree.cpp
blob: ca57a17f2c224596e34ccde1b2f79aa07fd1d641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <forstio/test/suite.h>
#include <forstio/core/tree.h>

namespace {
SAW_TEST("Tree insert"){
	using namespace saw;

	tree<int> troi;
	{
		// Replace with value
		auto eor = troi.replace_branch(5);

		SAW_EXPECT(eor.is_value(), "Didn't manage to replace with value");
	}
	{
		// Replace with branch again
		auto eor = troi.replace_value(branch<int>{});

		SAW_EXPECT(eor.is_value(), "Not a value");
	}
}

SAW_TEST("Tree add child"){
	using namespace saw;

	branch<int> tr;
	{
		auto eov = tr.add(10);
		SAW_EXPECT(eov.is_value(), "Didn't manage to add value");
	}
	{
		auto eov = tr.add();
		SAW_EXPECT(eov.is_value(), "Didn't manage to add branch");
		std::size_t index = eov.get_value();

		auto& inner_tr = tr.at(index);

		auto eov2 = inner_tr.get_branch().add(420);
		SAW_EXPECT(eov2.is_value(), "Didn't manage to add to inner branch");
	}
}
}