1 #include <ccan/invbloom/invbloom.h>
2 /* Include the C files directly. */
3 #include <ccan/invbloom/invbloom.c>
4 #include <ccan/tap/tap.h>
6 static void singleton_cb(struct invbloom *ib, size_t n,
9 ok1(ib->count[n] == 1 || ib->count[n] == -1);
16 const tal_t *ctx = tal(NULL, char);
18 unsigned singleton_count;
20 /* This is how many tests you plan to run */
21 plan_tests(10 + 3 + NUM_HASHES * 2);
23 /* Single entry ib table keeps it simple. */
24 ib = invbloom_new(ctx, int, 1, 100);
25 invbloom_singleton_cb(ib, singleton_cb, &singleton_count);
29 invbloom_insert(ib, &val);
30 ok1(ib->count[0] == NUM_HASHES);
31 ok1(singleton_count == 1);
32 ok1(!invbloom_empty(ib));
34 /* First delete takes it via singleton. */
35 invbloom_delete(ib, &val);
36 ok1(singleton_count == 2);
37 ok1(invbloom_empty(ib));
39 /* Second delete creates negative singleton. */
40 invbloom_delete(ib, &val);
41 ok1(singleton_count == 3);
43 /* Now a larger table: this seed set so entries don't clash */
44 ib = invbloom_new(ctx, int, 1024, 0);
46 invbloom_singleton_cb(ib, singleton_cb, &singleton_count);
49 invbloom_insert(ib, &val);
50 ok1(singleton_count == NUM_HASHES);
52 /* First delete does nothing. */
53 invbloom_delete(ib, &val);
54 ok1(singleton_count == NUM_HASHES);
55 ok1(invbloom_empty(ib));
57 /* Second delete creates negative singletons. */
58 invbloom_delete(ib, &val);
59 ok1(singleton_count == NUM_HASHES * 2);
63 /* This exits depending on whether all tests passed */