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 */
46 assert(j < MAX_EDGES);
48 "%s: %p #%d -> --- (expected #%d -> #%d)", name, e,
49 at[i].from, at[i].from, at[i].to[j]);
55 struct trivial_graph tg;
56 struct parallel_graph pg;
58 struct chain_graph cg;
59 struct grid_graph gg1, gg2;
60 struct error_graph eg;
61 struct traversal1_graph t1g;
63 plan_tests(1 + 5 + 30 + 22 + 21 + 33 + 6 + 21);
65 trivial_graph_init(&tg);
66 test_adjacency("trivial", &tg.sg, trivial_adjacency);
68 parallel_graph_init(&pg, 3);
69 test_adjacency("parallel nlinks 3", &pg.sg,
70 parallel_adjacency_nlinks3);
72 full_graph_init(&fg, 5);
73 test_adjacency("full 5", &fg.sg, full_adjacency_5);
75 chain_graph_init(&cg, 8);
76 test_adjacency("chain 8", &cg.fg.sg, chain_adjacency_8);
78 grid_graph_init(&gg1, 3, 3, true, true, false, false);
79 test_adjacency("grid 3x3 right-down", &gg1.sg,
80 grid_adjacency_3x3_rightdown);
82 grid_graph_init(&gg2, 3, 3, true, true, true, true);
83 test_adjacency("grid 3x3 all", &gg2.sg,
84 grid_adjacency_3x3_all);
86 error_graph_init(&eg);
87 test_adjacency("error graph", &eg.sg, error_adjacency);
89 traversal1_graph_init(&t1g);
90 test_adjacency("traversal1 graph", &t1g.sg, traversal1_adjacency);