X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fagar%2Ftest%2Fapi-adjacency.c;fp=ccan%2Fagar%2Ftest%2Fapi-adjacency.c;h=c17ead55e3ae7631fcabda93a76b2d8573eb44c9;hp=0000000000000000000000000000000000000000;hb=c2966d1879c825cfaf0e7d6848a5da052ee4a038;hpb=06162212353c882249d7e207756ea81ea645fc30 diff --git a/ccan/agar/test/api-adjacency.c b/ccan/agar/test/api-adjacency.c new file mode 100644 index 00000000..c17ead55 --- /dev/null +++ b/ccan/agar/test/api-adjacency.c @@ -0,0 +1,86 @@ +#include "config.h" + +#include +#include + +#include +#include + +#include + +#include "simple-graphr.h" + +static void test_adjacency(const char *name, + const struct agar_graph *gr, + const struct adjacency_listr *atr) +{ + int i; + + for (i = 0; atr[i].from != 0; i++) { + const void *e; + struct agar_edge_info eir; + int j = 0; + int err; + ptrint_t *from = int2ptr(atr[i].from); + + agar_for_each_edge_info(e, eir, err, gr, from) { + const void *cmpto; + + assert(j < MAX_EDGES); + cmpto = int2ptr(atr[i].to[j]); + ok(cmpto == eir.to, + "%s: %p #%d -> #%ld (expected #%d -> #%d)", name, e, + atr[i].from, ptr2int(eir.to), + atr[i].from, atr[i].to[j]); + + j++; + } + if (atr[i].to[j] < 0) { + ok(err == atr[i].to[j], "%s: %p #%d -> ERROR %d", + name, e, atr[i].from, atr[i].to[j]); + continue; /* Move onto next node on errors */ + } + assert(j < MAX_EDGES); + ok(atr[i].to[j] == 0, + "%s: %p #%d -> --- (expected #%d -> #%d)", name, e, + atr[i].from, atr[i].from, atr[i].to[j]); + } +} + +int main(void) +{ + struct trivial_graphr tgr; + struct parallel_graphr pgr; + struct full_graphr fgr; + struct chain_graphr cgr; + struct grid_graphr ggr1, ggr2; + struct error_graphr egr; + + plan_tests(1 + 5 + 30 + 22 + 21 + 33 + 6); + + trivial_graphr_init(&tgr); + test_adjacency("trivial", &tgr.gr, trivial_adjacencyr); + + parallel_graphr_init(&pgr, 3); + test_adjacency("parallel nlinks 3", &pgr.gr, + parallel_adjacencyr_nlinks3); + + full_graphr_init(&fgr, 5); + test_adjacency("full 5", &fgr.gr, full_adjacencyr_5); + + chain_graphr_init(&cgr, 8); + test_adjacency("chain 8", &cgr.fgr.gr, chain_adjacencyr_8); + + grid_graphr_init(&ggr1, 3, 3, true, true, false, false); + test_adjacency("grid 3x3 right-down", &ggr1.gr, + grid_adjacencyr_3x3_rightdown); + + grid_graphr_init(&ggr2, 3, 3, true, true, true, true); + test_adjacency("grid 3x3 all", &ggr2.gr, + grid_adjacencyr_3x3_all); + + error_graphr_init(&egr); + test_adjacency("error graph", &egr.gr, error_adjacencyr); + + return exit_status(); +}