X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fintmap%2Ftest%2Frun-after-exhaustive.c;fp=ccan%2Fintmap%2Ftest%2Frun-after-exhaustive.c;h=1655ddb5e57bc8f80316b3a9864f945e05437644;hb=a241664cddd9c1a9a66064171f871ae52598b82b;hp=0000000000000000000000000000000000000000;hpb=4d9c7e1c2f899930a0bef5f05391615875ff668c;p=ccan diff --git a/ccan/intmap/test/run-after-exhaustive.c b/ccan/intmap/test/run-after-exhaustive.c new file mode 100644 index 00000000..1655ddb5 --- /dev/null +++ b/ccan/intmap/test/run-after-exhaustive.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#define ELEMENTS 8 + +int main(void) +{ + UINTMAP(void *) umap; + + plan_tests((1 << ELEMENTS) * ELEMENTS); + + /* Run through every combination of elements */ + for (int i = 0; i < (1 << ELEMENTS); i++) { + /* Set up map */ + uintmap_init(&umap); + for (int j = 0; j < ELEMENTS; j++) { + if ((1 << j) & i) + uintmap_add(&umap, j, &umap); + } + + /* Try each uintmap_after value */ + for (int j = 0; j < ELEMENTS; j++) { + intmap_index_t idx = j, next; + + if ((i >> (j + 1)) == 0) + next = 0; + else + next = j + 1 + bitops_ls32(i >> (j + 1)); + + if (!uintmap_after(&umap, &idx)) + idx = 0; + ok1(idx == next); + } + uintmap_clear(&umap); + } + + /* This exits depending on whether all tests passed */ + return exit_status(); +}