X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Finvbloom%2Ftest%2Frun-singletoncb.c;fp=ccan%2Finvbloom%2Ftest%2Frun-singletoncb.c;h=f4f6455a7a2c79d554af2bdce7045c2364adda5d;hp=2ecf71e9655374a67ae73d881a6b7a9856c2ea85;hb=8c2ee69f54a357078e75392659be3c46a228b7d0;hpb=eaab3d3e5cef9a612e688cf2b0d099277ade145a diff --git a/ccan/invbloom/test/run-singletoncb.c b/ccan/invbloom/test/run-singletoncb.c index 2ecf71e9..f4f6455a 100644 --- a/ccan/invbloom/test/run-singletoncb.c +++ b/ccan/invbloom/test/run-singletoncb.c @@ -3,11 +3,11 @@ #include #include -static void singleton_cb(struct invbloom *ib, size_t n, +static void singleton_cb(struct invbloom *ib, size_t n, bool before, unsigned *count) { ok1(ib->count[n] == 1 || ib->count[n] == -1); - (*count)++; + count[before]++; } int main(void) @@ -15,48 +15,54 @@ int main(void) struct invbloom *ib; const tal_t *ctx = tal(NULL, char); int val; - unsigned singleton_count; + unsigned singleton_count[2]; /* This is how many tests you plan to run */ - plan_tests(10 + 3 + NUM_HASHES * 2); + plan_tests(16 + 6 + NUM_HASHES * 3); /* Single entry ib table keeps it simple. */ ib = invbloom_new(ctx, int, 1, 100); - invbloom_singleton_cb(ib, singleton_cb, &singleton_count); + invbloom_singleton_cb(ib, singleton_cb, singleton_count); val = 0; - singleton_count = 0; + singleton_count[false] = singleton_count[true] = 0; invbloom_insert(ib, &val); ok1(ib->count[0] == NUM_HASHES); - ok1(singleton_count == 1); + ok1(singleton_count[true] == 1); + ok1(singleton_count[false] == 1); ok1(!invbloom_empty(ib)); /* First delete takes it via singleton. */ invbloom_delete(ib, &val); - ok1(singleton_count == 2); + ok1(singleton_count[true] == 2); + ok1(singleton_count[false] == 2); ok1(invbloom_empty(ib)); /* Second delete creates negative singleton. */ invbloom_delete(ib, &val); - ok1(singleton_count == 3); + ok1(singleton_count[true] == 3); + ok1(singleton_count[false] == 3); /* Now a larger table: this seed set so entries don't clash */ ib = invbloom_new(ctx, int, 1024, 0); - singleton_count = 0; - invbloom_singleton_cb(ib, singleton_cb, &singleton_count); + singleton_count[false] = singleton_count[true] = 0; + invbloom_singleton_cb(ib, singleton_cb, singleton_count); val = 0; invbloom_insert(ib, &val); - ok1(singleton_count == NUM_HASHES); + ok1(singleton_count[true] == 0); + ok1(singleton_count[false] == NUM_HASHES); - /* First delete does nothing. */ + /* First delete removes singletons. */ invbloom_delete(ib, &val); - ok1(singleton_count == NUM_HASHES); + ok1(singleton_count[true] == NUM_HASHES); + ok1(singleton_count[false] == NUM_HASHES); ok1(invbloom_empty(ib)); /* Second delete creates negative singletons. */ invbloom_delete(ib, &val); - ok1(singleton_count == NUM_HASHES * 2); + ok1(singleton_count[true] == NUM_HASHES); + ok1(singleton_count[false] == NUM_HASHES * 2); tal_free(ctx);