Tests update

This commit is contained in:
Leonardo committed 2019-07-02 01:05:16 -03:00
1 parent 78cfc0c335
commit 6a2cb70fb5
11 files changed
+1157 -8

No files matched your search

+46 -1
View File
@@ -1,3 +1,5 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/deque.c"
CMC_CREATE_UNIT(deque_test, true, {
@@ -16,7 +18,7 @@ CMC_CREATE_UNIT(deque_test, true, {
d_free(d);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
deque *d = d_new(0);
@@ -25,4 +27,47 @@ CMC_CREATE_UNIT(deque_test, true, {
CMC_TEST_PASS_ELSE_FAIL(d == NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
deque *d = d_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, d);
CMC_TEST_PASS_ELSE_FAIL(d == NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 0; i < 50; i++)
d_push_back(d, i);
cmc_assert_equals(size_t, 50, d_count(d));
d_clear(d);
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert_equals(size_t, 100, d_capacity(d));
CMC_TEST_PASS_ELSE_FAIL(d_count(d) == 0 && d_capacity(d) == 100);
d_free(d);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
deque *d = d_new(1);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 0; i < 50; i++)
d_push_back(d, i);
cmc_assert_equals(size_t, 50, d_count(d));
CMC_TEST_PASS_ELSE_FAIL(d_count(d) == 50);
d_free(d);
});
});
+56
View File
@@ -0,0 +1,56 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/hashmap.c"
#include "../src/utl.c"
CMC_CREATE_UNIT(hashmap_test, true, {
CMC_CREATE_TEST(new, {
hashmap *map = hm_new(943722, 0.6, cmp, hash);
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_TEST_PASS_ELSE_FAIL(passed);
hm_free(map);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
hashmap *map = hm_new(0, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
CMC_TEST_PASS_ELSE_FAIL(map == NULL);
});
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);
CMC_TEST_PASS_ELSE_FAIL(map == NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 50; i++)
hm_insert(map, i, i);
cmc_assert_equals(size_t, 50, hm_count(map));
hm_clear(map);
cmc_assert_equals(size_t, 0, hm_count(map));
CMC_TEST_PASS_ELSE_FAIL(hm_count(map) == 0);
hm_free(map);
});
});
+56
View File
@@ -0,0 +1,56 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/hashset.c"
#include "../src/utl.c"
CMC_CREATE_UNIT(hashset_test, true, {
CMC_CREATE_TEST(new, {
hashset *set = hs_new(943722, 0.6, cmp, hash);
bool passed = (set->capacity >= (943722 / 0.6)) && set->count == 0 && set->buffer;
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(hs_capacity(set) > (943722 / 0.6));
CMC_TEST_PASS_ELSE_FAIL(passed);
hs_free(set);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
hashset *set = hs_new(0, 0.6, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
CMC_TEST_PASS_ELSE_FAIL(set == NULL);
});
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);
CMC_TEST_PASS_ELSE_FAIL(set == NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 0; i < 50; i++)
hs_insert(set, i);
cmc_assert_equals(size_t, 50, hs_count(set));
hs_clear(set);
cmc_assert_equals(size_t, 0, hs_count(set));
CMC_TEST_PASS_ELSE_FAIL(hs_count(set) == 0);
hs_free(set);
});
});
+39 -4
View File
@@ -1,3 +1,5 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/list.c"
CMC_CREATE_UNIT(list_test, true, {
@@ -12,10 +14,7 @@ CMC_CREATE_UNIT(list_test, true, {
cmc_assert_equals(size_t, 0, l_count(l));
cmc_assert_not_equals(ptr, NULL, l->buffer);
if (passed)
CMC_TEST_PASS();
else
CMC_TEST_FAIL();
CMC_TEST_PASS_ELSE_FAIL(passed);
l_free(l);
});
@@ -28,6 +27,14 @@ CMC_CREATE_UNIT(list_test, true, {
CMC_TEST_PASS_ELSE_FAIL(l == NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
list *l = l_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, l);
CMC_TEST_PASS_ELSE_FAIL(l == NULL);
});
CMC_CREATE_TEST(new_from[count item_preservation], {
size_t v[5];
@@ -76,13 +83,41 @@ CMC_CREATE_UNIT(list_test, true, {
for (size_t i = 0; i < 50; i++)
l_push_back(l, i);
cmc_assert_equals(size_t, 50, l_count(l));
l_clear(l);
cmc_assert_equals(size_t, 0, l_count(l));
cmc_assert_equals(size_t, 100, l_capacity(l));
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 0 && l_capacity(l) == 100);
l_free(l);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
list *l = l_new(1);
cmc_assert_not_equals(ptr, NULL, l);
for (size_t i = 0; i < 100; i++)
l_push_back(l, i);
cmc_assert_equals(size_t, 100, l_count(l));
bool passed = true;
for (size_t i = 0; i < 100; i++)
{
passed = passed && l_get(l, i) == i;
cmc_assert_equals(size_t, i, l_get(l, i));
}
CMC_TEST_PASS_ELSE_FAIL(passed);
l_free(l);
});
CMC_CREATE_TEST(push_front[count capacity item_preservation grow], {
list *l = l_new(100);