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

+10 -13
View File
@@ -1,22 +1,21 @@
#include <utl/timer.h>
#include "unt/bidimap.c"
#include "unt/deque.c"
#include "unt/hashmap.c"
#include "unt/hashset.c"
#include "unt/heap.c"
#include "unt/intervalheap.c"
#include "unt/linkedlist.c"
#include "unt/list.c"
#include "unt/multimap.c"
#include "unt/multiset.c"
#include "unt/queue.c"
#include "unt/sortedlist.c"
#include "unt/stack.c"
#include "unt/treemap.c"
#include "unt/treeset.c"
#include "unt/bidimap.c"
#include "unt/intervalheap.c"
#include "unt/multimap.c"
#include "unt/multiset.c"
#include "unt/sortedlist.c"
int main(void)
{
cmc_timer timer;
@@ -24,24 +23,22 @@ int main(void)
cmc_timer_start(timer);
uintmax_t failed = 0;
failed += bidimap_test();
failed += deque_test();
failed += hashmap_test();
failed += hashset_test();
failed += heap_test();
failed += intervalheap_test();
failed += linkedlist_test();
failed += list_test();
failed += multimap_test();
failed += multiset_test();
failed += queue_test();
failed += sortedlist_test();
failed += stack_test();
failed += treemap_test();
failed += treeset_test();
/* ext */
failed += bidimap_test();
failed += intervalheap_test();
failed += multimap_test();
failed += multiset_test();
failed += sortedlist_test();
cmc_timer_stop(timer);
cmc_timer_calc(timer);
+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);
});
});