MCPcopy Create free account
hub / github.com/comaps/comaps / UNIT_TEST

Function UNIT_TEST

libs/storage/storage_tests/simple_tree_test.cpp:5–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include "storage/country_tree.hpp"
4
5UNIT_TEST(CountryTree_Smoke)
6{
7 using Tree = storage::CountryTree::Node;
8 using Value = storage::Country;
9
10 Tree tree(Value("0"), nullptr);
11
12 tree.AddAtDepth(1, Value("4"));
13 tree.AddAtDepth(1, Value("3"));
14 tree.AddAtDepth(1, Value("5"));
15 tree.AddAtDepth(1, Value("2"));
16 tree.AddAtDepth(1, Value("1"));
17 tree.AddAtDepth(2, Value("20"));
18 tree.AddAtDepth(2, Value("10"));
19 tree.AddAtDepth(2, Value("30"));
20
21 // children test
22 TEST_EQUAL(tree.Child(0).Value().Name(), "4", ());
23 TEST_EQUAL(tree.Child(1).Value().Name(), "3", ());
24 TEST_EQUAL(tree.Child(2).Value().Name(), "5", ());
25 TEST_EQUAL(tree.Child(3).Value().Name(), "2", ());
26 TEST_EQUAL(tree.Child(4).Value().Name(), "1", ());
27 TEST_EQUAL(tree.Child(4).Child(0).Value().Name(), "20", ());
28 TEST_EQUAL(tree.Child(4).Child(1).Value().Name(), "10", ());
29 TEST_EQUAL(tree.Child(4).Child(2).Value().Name(), "30", ());
30
31 // parent test
32 TEST(!tree.HasParent(), ());
33 TEST(!tree.Child(0).Parent().HasParent(), ());
34 TEST_EQUAL(tree.Child(4).Child(0).Parent().Value().Name(), "1", ());
35 TEST_EQUAL(tree.Child(4).Child(2).Parent().Value().Name(), "1", ());
36
37 size_t count = 0;
38 auto countCallback = [&count](Tree const &) { ++count; };
39 tree.ForEachChild(countCallback);
40 TEST_EQUAL(count, 5, ());
41
42 count = 0;
43 tree.ForEachDescendant(countCallback);
44 TEST_EQUAL(count, 8, ());
45
46 count = 0;
47 tree.Child(4).Child(0).ForEachAncestorExceptForTheRoot(countCallback);
48 TEST_EQUAL(count, 1, ());
49}

Callers

nothing calls this directly

Calls 11

TESTFunction · 0.85
AddAtDepthMethod · 0.80
ChildMethod · 0.80
ParentMethod · 0.80
ForEachChildMethod · 0.80
ForEachDescendantMethod · 0.80
ValueClass · 0.50
NameMethod · 0.45
ValueMethod · 0.45
HasParentMethod · 0.45

Tested by

no test coverage detected