void test_hashset_iter_remove() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); HashSetIter iter; hashset_iter_init(&iter, hs); while (hashset_iter_has_next(&iter)) { char const *e = hashset_iter_next(&iter); if (!strcmp(e, "bar")) hashset_iter_remove(&iter); } cc_assert(hashset_size(hs) == 2, cc_msg("hashset_iter: Expected size 2 but got %d ", hashset_size(hs))); cc_assert(!hashset_contains(hs, "bar"), cc_msg("hashset_iter: Element (%s) still pressent " "after removal", "bar")); hashset_destroy(hs); }
void test_hashset_iter_remove() { HashSet *hs; hashset_new(&hs); char *a = "foo"; char *b = "bar"; char *c = "baz"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); HashSetIter iter; hashset_iter_init(&iter, hs); char *e; while (hashset_iter_next(&iter, (void*) &e) != CC_ITER_END) { if (!strcmp(e, "bar")) hashset_iter_remove(&iter, NULL); } cc_assert(hashset_size(hs) == 2, cc_msg("hashset_iter: Expected size 2 but got %d ", hashset_size(hs))); cc_assert(!hashset_contains(hs, "bar"), cc_msg("hashset_iter: Element (%s) still pressent " "after removal", "bar")); hashset_destroy(hs); }
void test_hashset_iter_next() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); size_t x = 0; size_t y = 0; size_t z = 0; HashSetIter iter; hashset_iter_init(&iter, hs); while (hashset_iter_has_next(&iter)) { char const *e = hashset_iter_next(&iter); if (!strcmp(e, "foo")) x++; if (!strcmp(e, "bar")) y++; if (!strcmp(e, "baz")) z++; } cc_assert((x == 1) && (y == 1) && (z == 1), cc_msg("hashset_iter: Unexpected number of " "elements returned by the iterator")); hashset_destroy(hs); }