Finishing up some functions of bidimap that were left off

Also gearing up bidimap for next update containing callbacks and custom allocation functions
This commit is contained in:
Leonardo committed 2019-11-13 23:23:54 -03:00
1 parent 0d57698d2f
commit ad2ae84c13
2 files changed
+572 -218

No files matched your search

+81 -2
View File
@@ -16,15 +16,76 @@ CMC_CREATE_UNIT(bidimap_test, true, {
bm_free(map, NULL);
});
CMC_CREATE_TEST(new_custom, {
struct bidimap *map = bm_new_custom(100, 0.6, cmp, hash, cmp, hash,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
cmc_assert_not_equals(ptr, NULL, map);
bm_free(map, NULL);
});
CMC_CREATE_TEST(new_custom, {
struct bidimap *map = bm_new_custom(100, 0.6, cmp, hash, cmp, hash,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
cmc_assert_not_equals(ptr, NULL, map);
bm_free(map, NULL);
});
CMC_CREATE_TEST(new_custom[insert remove], {
struct bidimap *map = bm_new_custom(100, 0.6, cmp, hash, cmp, hash,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 500; i++)
cmc_assert(bm_insert(map, i, i));
cmc_assert_equals(size_t, 500, bm_count(map));
for (size_t i = 0; i < 500; i++)
{
if (i % 2 == 0)
{
cmc_assert(bm_remove_by_key(map, i, NULL, NULL));
}
else
{
cmc_assert(bm_remove_by_val(map, i, NULL, NULL));
}
}
cmc_assert_equals(size_t, 0, bm_count(map));
bm_free(map, NULL);
});
CMC_CREATE_TEST(clear[count], {
struct bidimap *map = bm_new(100, 0.6, cmp, hash, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 50; i++)
for (size_t i = 0; i < 500; i++)
cmc_assert(bm_insert(map, i, i));
cmc_assert_equals(size_t, 50, bm_count(map));
cmc_assert_equals(size_t, 500, bm_count(map));
bm_clear(map, NULL);
@@ -36,6 +97,8 @@ CMC_CREATE_UNIT(bidimap_test, true, {
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
struct bidimap *map = bm_new(1, 0.7, cmp, hash, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 1; i <= 10000; i++)
cmc_assert(bm_insert(map, i, i));
@@ -54,6 +117,22 @@ CMC_CREATE_UNIT(bidimap_test, true, {
bm_free(map, NULL);
});
CMC_CREATE_TEST(insert, {
struct bidimap *map = bm_new(100, 0.7, cmp, hash, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(bm_insert(map, 1, 1));
cmc_assert(!bm_insert(map, 1, 1));
cmc_assert(!bm_insert(map, 2, 1));
cmc_assert(!bm_insert(map, 1, 2));
cmc_assert(bm_insert(map, 2, 2));
cmc_assert_equals(size_t, 2, bm_count(map));
bm_free(map, NULL);
});
CMC_CREATE_TEST(copy_of, {
struct bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);