Added compile time benchmark and bidimap tests

This commit is contained in:
Leonardo committed 2019-10-26 15:03:44 -03:00
1 parent 8f06e8abce
commit db61269d42
4 files changed
+272 -13

No files matched your search

+82
View File
@@ -32,4 +32,86 @@ CMC_CREATE_UNIT(bidimap_test, true, {
bm_free(map, NULL);
});
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
bidimap *map = bm_new(1, 0.7, cmp, hash, cmp, hash);
for (size_t i = 1; i <= 10000; i++)
cmc_assert(bm_insert(map, i, i));
size_t sum = 0;
for (size_t i = 0; i < bm_capacity(map); i++)
{
if (map->key_buffer[i] && map->key_buffer[i] != CMC_ENTRY_DELETED)
{
sum += map->key_buffer[i]->key;
}
}
cmc_assert_equals(size_t, 50005000, sum);
bm_free(map, NULL);
});
CMC_CREATE_TEST(copy_of, {
bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);
for (size_t i = 0; i < 100; i++)
cmc_assert(bm_insert(map1, i, i));
bidimap *map2 = bm_copy_of(map1, NULL, NULL);
cmc_assert_not_equals(ptr, NULL, map2);
cmc_assert_equals(size_t, bm_count(map1), bm_count(map2));
for (size_t i = 0; i < 100; i++)
{
cmc_assert(bm_contains_key(map2, i) && bm_contains_key(map1, i));
cmc_assert(bm_contains_val(map2, i) && bm_contains_val(map1, i));
}
bm_free(map1, NULL);
bm_free(map2, NULL);
});
CMC_CREATE_TEST(equals, {
bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);
bidimap *map2 = bm_new(1000, 0.9, cmp, hash, cmp, hash);
for (size_t i = 0; i < 100; i++)
{
cmc_assert(bm_insert(map1, i, i));
cmc_assert(bm_insert(map2, 99 - i, 99 - i));
}
cmc_assert_not_equals(ptr, NULL, map1);
cmc_assert_not_equals(ptr, NULL, map2);
cmc_assert_equals(size_t, bm_count(map1), bm_count(map2));
for (size_t i = 0; i < 100; i++)
{
cmc_assert(bm_contains_key(map2, i) && bm_contains_key(map1, i));
cmc_assert(bm_contains_val(map2, i) && bm_contains_val(map1, i));
}
bm_free(map1, NULL);
bm_free(map2, NULL);
});
CMC_CREATE_TEST(equals[from copy], {
bidimap *map1 = bm_new(100, 0.7, cmp, hash, cmp, hash);
for (size_t i = 0; i < 100; i++)
cmc_assert(bm_insert(map1, i, i));
bidimap *map2 = bm_copy_of(map1, NULL, NULL);
cmc_assert_not_equals(ptr, NULL, map2);
cmc_assert(bm_equals(map1, map2));
bm_free(map1, NULL);
bm_free(map2, NULL);
});
});