6 #include <ccan/aga/aga.h>
8 #include <ccan/tap/tap.h>
10 #include "simple-graph.h"
12 static void test_adjacency(const char *name,
13 const struct simple_graph *sg,
14 const struct adjacency_list *at)
18 for (i = 0; at[i].from != 0; i++) {
20 struct aga_edge_info ei;
22 const struct aga_node *from;
25 assert(i < MAX_NODES);
27 from = &sg->nodes[at[i].from];
29 aga_for_each_edge_info(e, ei, err, &sg->g, from) {
30 const struct aga_node *cmpto;
32 assert(j < MAX_EDGES);
33 cmpto = &sg->nodes[at[i].to[j]];
35 "%s: %p #%d -> #%ld (expected #%d -> #%d)", name, e,
36 at[i].from, (ei.to - sg->nodes),
37 at[i].from, at[i].to[j]);
41 if (at[i].to[j] < 0) {
42 ok(err == at[i].to[j], "%s: %p #%d -> ERROR %d",
43 name, e, at[i].from, at[i].to[j]);
44 continue; /* Move onto next node on errors */
48 assert(j < MAX_EDGES);
50 "%s: %p #%d -> --- (expected #%d -> #%d)", name, e,
51 at[i].from, at[i].from, at[i].to[j]);
57 struct trivial_graph tg;
58 struct parallel_graph pg;
60 struct chain_graph cg;
61 struct grid_graph gg1, gg2;
62 struct error_graph eg;
63 struct traversal1_graph t1g;
64 struct shortcut1_graph s1g;
65 struct shortcut2_graph s2g;
66 struct negacycle_graph ng;
68 plan_tests(2 + 7 + 35 + 30 + 30 + 42 + 9 + 30 + 9 + 9 + 9);
70 trivial_graph_init(&tg);
71 test_adjacency("trivial", &tg.sg, trivial_adjacency);
73 parallel_graph_init(&pg, 3, 0);
74 test_adjacency("parallel nlinks 3", &pg.sg,
75 parallel_adjacency_nlinks3);
77 full_graph_init(&fg, 5);
78 test_adjacency("full 5", &fg.sg, full_adjacency_5);
80 chain_graph_init(&cg, 8);
81 test_adjacency("chain 8", &cg.fg.sg, chain_adjacency_8);
83 grid_graph_init(&gg1, 3, 3, true, true, false, false);
84 test_adjacency("grid 3x3 right-down", &gg1.sg,
85 grid_adjacency_3x3_rightdown);
87 grid_graph_init(&gg2, 3, 3, true, true, true, true);
88 test_adjacency("grid 3x3 all", &gg2.sg,
89 grid_adjacency_3x3_all);
91 error_graph_init(&eg);
92 test_adjacency("error graph", &eg.sg, error_adjacency);
94 traversal1_graph_init(&t1g);
95 test_adjacency("traversal1 graph", &t1g.sg, traversal1_adjacency);
97 shortcut1_graph_init(&s1g);
98 test_adjacency("shortcut1 graph", &s1g.sg, shortcut1_adjacency);
100 shortcut2_graph_init(&s2g);
101 test_adjacency("shortcut2 graph", &s2g.sg, shortcut2_adjacency);
103 negacycle_graph_init(&ng);
104 test_adjacency("negacycle graph", &ng.sg, negacycle_adjacency);
106 return exit_status();