]> git.ozlabs.org Git - ccan/blob - ccan/aga/test/api-adjacency.c
Remove travis workarounds for previous build system
[ccan] / ccan / aga / test / api-adjacency.c
1 #include "config.h"
2
3 #include <stddef.h>
4 #include <assert.h>
5
6 #include <ccan/aga/aga.h>
7
8 #include <ccan/tap/tap.h>
9
10 #include "simple-graph.h"
11
12 static void test_adjacency(const char *name,
13                            const struct simple_graph *sg,
14                            const struct adjacency_list *at)
15 {
16         int i;
17
18         for (i = 0; at[i].from != 0; i++) {
19                 const void *e;
20                 struct aga_edge_info ei;
21                 int j = 0;
22                 const struct aga_node *from;
23                 int err = 0xdeadbeef;
24
25                 assert(i < MAX_NODES);
26
27                 from = &sg->nodes[at[i].from];
28
29                 aga_for_each_edge_info(e, ei, err, &sg->g, from) {
30                         const struct aga_node *cmpto;
31
32                         assert(j < MAX_EDGES);
33                         cmpto = &sg->nodes[at[i].to[j]];
34                         ok(cmpto == ei.to,
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]);
38
39                         j++;
40                 }
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 */
45                 } else {
46                         ok1(err == 0);
47                 }
48                 assert(j < MAX_EDGES);
49                 ok(at[i].to[j] == 0,
50                    "%s: %p #%d -> --- (expected #%d -> #%d)", name, e,
51                    at[i].from, at[i].from, at[i].to[j]);
52         }
53 }
54
55 int main(void)
56 {
57         struct trivial_graph tg;
58         struct parallel_graph pg;
59         struct full_graph fg;
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
67         plan_tests(2 + 7 + 35 + 30 + 30 + 42 + 9 + 30 + 9 + 9);
68
69         trivial_graph_init(&tg);
70         test_adjacency("trivial", &tg.sg, trivial_adjacency);
71
72         parallel_graph_init(&pg, 3, 0);
73         test_adjacency("parallel nlinks 3", &pg.sg,
74                        parallel_adjacency_nlinks3);
75
76         full_graph_init(&fg, 5);
77         test_adjacency("full 5", &fg.sg, full_adjacency_5);
78
79         chain_graph_init(&cg, 8);
80         test_adjacency("chain 8", &cg.fg.sg, chain_adjacency_8);
81
82         grid_graph_init(&gg1, 3, 3, true, true, false, false);
83         test_adjacency("grid 3x3 right-down", &gg1.sg,
84                        grid_adjacency_3x3_rightdown);
85
86         grid_graph_init(&gg2, 3, 3, true, true, true, true);
87         test_adjacency("grid 3x3 all", &gg2.sg,
88                        grid_adjacency_3x3_all);
89
90         error_graph_init(&eg);
91         test_adjacency("error graph", &eg.sg, error_adjacency);
92
93         traversal1_graph_init(&t1g);
94         test_adjacency("traversal1 graph", &t1g.sg, traversal1_adjacency);
95
96         shortcut1_graph_init(&s1g);
97         test_adjacency("shortcut1 graph", &s1g.sg, shortcut1_adjacency);
98
99         shortcut2_graph_init(&s2g);
100         test_adjacency("shortcut2 graph", &s2g.sg, shortcut2_adjacency);
101
102         return exit_status();
103 }