More tests

This commit is contained in:
Leonardo committed 2019-07-04 02:18:05 -03:00
1 parent a9314ee8f7
commit 846d0bbba6
9 files changed
+1147 -88

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
bool passed = (map->capacity >= (943722 / 0.6)) && map->count == 0 && map->buffer;
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_capacity(map) > (943722 / 0.6));
cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(map));
CMC_TEST_PASS_ELSE_FAIL(passed);
+75
View File
@@ -0,0 +1,75 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/heap.c"
#include "utl.c"
CMC_CREATE_UNIT(heap_test, true, {
CMC_CREATE_TEST(new, {
heap *h = h_new(1000000, MaxHeap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
bool passed = h->capacity == 1000000 && h->count == 0 && h->buffer;
cmc_assert_equals(size_t, 1000000, h->capacity);
cmc_assert_equals(size_t, 0, h_count(h));
cmc_assert_not_equals(ptr, NULL, h->buffer);
CMC_TEST_PASS_ELSE_FAIL(passed);
h_free(h);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
heap *h = h_new(0, MaxHeap, cmp);
cmc_assert_equals(ptr, NULL, h);
CMC_TEST_PASS_ELSE_FAIL(h == NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
heap *h = h_new(UINT64_MAX, MaxHeap, cmp);
cmc_assert_equals(ptr, NULL, h);
CMC_TEST_PASS_ELSE_FAIL(h == NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
heap *h = h_new(100, MaxHeap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
for (size_t i = 0; i < 50; i++)
h_insert(h, i);
cmc_assert_equals(size_t, 50, h_count(h));
h_clear(h);
cmc_assert_equals(size_t, 0, h_count(h));
cmc_assert_equals(size_t, 100, h_capacity(h));
CMC_TEST_PASS_ELSE_FAIL(h_count(h) == 0 && h_capacity(h) == 100);
h_free(h);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
heap *h = h_new(1, MaxHeap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
for (size_t i = 0; i < 50; i++)
h_insert(h, i);
cmc_assert_equals(size_t, 50, h_count(h));
CMC_TEST_PASS_ELSE_FAIL(h_count(h) == 50);
h_free(h);
});
});
+93
View File
@@ -0,0 +1,93 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/linkedlist.c"
CMC_CREATE_UNIT(linkedlist_test, true, {
CMC_CREATE_TEST(new, {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
bool passed = ll->count == 0 && ll->head == NULL && ll->tail == NULL;
cmc_assert_equals(size_t, 0, ll_count(ll));
cmc_assert_equals(ptr, NULL, ll->head);
cmc_assert_equals(ptr, NULL, ll->tail);
CMC_TEST_PASS_ELSE_FAIL(passed);
ll_free(ll);
});
CMC_CREATE_TEST(clear[count capacity], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
for (size_t i = 0; i < 50; i++)
ll_push_back(ll, i);
cmc_assert_equals(size_t, 50, ll_count(ll));
ll_clear(ll);
cmc_assert_equals(size_t, 0, ll_count(ll));
CMC_TEST_PASS_ELSE_FAIL(ll_count(ll) == 0);
ll_free(ll);
});
CMC_CREATE_TEST(clear[edge_case:count = 0], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
ll_clear(ll);
cmc_assert_equals(size_t, 0, ll_count(ll));
CMC_TEST_PASS_ELSE_FAIL(ll_count(ll) == 0);
ll_free(ll);
});
CMC_CREATE_TEST(push_front[count], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
ll_push_front(ll, 1);
cmc_assert_not_equals(ptr, NULL, ll->head);
cmc_assert_not_equals(ptr, NULL, ll->tail);
cmc_assert_equals(size_t, 1, ll_count(ll));
CMC_TEST_PASS_ELSE_FAIL(ll->head && ll->tail && ll_count(ll) == 1);
ll_free(ll);
});
CMC_CREATE_TEST(push_front[item_preservation], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
for (size_t i = 0; i < 200; i++)
ll_push_front(ll, i);
bool passed = true;
for (size_t i = 0; i < ll_count(ll); i++)
{
passed = passed && ll_get(ll, i) == (ll_count(ll) - i - 1);
cmc_assert_equals(size_t, ll_get(ll, i), ll_count(ll) - i - 1);
}
CMC_TEST_PASS_ELSE_FAIL(passed && ll_count(ll) == 200);
ll_free(ll);
});
});
+136 -22
View File
@@ -118,13 +118,43 @@ CMC_CREATE_UNIT(list_test, true, {
l_free(l);
});
CMC_CREATE_TEST(push_front[count capacity item_preservation grow], {
CMC_CREATE_TEST(push_front[count], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 200; i++)
l_push_front(l, i);
for (size_t i = 0; i < 250; i++)
cmc_assert(l_push_front(l, i));
cmc_assert_equals(size_t, 250, l_count(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 250);
l_free(l);
});
CMC_CREATE_TEST(push_front[capacity], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 250; i++)
cmc_assert(l_push_front(l, i));
cmc_assert_lesser_equals(size_t, l_capacity(l), l_count(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) <= l_capacity(l));
l_free(l);
});
CMC_CREATE_TEST(push_front[item_preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 250; i++)
cmc_assert(l_push_front(l, i));
bool passed = true;
@@ -135,18 +165,57 @@ CMC_CREATE_UNIT(list_test, true, {
cmc_assert_equals(size_t, l_get(l, i), l_count(l) - i - 1);
}
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200);
CMC_TEST_PASS_ELSE_FAIL(passed);
l_free(l);
});
CMC_CREATE_TEST(push[count capacity item_preservation grow], {
CMC_CREATE_TEST(push[count], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 200; i++)
l_push(l, i, l_count(l));
cmc_assert(l_push_back(l, 0));
cmc_assert(l_push_back(l, 249));
for (size_t i = 1; i < 249; i++)
cmc_assert(l_push(l, i, l_count(l) - 1));
cmc_assert_equals(size_t, 250, l_count(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 250);
l_free(l);
});
CMC_CREATE_TEST(push[capacity], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(l_push_back(l, 0));
cmc_assert(l_push_back(l, 249));
for (size_t i = 1; i < 249; i++)
cmc_assert(l_push(l, i, l_count(l) - 1));
cmc_assert_lesser_equals(size_t, l_capacity(l), l_count(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) <= l_capacity(l));
l_free(l);
});
CMC_CREATE_TEST(push[item_preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(l_push_back(l, 0));
cmc_assert(l_push_back(l, 249));
for (size_t i = 1; i < 249; i++)
cmc_assert(l_push(l, i, l_count(l) - 1));
bool passed = true;
@@ -157,39 +226,84 @@ CMC_CREATE_UNIT(list_test, true, {
cmc_assert_equals(size_t, l_get(l, i), i);
}
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200);
CMC_TEST_PASS_ELSE_FAIL(passed);
l_free(l);
});
CMC_CREATE_TEST(push_back[count capacity item_preservation grow], {
CMC_CREATE_TEST(push_back[count], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 200; i++)
for (size_t i = 0; i < 250; i++)
cmc_assert(l_push_back(l, i));
cmc_assert_equals(size_t, 250, l_count(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 250);
l_free(l);
});
CMC_CREATE_TEST(push_back[capacity], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 250; i++)
cmc_assert(l_push_back(l, i));
cmc_assert_lesser_equals(size_t, l_capacity(l), l_count(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) <= l_capacity(l));
l_free(l);
});
CMC_CREATE_TEST(push_back[item_preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 250; i++)
cmc_assert(l_push_back(l, i));
bool passed = true;
for (size_t i = 0; i < l_count(l); i++)
{
passed = passed && l_get(l, i) == i;
cmc_assert_equals(size_t, l_get(l, i), i);
}
CMC_TEST_PASS_ELSE_FAIL(passed);
l_free(l);
});
CMC_CREATE_TEST(pop_front[count], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 250; i++)
l_push_back(l, i);
bool passed = true;
cmc_assert(l_pop_front(l));
for (size_t i = 0; i < l_count(l); i++)
{
passed = passed && l_get(l, i) == i;
cmc_assert_equals(size_t, l_get(l, i), i);
}
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200);
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 250 - 1);
l_free(l);
});
CMC_CREATE_TEST(pop_front[count item_preservation], {
CMC_CREATE_TEST(pop_front[item_preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 200; i++)
for (size_t i = 0; i < 250; i++)
l_push_back(l, i);
bool passed = l_pop_front(l);
@@ -201,7 +315,7 @@ CMC_CREATE_UNIT(list_test, true, {
cmc_assert_equals(size_t, l_get(l, i), i + 1);
}
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 199);
CMC_TEST_PASS_ELSE_FAIL(passed);
l_free(l);
});