Fast forward changes

This commit is contained in:
Leonardo committed 2020-01-29 23:58:56 -03:00
1 parent cbf24ab217
commit b2bef4e3cc
25 files changed
+650 -257

No files matched your search

+60 -39
View File
@@ -7,17 +7,36 @@
CMC_GENERATE_BIDIMAP(bm, bidimap, size_t, size_t)
struct bidimap_ftab_key *bm_ftab_key = &(struct bidimap_ftab_key) {
.cmp = cmp,
.cpy = copy,
.str = to_string,
.free = custom_free,
.hash = hash,
.pri = priority
};
struct bidimap_ftab_val *bm_ftab_val = &(struct bidimap_ftab_val) {
.cmp = cmp,
.cpy = copy,
.str = to_string,
.free = custom_free,
.hash = hash,
.pri = priority
};
CMC_CREATE_UNIT(bidimap_test, true, {
CMC_CREATE_TEST(new, {
struct bidimap *map = bm_new(100, 0.6, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.6, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(int32_t, cmc_flags.OK, map->flag);
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(new[null buffer], {
struct bidimap *map = bm_new(100, 0.6, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.6, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -27,11 +46,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(ptr, NULL, map->val_buffer[i]);
}
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(new_custom, {
struct bidimap *map = bm_new_custom(100, 0.6, cmp, hash, cmp, hash,
struct bidimap *map = bm_new_custom(100, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
@@ -41,11 +60,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_not_equals(ptr, NULL, map);
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(new_custom[insert remove], {
struct bidimap *map = bm_new_custom(500, 0.6, cmp, hash, cmp, hash,
struct bidimap *map = bm_new_custom(500, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
@@ -74,11 +93,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 0, bm_count(map));
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(clear[count], {
struct bidimap *map = bm_new(100, 0.6, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.6, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -87,15 +106,15 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 500, bm_count(map));
bm_clear(map, NULL);
bm_clear(map);
cmc_assert_equals(size_t, 0, bm_count(map));
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
struct bidimap *map = bm_new(1, 0.7, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(1, 0.7, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -114,11 +133,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 50005000, sum);
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(insert, {
struct bidimap *map = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -130,11 +149,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 2, bm_count(map));
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(insert[growth remove clear], {
struct bidimap *map = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -159,17 +178,18 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 1000, bm_count(map));
bm_clear(map, NULL);
bm_clear(map);
cmc_assert_equals(size_t, 0, bm_count(map));
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(update_key, {
struct bidimap *map = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(int32_t, cmc_flags.OK, map->flag);
for (size_t i = 1; i <= 100; i++)
cmc_assert(bm_insert(map, i, i));
@@ -186,11 +206,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 100, bm_count(map));
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(update_val, {
struct bidimap *map = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -209,11 +229,11 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert_equals(size_t, 100, bm_count(map));
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(remove_by_key[cleanup custom], {
struct bidimap *map = bm_new_custom(10000, 0.6, cmp, hash, cmp, hash,
struct bidimap *map = bm_new_custom(10000, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
@@ -238,14 +258,15 @@ CMC_CREATE_UNIT(bidimap_test, true, {
struct bidimap_entry *k = map->key_buffer[i];
struct bidimap_entry *v = map->val_buffer[i];
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) && (v == NULL || v == CMC_ENTRY_DELETED));
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED)
&& (v == NULL || v == CMC_ENTRY_DELETED));
}
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(remove_by_val[cleanup custom], {
struct bidimap *map = bm_new_custom(10000, 0.6, cmp, hash, cmp, hash,
struct bidimap *map = bm_new_custom(10000, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
@@ -273,16 +294,16 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) && (v == NULL || v == CMC_ENTRY_DELETED));
}
bm_free(map, NULL);
bm_free(map);
});
CMC_CREATE_TEST(copy_of, {
struct bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map1 = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
for (size_t i = 0; i < 100; i++)
cmc_assert(bm_insert(map1, i, i));
struct bidimap *map2 = bm_copy_of(map1, NULL, NULL);
struct bidimap *map2 = bm_copy_of(map1);
cmc_assert_not_equals(ptr, NULL, map2);
cmc_assert_equals(size_t, bm_count(map1), bm_count(map2));
@@ -293,13 +314,13 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert(bm_contains_val(map2, i) && bm_contains_val(map1, i));
}
bm_free(map1, NULL);
bm_free(map2, NULL);
bm_free(map1);
bm_free(map2);
});
CMC_CREATE_TEST(equals, {
struct bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map2 = bm_new(1000, 0.9, cmp, hash, cmp, hash);
struct bidimap *map1 = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
struct bidimap *map2 = bm_new(1000, 0.9, bm_ftab_key, bm_ftab_val);
for (size_t i = 0; i < 100; i++)
{
@@ -317,23 +338,23 @@ CMC_CREATE_UNIT(bidimap_test, true, {
cmc_assert(bm_contains_val(map2, i) && bm_contains_val(map1, i));
}
bm_free(map1, NULL);
bm_free(map2, NULL);
bm_free(map1);
bm_free(map2);
});
CMC_CREATE_TEST(equals[from copy], {
struct bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);
struct bidimap *map1 = bm_new(100, 0.7, bm_ftab_key, bm_ftab_val);
for (size_t i = 0; i < 100; i++)
cmc_assert(bm_insert(map1, i, i));
struct bidimap *map2 = bm_copy_of(map1, NULL, NULL);
struct bidimap *map2 = bm_copy_of(map1);
cmc_assert_not_equals(ptr, NULL, map2);
cmc_assert(bm_equals(map1, map2));
bm_free(map1, NULL);
bm_free(map2, NULL);
bm_free(map1);
bm_free(map2);
});
});
-30
View File
@@ -31,36 +31,6 @@ CMC_CREATE_UNIT(list_test, true, {
cmc_assert_equals(ptr, NULL, l);
});
CMC_CREATE_TEST(new_from[count and item preservation], {
size_t v[5];
for (size_t i = 0; i < 5; i++)
{
v[i] = i;
}
struct list *l = l_new_from(v, 5);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 5; i++)
cmc_assert_equals(size_t, i, l_get(l, i));
l_free(l, NULL);
});
CMC_CREATE_TEST(new_from[size = 1], {
size_t a = 10;
size_t *values = &a;
struct list *l = l_new_from(values, 1);
cmc_assert_not_equals(ptr, NULL, l);
l_free(l, NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
struct list *l = l_new(100);
+23
View File
@@ -3,6 +3,7 @@
#define CMC_UNIT_TEST_UTL__
#include <stdlib.h>
#include <inttypes.h>
#include <cmc/hashmap.h>
int cmp(size_t a, size_t b)
@@ -10,6 +11,22 @@ int cmp(size_t a, size_t b)
return (a > b) - (a < b);
}
size_t copy(size_t a)
{
return a;
}
bool to_string(FILE *fptr, size_t a)
{
return fprintf(fptr, "%" PRIuMAX " ", a) > 0;
}
void custom_free(size_t a)
{
// blank
// Free any resources if necessary
}
size_t hash(size_t a)
{
a += ~(a << 15);
@@ -21,6 +38,12 @@ size_t hash(size_t a)
return a;
}
int priority(size_t a, size_t b)
{
// Could contain different logic
return cmp(a, b);
}
size_t numhash(size_t a)
{
return a;