| 215 | } |
| 216 | |
| 217 | void 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. |
| 271 | void test_destinationSpecificPaths() { |
nothing calls this directly
no test coverage detected