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

Function test_twoLegPaths

tests/unit/test_all_paths.c:217–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void test_twoLegPaths() {
218 Graph *g = BuildGraph();
219
220 NodeID src_id = 0;
221 Node src;
222 Path *path = NULL;
223 Graph_GetNode(g, src_id, &src);
224 unsigned int minLen = 2;
225 unsigned int maxLen = 2;
226 unsigned int pathsCount = 0;
227 int relationships[] = {GRAPH_NO_RELATION};
228 AllPathsCtx *ctx = AllPathsCtx_New(&src, NULL, g, relationships, 1,
229 GRAPH_EDGE_DIR_OUTGOING, minLen, maxLen, NULL, NULL, 0, false);
230 /* Connections:
231 * 0 -> 1
232 * 0 -> 2
233 * 1 -> 0
234 * 1 -> 2
235 * 2 -> 1
236 * 2 -> 3
237 * 3 -> 0 */
238 NodeID p0[3] = {0, 1, 0};
239 NodeID p1[3] = {0, 1, 2};
240 NodeID p2[3] = {0, 2, 1};
241 NodeID p3[3] = {0, 2, 3};
242 NodeID *expectedPaths[4] = {p0, p1, p2, p3};
243
244 while((path = AllPathsCtx_NextPath(ctx))) {
245 TEST_ASSERT(pathsCount < 4);
246 TEST_ASSERT(Path_Len(path) == 2);
247 bool expectedPathFound = false;
248
249 for(int i = 0; i < 4; i++) {
250 NodeID *expectedPath = expectedPaths[i];
251 int j;
252 for(j = 0; j < 3; j++) {
253 Node n = path->nodes[j];
254 if(ENTITY_GET_ID(&n) != expectedPath[j]) break;
255 }
256 expectedPathFound = (j == 3);
257 if(expectedPathFound) break;
258 }
259
260 TEST_ASSERT(expectedPathFound);
261 pathsCount++;
262 }
263
264 TEST_ASSERT(pathsCount == 4);
265
266 AllPathsCtx_Free(ctx);
267 Graph_Free(g);
268}
269
270// Test all paths from source to a specific destination node.
271void test_destinationSpecificPaths() {

Callers

nothing calls this directly

Calls 7

Graph_GetNodeFunction · 0.85
AllPathsCtx_NewFunction · 0.85
AllPathsCtx_NextPathFunction · 0.85
Path_LenFunction · 0.85
AllPathsCtx_FreeFunction · 0.85
Graph_FreeFunction · 0.85
BuildGraphFunction · 0.70

Tested by

no test coverage detected