2 #include "../../src/connection.h"
3 #include "../../src/node.h"
4 #include "../../src/xalloc.h"
6 extern void sssp_bfs(void);
8 static void connect_nodes(node_t *from, node_t *to, int weight) {
9 edge_t *direct = new_edge();
12 direct->weight = weight;
15 edge_t *reverse = new_edge();
18 reverse->weight = weight;
22 static node_t *make_node(const char *name) {
23 node_t *node = new_node(name);
24 node->status.reachable = true;
29 static void test_sssp_bfs(void **state) {
32 node_t *mars = make_node("mars");
33 node_t *saturn = make_node("saturn");
34 node_t *neptune = make_node("neptune");
37 // myself ------ mars ------------- neptune
39 // ----------------- saturn ----
43 connect_nodes(myself, mars, 50);
44 connect_nodes(mars, neptune, 1000);
47 connect_nodes(myself, saturn, 500);
48 connect_nodes(saturn, neptune, 10);
52 assert_true(mars->status.visited);
53 assert_true(saturn->status.visited);
54 assert_true(neptune->status.visited);
56 assert_false(mars->status.indirect);
57 assert_false(saturn->status.indirect);
58 assert_false(neptune->status.indirect);
60 assert_int_equal(1, mars->distance);
61 assert_int_equal(1, saturn->distance);
62 assert_int_equal(2, neptune->distance);
64 assert_ptr_equal(mars, mars->nexthop);
65 assert_ptr_equal(saturn, saturn->nexthop);
66 assert_ptr_equal(saturn, neptune->nexthop);
68 assert_ptr_equal(lookup_edge(myself, mars), mars->prevedge);
69 assert_ptr_equal(lookup_edge(myself, saturn), saturn->prevedge);
70 assert_ptr_equal(lookup_edge(saturn, neptune), neptune->prevedge);
72 assert_ptr_equal(mars, mars->via);
73 assert_ptr_equal(saturn, saturn->via);
74 assert_ptr_equal(neptune, neptune->via);
77 static int setup(void **state) {
79 myself = new_node("myself");
83 static int teardown(void **state) {
92 const struct CMUnitTest tests[] = {
93 cmocka_unit_test_setup_teardown(test_sssp_bfs, setup, teardown),
95 return cmocka_run_group_tests(tests, NULL, NULL);