Refactoring tests and added sortedlist test

This commit is contained in:
Leonardo committed 2019-09-30 18:27:19 -03:00
1 parent 376c0ad4e7
commit f52a9ff702
13 files changed
+118 -58

No files matched your search

+2
View File
@@ -14,6 +14,7 @@
#include "unt/intervalheap.c"
#include "unt/multimap.c"
#include "unt/multiset.c"
#include "unt/sortedlist.c"
int main(void)
{
@@ -37,6 +38,7 @@ int main(void)
failed += intervalheap_test();
failed += multimap_test();
failed += multiset_test();
failed += sortedlist_test();
cmc_timer_stop(timer);
cmc_timer_calc(timer);
+2 -3
View File
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(hashmap_test, true, {
hm_free(map, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
hashmap *map = hm_new(0, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
hashmap *map = hm_new(UINT64_MAX, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
@@ -47,5 +47,4 @@ CMC_CREATE_UNIT(hashmap_test, true, {
hm_free(map, NULL);
});
});
+2 -3
View File
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(hashset_test, true, {
hs_free(set, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
hashset *set = hs_new(0, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
hashset *set = hs_new(UINT64_MAX, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
@@ -47,5 +47,4 @@ CMC_CREATE_UNIT(hashset_test, true, {
hs_free(set, NULL);
});
});
+3 -4
View File
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(heap_test, true, {
h_free(h, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
heap *h = h_new(0, cmc_max_heap, cmp);
cmc_assert_equals(ptr, NULL, h);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
heap *h = h_new(UINT64_MAX, cmc_max_heap, cmp);
cmc_assert_equals(ptr, NULL, h);
@@ -49,7 +49,7 @@ CMC_CREATE_UNIT(heap_test, true, {
h_free(h, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth [edge_case:capacity = 1], {
heap *h = h_new(1, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
@@ -61,5 +61,4 @@ CMC_CREATE_UNIT(heap_test, true, {
h_free(h, NULL);
});
});
+1 -2
View File
@@ -36,7 +36,7 @@ CMC_CREATE_UNIT(linkedlist_test, true, {
ll_free(ll, NULL);
});
CMC_CREATE_TEST(clear[edge_case:count = 0], {
CMC_CREATE_TEST(clear [edge_case:count = 0], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
@@ -75,5 +75,4 @@ CMC_CREATE_UNIT(linkedlist_test, true, {
ll_free(ll, NULL);
});
});
+11 -11
View File
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
list *l = l_new(0);
cmc_assert_equals(ptr, NULL, l);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
list *l = l_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, l);
@@ -49,7 +49,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(new_from[edge_case:size = 1], {
CMC_CREATE_TEST(new_from [edge_case:size = 1], {
size_t a = 10;
size_t *values = &a;
@@ -79,7 +79,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth [edge_case:capacity = 1], {
list *l = l_new(1);
cmc_assert_not_equals(ptr, NULL, l);
@@ -253,7 +253,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[edge_case:count = 0], {
CMC_CREATE_TEST(pop_front [edge_case:count = 0], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -262,7 +262,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[edge_case:count = 1], {
CMC_CREATE_TEST(pop_front [edge_case:count = 1], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -286,7 +286,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop[edge_case:count = 0], {
CMC_CREATE_TEST(pop_at [edge_case:count = 0], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -295,7 +295,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop[edge_case:count = 1], {
CMC_CREATE_TEST(pop_at [edge_case:count = 1], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -307,7 +307,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop[buffer_clear], {
CMC_CREATE_TEST(pop_at[buffer_clear], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -319,7 +319,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_back[edge_case:count = 0], {
CMC_CREATE_TEST(pop_back [edge_case:count = 0], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -328,7 +328,7 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_back[edge_case:count = 1], {
CMC_CREATE_TEST(pop_back [edge_case:count = 1], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
+4 -5
View File
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(multimap_test, true, {
mm_free(map, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
multimap *map = mm_new(0, 0.8, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
multimap *map = mm_new(UINT64_MAX, 0.8, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
@@ -79,7 +79,7 @@ CMC_CREATE_UNIT(multimap_test, true, {
mm_free(map, NULL);
});
CMC_CREATE_TEST(remove[edge_case:count = 0], {
CMC_CREATE_TEST(remove [edge_case:count = 0], {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
@@ -91,7 +91,7 @@ CMC_CREATE_UNIT(multimap_test, true, {
mm_free(map, NULL);
});
CMC_CREATE_TEST(remove[edge_case:count = 1], {
CMC_CREATE_TEST(remove [edge_case:count = 1], {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
@@ -119,5 +119,4 @@ CMC_CREATE_UNIT(multimap_test, true, {
mm_free(map, NULL);
});
});
+2 -3
View File
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(multiset_test, true, {
ms_free(set, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
multiset *set = ms_new(0, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINTMAX_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINTMAX_MAX], {
multiset *set = ms_new(UINTMAX_MAX, 0.99, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
@@ -85,5 +85,4 @@ CMC_CREATE_UNIT(multiset_test, true, {
ms_free(set, NULL);
});
});
+3 -4
View File
@@ -20,13 +20,13 @@ CMC_CREATE_UNIT(queue_test, true, {
q_free(q, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
queue *q = q_new(0);
cmc_assert_equals(ptr, NULL, q);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
queue *q = q_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, q);
@@ -50,7 +50,7 @@ CMC_CREATE_UNIT(queue_test, true, {
q_free(q, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth [edge_case:capacity = 1], {
queue *q = q_new(1);
cmc_assert_not_equals(ptr, NULL, q);
@@ -62,5 +62,4 @@ CMC_CREATE_UNIT(queue_test, true, {
q_free(q, NULL);
});
});
+68
View File
@@ -0,0 +1,68 @@
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include <ext/sortedlist.h>
CMC_GENERATE_SORTEDLIST(sl, sortedlist, size_t)
CMC_CREATE_UNIT(sortedlist_test, true, {
CMC_CREATE_TEST(new, {
sortedlist *sl = sl_new(1000000, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
cmc_assert_not_equals(ptr, NULL, sl->buffer);
cmc_assert_equals(size_t, 1000000, sl_capacity(sl));
cmc_assert_equals(size_t, 0, sl_count(sl));
cmc_assert_not_equals(ptr, NULL, sl->buffer);
sl_free(sl, NULL);
});
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
sortedlist *sl = sl_new(0, cmp);
cmc_assert_equals(ptr, NULL, sl);
});
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
sortedlist *sl = sl_new(UINT64_MAX, cmp);
cmc_assert_equals(ptr, NULL, sl);
});
CMC_CREATE_TEST(clear[count capacity], {
sortedlist *sl = sl_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
for (size_t i = 0; i < 50; i++)
cmc_assert(sl_insert(sl, i));
cmc_assert_equals(size_t, 50, sl_count(sl));
sl_clear(sl, NULL);
cmc_assert_equals(size_t, 0, sl_count(sl));
cmc_assert_equals(size_t, 100, sl_capacity(sl));
sl_free(sl, NULL);
});
CMC_CREATE_TEST(buffer_growth [edge_case:capacity = 1], {
sortedlist *sl = sl_new(1, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
for (size_t i = 0; i < 50; i++)
cmc_assert(sl_insert(sl, i));
sl_sort(sl);
cmc_assert_equals(size_t, 50, sl_count(sl));
cmc_assert_array_sorted_any(size_t, sl->buffer, cmp, 0, sl->count - 1);
sl_free(sl, NULL);
});
});
+20 -21
View File
@@ -20,13 +20,13 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
stack *s = s_new(0);
cmc_assert_equals(ptr, NULL, s);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new [edge_case:capacity = UINT64_MAX], {
stack *s = s_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, s);
@@ -50,7 +50,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth [edge_case:capacity = 1], {
stack *s = s_new(1);
cmc_assert_not_equals(ptr, NULL, s);
@@ -151,7 +151,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(pop[edge_case:count = 0], {
CMC_CREATE_TEST(pop [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -177,7 +177,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(top[edge_case:count = 0], {
CMC_CREATE_TEST(top [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -191,7 +191,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(top[edge_case:count = 1], {
CMC_CREATE_TEST(top [edge_case:count = 1], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -217,7 +217,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(contains[edge_case:count = 0], {
CMC_CREATE_TEST(contains [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -262,7 +262,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(full[edge_case:capacity = 1], {
CMC_CREATE_TEST(full [edge_case:capacity = 1], {
stack *s = s_new(1);
cmc_assert_not_equals(ptr, NULL, s);
@@ -287,7 +287,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_init[edge_case:count = 0], {
CMC_CREATE_TEST(iter_init [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -304,7 +304,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_start[edge_case:count = 0], {
CMC_CREATE_TEST(iter_start [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -318,7 +318,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_end[edge_case:count = 0], {
CMC_CREATE_TEST(iter_end [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -389,7 +389,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[edge_case:count = 1], {
CMC_CREATE_TEST(iteration [edge_case:count = 1], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -412,7 +412,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[edge_case:count = capacity], {
CMC_CREATE_TEST(iteration [edge_case:count = capacity], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -476,7 +476,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[boundaries:count = 0], {
CMC_CREATE_TEST(iteration [boundaries:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -495,7 +495,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[boundaries:count > 0], {
CMC_CREATE_TEST(iteration [boundaries:count > 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -517,7 +517,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_value[edge_case:count = 0], {
CMC_CREATE_TEST(iter_value [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -531,7 +531,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_rvalue[edge_case:count = 0], {
CMC_CREATE_TEST(iter_rvalue [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -557,12 +557,12 @@ CMC_CREATE_UNIT(stack_test, true, {
size_t total = 0;
for (stack_iter it = s->it_start(s); false; )
for (stack_iter it = s->it_start(s); false;)
{
cmc_assert_equals(size_t, 0, s_iter_index(&it));
}
for (stack_iter it = s->it_start(s); false; )
for (stack_iter it = s->it_start(s); false;)
{
cmc_assert_equals(size_t, s_count(s) - 1, s_iter_index(&it));
}
@@ -584,7 +584,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
CMC_CREATE_TEST(index[edge_case:count = 0], {
CMC_CREATE_TEST(index [edge_case:count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -596,5 +596,4 @@ CMC_CREATE_UNIT(stack_test, true, {
s_free(s, NULL);
});
});
-1
View File
@@ -33,5 +33,4 @@ CMC_CREATE_UNIT(treemap_test, true, {
tm_free(map, NULL);
});
});
-1
View File
@@ -33,5 +33,4 @@ CMC_CREATE_UNIT(treeset_test, true, {
ts_free(set, NULL);
});
});