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 */
18 /* Must be in order, must contain value. */
20 for (v = uintmap_first(map, &i); v; v = uintmap_after(map, &i)) {
21 if ((int64_t)i <= prev)
26 last = (uintmap_last(map, &last_idx) == v);
31 static bool check_smap(const smap *map)
33 /* This is a larger type than int, and allows negative */
34 int64_t prev, i, last_idx;
38 /* Must be in order, must contain value. */
39 prev = -0x80000001ULL;
40 for (v = sintmap_first(map, &i); v; v = sintmap_after(map, &i)) {
45 last = (sintmap_last(map, &last_idx) == v);
56 unsigned int urandoms[NUM];
59 plan_tests(6 * NUM + 2);
63 for (i = 0; i < NUM; i++) {
64 urandoms[i] = random();
65 srandoms[i] = random();
67 for (i = 0; i < NUM; i++) {
68 /* In case we have duplicates. */
69 while (!uintmap_add(&umap, urandoms[i], urandoms+i))
70 urandoms[i] = random();
71 ok1(check_umap(&umap));
73 for (i = 0; i < NUM; i++) {
74 ok1(uintmap_del(&umap, urandoms[i]) == urandoms+i);
75 ok1(check_umap(&umap));
77 ok1(uintmap_empty(&umap));
79 for (i = 0; i < NUM; i++) {
80 /* In case we have duplicates. */
81 while (!sintmap_add(&smap, srandoms[i], srandoms+i))
82 srandoms[i] = random();
83 ok1(check_smap(&smap));
85 for (i = 0; i < NUM; i++) {
86 ok1(sintmap_del(&smap, srandoms[i]) == srandoms+i);
87 ok1(check_smap(&smap));
89 ok1(sintmap_empty(&smap));
91 /* This exits depending on whether all tests passed */