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 trivial_graphr tgr;
53 struct parallel_graphr pgr;
54 struct full_graphr fgr;
55 struct chain_graphr cgr;
56 struct grid_graphr ggr1, ggr2;
57 struct error_graphr egr;
58 struct shortcut1_graphr s1gr;
59 struct shortcut2_graphr s2gr;
61 plan_tests(1 + 5 + 30 + 22 + 21 + 33 + 6 + 6 + 6);
63 trivial_graphr_init(&tgr);
64 test_adjacency("trivial", &tgr.gr, trivial_adjacencyr);
66 parallel_graphr_init(&pgr, 3, 0);
67 test_adjacency("parallel nlinks 3", &pgr.gr,
68 parallel_adjacencyr_nlinks3);
70 full_graphr_init(&fgr, 5);
71 test_adjacency("full 5", &fgr.gr, full_adjacencyr_5);
73 chain_graphr_init(&cgr, 8);
74 test_adjacency("chain 8", &cgr.fgr.gr, chain_adjacencyr_8);
76 grid_graphr_init(&ggr1, 3, 3, true, true, false, false);
77 test_adjacency("grid 3x3 right-down", &ggr1.gr,
78 grid_adjacencyr_3x3_rightdown);
80 grid_graphr_init(&ggr2, 3, 3, true, true, true, true);
81 test_adjacency("grid 3x3 all", &ggr2.gr,
82 grid_adjacencyr_3x3_all);
84 error_graphr_init(&egr);
85 test_adjacency("error graph", &egr.gr, error_adjacencyr);
87 shortcut1_graphr_init(&s1gr);
88 test_adjacency("shortcut1 graph", &s1gr.gr, shortcut1_adjacencyr);
90 shortcut2_graphr_init(&s2gr);
91 test_adjacency("shortcut2 graph", &s2gr.gr, shortcut2_adjacencyr);