| 342 | } |
| 343 | |
| 344 | void test_path() { |
| 345 | Path *path = Path_New(3); |
| 346 | Path *clone; |
| 347 | Node *n; |
| 348 | Edge *e; |
| 349 | |
| 350 | // Path should be empty. |
| 351 | TEST_ASSERT(Path_NodeCount(path) == 0); |
| 352 | TEST_ASSERT(Path_EdgeCount(path) == 0); |
| 353 | TEST_ASSERT(Path_Len(path) == 0); |
| 354 | |
| 355 | // Populate path. |
| 356 | Node ns[3]; |
| 357 | Edge es[2]; |
| 358 | for (uint i = 0; i < 2; i++) { |
| 359 | ns[i].id = i; |
| 360 | |
| 361 | es[i].id = i; |
| 362 | es[i].src_id = i; |
| 363 | es[i].dest_id = i + 1; |
| 364 | } |
| 365 | ns[2].id = 2; |
| 366 | |
| 367 | for (uint i = 0; i < 2; i++) { |
| 368 | Path_AppendNode(path, ns[i]); |
| 369 | Path_AppendEdge(path, es[i]); |
| 370 | } |
| 371 | Path_AppendNode(path, ns[2]); |
| 372 | |
| 373 | TEST_ASSERT(Path_NodeCount(path) == 3); |
| 374 | TEST_ASSERT(Path_EdgeCount(path) == 2); |
| 375 | TEST_ASSERT(Path_Len(path) == 2); |
| 376 | |
| 377 | // Make sure all nodes and edges are in path. |
| 378 | for (uint i = 0; i < 2; i++) { |
| 379 | n = Path_GetNode(path, i); |
| 380 | TEST_ASSERT(n->id == i); |
| 381 | e = Path_GetEdge(path, i); |
| 382 | TEST_ASSERT(e->id == i); |
| 383 | } |
| 384 | n = Path_GetNode(path, 2); |
| 385 | TEST_ASSERT(n->id == 2); |
| 386 | |
| 387 | clone = Path_Clone(path); |
| 388 | // Make sure all nodes and edges are in path. |
| 389 | for (uint i = 0; i < 2; i++) { |
| 390 | n = Path_GetNode(clone, i); |
| 391 | TEST_ASSERT(n->id == i); |
| 392 | e = Path_GetEdge(clone, i); |
| 393 | TEST_ASSERT(e->id == i); |
| 394 | } |
| 395 | n = Path_GetNode(clone, 2); |
| 396 | TEST_ASSERT(n->id == 2); |
| 397 | |
| 398 | Node head = Path_Head(path); |
| 399 | TEST_ASSERT(head.id == 2); |
| 400 | |
| 401 | Path_Reverse(path); |
nothing calls this directly
no test coverage detected