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;
65 plan_tests(2 + 7 + 35 + 30 + 30 + 42 + 9 + 30);
67 trivial_graph_init(&tg);
68 test_adjacency("trivial", &tg.sg, trivial_adjacency);
70 parallel_graph_init(&pg, 3);
71 test_adjacency("parallel nlinks 3", &pg.sg,
72 parallel_adjacency_nlinks3);
74 full_graph_init(&fg, 5);
75 test_adjacency("full 5", &fg.sg, full_adjacency_5);
77 chain_graph_init(&cg, 8);
78 test_adjacency("chain 8", &cg.fg.sg, chain_adjacency_8);
80 grid_graph_init(&gg1, 3, 3, true, true, false, false);
81 test_adjacency("grid 3x3 right-down", &gg1.sg,
82 grid_adjacency_3x3_rightdown);
84 grid_graph_init(&gg2, 3, 3, true, true, true, true);
85 test_adjacency("grid 3x3 all", &gg2.sg,
86 grid_adjacency_3x3_all);
88 error_graph_init(&eg);
89 test_adjacency("error graph", &eg.sg, error_adjacency);
91 traversal1_graph_init(&t1g);
92 test_adjacency("traversal1 graph", &t1g.sg, traversal1_adjacency);