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

Function test_upToThreeLegsPaths

tests/unit/test_all_paths.c:140–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140void test_upToThreeLegsPaths() {
141 Graph *g = BuildGraph();
142
143 NodeID src_id = 0;
144 Node src;
145 Graph_GetNode(g, src_id, &src);
146
147 Path *path = NULL;
148 unsigned int minLen = 0;
149 unsigned int maxLen = 3;
150 uint pathsCount = 0;
151 int relationships[] = {GRAPH_NO_RELATION};
152 AllPathsCtx *ctx = AllPathsCtx_New(&src, NULL, g, relationships, 1,
153 GRAPH_EDGE_DIR_OUTGOING, minLen, maxLen, NULL, NULL, 0, false);
154
155 /* Connections:
156 * 0 -> 1
157 * 0 -> 2
158 * 1 -> 0
159 * 1 -> 2
160 * 2 -> 1
161 * 2 -> 3
162 * 3 -> 0 */
163
164 // Zero leg paths.
165 NodeID p0[2] = {0, 0};
166
167 // One leg paths.
168 NodeID p1[3] = {1, 0, 1};
169 NodeID p2[3] = {1, 0, 2};
170
171 // Two leg paths.
172 NodeID p3[4] = {2, 0, 1, 0};
173 NodeID p4[4] = {2, 0, 1, 2};
174 NodeID p5[4] = {2, 0, 2, 1};
175 NodeID p6[4] = {2, 0, 2, 3};
176
177 // Three leg paths.
178 NodeID p7[5] = {3, 0, 1, 2, 1};
179 NodeID p8[5] = {3, 0, 1, 2, 3};
180 NodeID p9[5] = {3, 0, 2, 1, 0};
181 NodeID p10[5] = {3, 0, 2, 1, 2};
182 NodeID p11[5] = {3, 0, 2, 3, 0};
183
184 NodeID *expectedPaths[12] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11};
185
186 while((path = AllPathsCtx_NextPath(ctx))) {
187 bool expectedPathFound = false;
188 assert(pathsCount < 12);
189
190 // Try to match a path.
191 for(int i = 0; i < 12; i++) {
192 NodeID *expectedPath = expectedPaths[i];
193 size_t expectedPathLen = expectedPath[0];
194 expectedPath++; // Skip path length.
195
196 if(Path_Len(path) != expectedPathLen) continue;
197

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