6 #include <ccan/agar/agar.h>
7 #include <ccan/ptrint/ptrint.h>
9 #include <ccan/tap/tap.h>
11 #include "simple-graphr.h"
13 static void test_adjacency(const char *name,
14 const struct agar_graph *gr,
15 const struct adjacency_listr *atr)
19 for (i = 0; atr[i].from != 0; i++) {
21 struct agar_edge_info eir;
24 ptrint_t *from = int2ptr(atr[i].from);
26 agar_for_each_edge_info(e, eir, err, gr, from) {
29 assert(j < MAX_EDGES);
30 cmpto = int2ptr(atr[i].to[j]);
32 "%s: %p #%d -> #%ld (expected #%d -> #%d)", name, e,
33 atr[i].from, ptr2int(eir.to),
34 atr[i].from, atr[i].to[j]);
38 if (atr[i].to[j] < 0) {
39 ok(err == atr[i].to[j], "%s: %p #%d -> ERROR %d",
40 name, e, atr[i].from, atr[i].to[j]);
41 continue; /* Move onto next node on errors */
43 assert(j < MAX_EDGES);
45 "%s: %p #%d -> --- (expected #%d -> #%d)", name, e,
46 atr[i].from, atr[i].from, atr[i].to[j]);
52 struct parallel_graphr pgr;
53 struct full_graphr fgr;
54 struct chain_graphr cgr;
55 struct grid_graphr ggr1, ggr2;
57 plan_tests(1 + 5 + 30 + 22 + 21 + 33 + 6 + 6 + 6);
59 test_adjacency("trivial", &trivial_graphr.gr, trivial_adjacencyr);
61 parallel_graphr_init(&pgr, 3, 0);
62 test_adjacency("parallel nlinks 3", &pgr.gr,
63 parallel_adjacencyr_nlinks3);
65 full_graphr_init(&fgr, 5);
66 test_adjacency("full 5", &fgr.gr, full_adjacencyr_5);
68 chain_graphr_init(&cgr, 8);
69 test_adjacency("chain 8", &cgr.fgr.gr, chain_adjacencyr_8);
71 grid_graphr_init(&ggr1, 3, 3, true, true, false, false);
72 test_adjacency("grid 3x3 right-down", &ggr1.gr,
73 grid_adjacencyr_3x3_rightdown);
75 grid_graphr_init(&ggr2, 3, 3, true, true, true, true);
76 test_adjacency("grid 3x3 all", &ggr2.gr,
77 grid_adjacencyr_3x3_all);
79 test_adjacency("error graph", &error_graphr.gr, error_adjacencyr);
81 test_adjacency("shortcut1 graph", &shortcut1_graphr.gr,
82 shortcut1_adjacencyr);
84 test_adjacency("shortcut2 graph", &shortcut2_graphr.gr,
85 shortcut2_adjacencyr);