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 */
17 /* Must be in order, must contain value. */
19 for (v = uintmap_first(map, &i); v; v = uintmap_after(map, &i)) {
20 if ((int64_t)i <= prev)
29 static bool check_smap(const smap *map)
31 /* This is a larger type than int, and allows negative */
35 /* Must be in order, must contain value. */
36 prev = -0x80000001ULL;
37 for (v = sintmap_first(map, &i); v; v = sintmap_after(map, &i)) {
52 unsigned int urandoms[NUM];
55 plan_tests(6 * NUM + 2);
59 for (i = 0; i < NUM; i++) {
60 urandoms[i] = random();
61 srandoms[i] = random();
63 for (i = 0; i < NUM; i++) {
64 /* In case we have duplicates. */
65 while (!uintmap_add(&umap, urandoms[i], urandoms+i))
66 urandoms[i] = random();
67 ok1(check_umap(&umap));
69 for (i = 0; i < NUM; i++) {
70 ok1(uintmap_del(&umap, urandoms[i]) == urandoms+i);
71 ok1(check_umap(&umap));
73 ok1(uintmap_empty(&umap));
75 for (i = 0; i < NUM; i++) {
76 /* In case we have duplicates. */
77 while (!sintmap_add(&smap, srandoms[i], srandoms+i))
78 srandoms[i] = random();
79 ok1(check_smap(&smap));
81 for (i = 0; i < NUM; i++) {
82 ok1(sintmap_del(&smap, srandoms[i]) == srandoms+i);
83 ok1(check_smap(&smap));
85 ok1(sintmap_empty(&smap));
87 /* This exits depending on whether all tests passed */