MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_BFSLevels

Function test_BFSLevels

tests/unit/test_bfs.c:61–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61void test_BFSLevels() {
62 QGNode *S; // BFS starts here.
63 QGNode **nodes; // Nodes reached by BFS.
64 QueryGraph *g; // Graph traversed.
65 int level = 0; // BFS stops when reach level depth.
66
67 g = BuildGraph();
68 // S = QueryGraph_GetNodeByID(g, A->id);
69 S = A;
70
71 QGNode *expected_level_0[1] = {A};
72 QGNode *expected_level_1[1] = {B};
73 QGNode *expected_level_2[2] = {C, D};
74 QGNode *expected_level_3[0];
75 QGNode *expected_level_deepest[2] = {C, D};
76
77 QGNode **expected[4] = {
78 expected_level_0,
79 expected_level_1,
80 expected_level_2,
81 expected_level_3
82 };
83
84 //------------------------------------------------------------------------------
85 // BFS depth 0 - 3
86 //------------------------------------------------------------------------------
87
88
89 for(; level < 4; level++) {
90 nodes = BFS(S, &level);
91 QGNode **expectation = expected[level];
92
93 int node_count = array_len(nodes);
94 for(int i = 0; i < node_count; i++) {
95 bool found = false;
96 for(int j = 0; j < node_count; j++) {
97 if(nodes[i] == expectation[j]) {
98 found = true;
99 break;
100 }
101 }
102 TEST_ASSERT(found);
103 }
104
105 array_free(nodes);
106 }
107
108 //------------------------------------------------------------------------------
109 // BFS depth BFS_LOWEST_LEVEL
110 //------------------------------------------------------------------------------
111
112 level = BFS_LOWEST_LEVEL;
113 nodes = BFS(S, &level);
114
115 // Determine number of expected nodes.
116 int expected_node_count = sizeof(expected_level_deepest) / sizeof(expected_level_deepest[0]);
117 TEST_ASSERT(expected_node_count == array_len(nodes));
118

Callers

nothing calls this directly

Calls 5

BFSFunction · 0.85
array_lenFunction · 0.85
array_freeFunction · 0.85
QueryGraph_FreeFunction · 0.85
BuildGraphFunction · 0.70

Tested by

no test coverage detected