1 #include <ccan/intmap/intmap.c>
2 #include <ccan/tap/tap.h>
7 typedef UINTMAP(unsigned int *) umap;
8 typedef SINTMAP(int *) smap;
10 static bool check_umap(const umap *map)
12 /* This is a larger type than unsigned, and allows negative */
15 /* Must be in order, must contain value. */
17 for (i = uintmap_first(map); i != -1ULL; i = uintmap_after(map, i)) {
20 if (*(unsigned int *)uintmap_get(map, i) != i)
27 static bool check_smap(const smap *map)
29 /* This is a larger type than int, and allows negative */
32 /* Must be in order, must contain value. */
33 prev = -0x80000001ULL;
34 for (i = sintmap_first(map);
35 i != 0x7FFFFFFFFFFFFFFFLL;
36 i = sintmap_after(map, i)) {
39 if (*(int *)sintmap_get(map, i) != i)
51 unsigned int urandoms[NUM];
54 plan_tests(6 * NUM + 2);
58 for (i = 0; i < NUM; i++) {
59 urandoms[i] = random();
60 srandoms[i] = random();
62 for (i = 0; i < NUM; i++) {
63 /* In case we have duplicates. */
64 while (!uintmap_add(&umap, urandoms[i], urandoms+i))
65 urandoms[i] = random();
66 ok1(check_umap(&umap));
68 for (i = 0; i < NUM; i++) {
69 ok1(uintmap_del(&umap, urandoms[i]) == urandoms+i);
70 ok1(check_umap(&umap));
72 ok1(uintmap_empty(&umap));
74 for (i = 0; i < NUM; i++) {
75 /* In case we have duplicates. */
76 while (!sintmap_add(&smap, srandoms[i], srandoms+i))
77 srandoms[i] = random();
78 ok1(check_smap(&smap));
80 for (i = 0; i < NUM; i++) {
81 ok1(sintmap_del(&smap, srandoms[i]) == srandoms+i);
82 ok1(check_smap(&smap));
84 ok1(sintmap_empty(&smap));
86 /* This exits depending on whether all tests passed */