Added flags to hashset

This commit is contained in:
Leonardo committed 2020-02-29 21:15:04 -03:00
1 parent 4b7678a621
commit 6e49fb8174
3 files changed
+187 -26

No files matched your search

+2 -1
View File
@@ -659,7 +659,8 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(int32_t, cmc_flags.OK, d_flag(d));
// customize
d_customize(d, &cmc_alloc_node_default, &(struct cmc_callbacks_deque) {0});
d_customize(d, &cmc_alloc_node_default,
&(struct cmc_callbacks_deque){ 0 });
cmc_assert_equals(int32_t, cmc_flags.OK, d_flag(d));
// push_front
+74
View File
@@ -406,4 +406,78 @@ CMC_CREATE_UNIT(hashset_test, true, {
hs_free(set);
});
CMC_CREATE_TEST(flags, {
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
// insert
cmc_assert(hs_insert(set, 1));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert(!hs_insert(set, 1));
cmc_assert_equals(int32_t, cmc_flags.DUPLICATE, hs_flag(set));
// clear
hs_clear(set);
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert(hs_insert(set, 1));
// remove
cmc_assert(!hs_remove(set, 2));
cmc_assert_equals(int32_t, cmc_flags.NOT_FOUND, hs_flag(set));
cmc_assert(hs_remove(set, 1));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert(!hs_remove(set, 1));
cmc_assert_equals(int32_t, cmc_flags.EMPTY, hs_flag(set));
// max
cmc_assert(hs_insert(set, 1));
cmc_assert(hs_max(set, NULL));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert(hs_remove(set, 1));
cmc_assert(!hs_max(set, NULL));
cmc_assert_equals(int32_t, cmc_flags.EMPTY, hs_flag(set));
// min
cmc_assert(hs_insert(set, 1));
cmc_assert(hs_min(set, NULL));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert(hs_remove(set, 1));
cmc_assert(!hs_min(set, NULL));
cmc_assert_equals(int32_t, cmc_flags.EMPTY, hs_flag(set));
// contains
hs_contains(set, 1);
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
// copy
struct hashset *set2 = hs_copy_of(set);
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set2));
size_t tmp = set->capacity;
set->capacity = 0;
struct hashset *set3 = hs_copy_of(set);
cmc_assert_equals(ptr, NULL, set3);
cmc_assert_equals(int32_t, cmc_flags.ERROR, hs_flag(set));
set->capacity = tmp;
cmc_assert(hs_equals(set, set2));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set));
cmc_assert_equals(int32_t, cmc_flags.OK, hs_flag(set2));
hs_free(set);
hs_free(set2);
});
});