Added cmc_assert_total, cmc_assert_failed, better-looking unit test and other things

Started using functions from futils.h in unit test
Renamed unit tests
This commit is contained in:
Leonardo committed 2020-04-17 16:29:52 -03:00
1 parent 6f1fb7554e
commit 656c0e3b3a
21 files changed
+592 -305

No files matched your search

+1 -1
View File
@@ -20,6 +20,6 @@ utl: FORCE
clang-format --style=file -i ./src/utl/*.h
tests: FORCE
clang-format --style=file -i ./tests/main/unt/*.c ./tests/*.c
clang-format --style=file -i ./tests/main/unt/*.c ./tests/main/main.c ./tests/*.c
FORCE:
+241
View File
File diff suppressed because it is too large. Load diff
+135 -56
View File
@@ -45,83 +45,162 @@
#include "assert.h"
#include "timer.h"
#ifdef CMC_TEST_COLOR
static const char *cmc_test_color[] = { "\x1b[32m", "\x1b[31m", "\x1b[35m" };
#endif
struct cmc_test_info
{
uintmax_t total;
uintmax_t passed;
uintmax_t failed;
uintmax_t assert_total;
uintmax_t assert_failed;
bool aborted;
bool verbose;
};
static inline const char *cmc_test_color(int i)
{
#ifdef CMC_TEST_COLOR
// 0 - Default, all off
// 1 - Failed (red)
// 2 - Passed (green)
// 3 - Box (gray)
// 4 - Name (cyan)
// 5 - Total (yellow)
static const char *cmc_test_colors[] = {
"\x1b[0m", "\x1b[31m", "\x1b[32m", "\x1b[90m", "\x1b[36m", "\x1b[33m"
};
return cmc_test_colors[i];
#else
return "";
#endif
}
/* Logging function */
static void cmc_test_log(const char *unit_name, const char *current_test,
bool aborted, bool passed)
{
if (aborted)
{
#ifdef CMC_TEST_COLOR
printf("UNIT_TEST %s %sABORTED\x1b[0m AT %s\n", unit_name,
cmc_test_color[2], current_test);
#else
printf("UNIT_TEST %s ABORTED at %s\n", unit_name, current_test);
#endif
printf(" X UNIT TEST");
printf("%s", cmc_test_color(4));
printf(" %s ", unit_name);
printf("%sABORTED%s", cmc_test_color(5), cmc_test_color(0));
printf(" at %s\n", current_test);
}
else
{
#ifdef CMC_TEST_COLOR
printf("Test from \x1b[33m%s\x1b[0m %s%7s\x1b[0m %s\n", unit_name,
passed ? cmc_test_color[0] : cmc_test_color[1],
passed ? "PASSED" : "FAILED", current_test);
#else
printf("Test from %s %7s %s\n", unit_name, passed ? "PASSED" : "FAILED",
current_test);
#endif
printf("%s", passed ? cmc_test_color(2) : cmc_test_color(1));
printf(" |");
printf("%s", cmc_test_color(0));
printf(" %s", current_test);
size_t str_len = strlen(current_test);
if (str_len < 53)
{
printf(cmc_test_color(3));
for (size_t i = 0; i < 53 - str_len; i++)
putchar('.');
}
printf("%s", passed ? cmc_test_color(2) : cmc_test_color(1));
printf("%s", passed ? "PASSED" : "FAILED");
printf("%s\n", cmc_test_color(0));
}
}
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY) \
uintmax_t UNAME(void) \
{ \
const char *unit_name = #UNAME; \
const char *current_test = NULL; \
\
struct cmc_test_info tinfo = { 0 }; \
struct cmc_timer timer = { 0 }; \
\
tinfo.verbose = VERBOSE; \
\
/* Tests */ \
cmc_timer_start(timer); \
\
BODY; \
\
cmc_timer_stop(timer); \
\
unittest_abort: \
if (tinfo.aborted) \
{ \
cmc_test_log(unit_name, current_test, true, false); \
} \
\
printf("+--------------------------------------------------+\n"); \
printf("| Unit Test Report : %-30s|\n", unit_name); \
printf("| TOTAL : %10" PRIuMAX " |\n", \
tinfo.total); \
printf("| PASSED : %10" PRIuMAX " |\n", \
tinfo.passed); \
printf("| FAILED : %10" PRIuMAX " |\n", \
tinfo.failed); \
printf("| |\n"); \
printf("| Total Unit Test Runtime : %9.0f milliseconds |\n", \
timer.result); \
printf("+--------------------------------------------------+\n"); \
\
return tinfo.failed; \
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY) \
uintmax_t UNAME(void) \
{ \
const char *unit_name = #UNAME; \
const char *current_test = NULL; \
\
struct cmc_test_info tinfo = { 0 }; \
struct cmc_timer timer = { 0 }; \
\
tinfo.verbose = VERBOSE; \
tinfo.assert_total = cmc_assert_total; \
tinfo.assert_failed = cmc_assert_failed; \
\
/* Tests */ \
cmc_timer_start(timer); \
\
printf(cmc_test_color(3)); \
printf( \
" +---------------------------------------------------------------+\n"); \
printf(" | "); \
printf(cmc_test_color(0)); \
printf("Unit "); \
printf(cmc_test_color(4)); \
printf("%-56s", unit_name); \
printf(cmc_test_color(3)); \
printf( \
" |\n +---------------------------------------------------------------+"); \
printf("%s\n", cmc_test_color(0)); \
\
BODY; \
\
cmc_timer_stop(timer); \
\
tinfo.assert_total = cmc_assert_total - tinfo.assert_total; \
tinfo.assert_failed = cmc_assert_failed - tinfo.assert_failed; \
\
unittest_abort: \
if (tinfo.aborted) \
{ \
cmc_test_log(unit_name, current_test, true, false); \
} \
\
printf(cmc_test_color(3)); \
printf( \
" +---------------------------------------------------------------+\n | "); \
printf(cmc_test_color(0)); \
printf("Summary : "); \
printf(cmc_test_color(4)); \
printf("%-52s", unit_name); \
printf("%s|\n", cmc_test_color(3)); \
printf( \
" +---------++----------------+-----------------+-----------------+\n | "); \
printf(cmc_test_color(0)); \
printf("Tests "); \
printf(cmc_test_color(3)); \
printf("||"); \
printf(cmc_test_color(5)); \
printf(" Total %8" PRIuMAX "", tinfo.total); \
printf(cmc_test_color(3)); \
printf(" | "); \
printf(cmc_test_color(2)); \
printf("Passed %8" PRIuMAX "", tinfo.passed); \
printf(cmc_test_color(3)); \
printf(" | "); \
printf(cmc_test_color(1)); \
printf("Failed %8" PRIuMAX "", tinfo.failed); \
printf(cmc_test_color(3)); \
printf(" |\n | "); \
printf(cmc_test_color(0)); \
printf("Asserts "); \
printf(cmc_test_color(3)); \
printf("||"); \
printf(cmc_test_color(5)); \
printf(" Total %8" PRIuMAX "", tinfo.assert_total); \
printf(cmc_test_color(3)); \
printf(" | "); \
printf(cmc_test_color(2)); \
printf("Passed %8" PRIuMAX "", \
tinfo.assert_total - tinfo.assert_failed); \
printf(cmc_test_color(3)); \
printf(" | "); \
printf(cmc_test_color(1)); \
printf("Failed %8" PRIuMAX "", tinfo.assert_failed); \
printf(cmc_test_color(3)); \
printf(" |\n"); \
printf( \
" +---------++----------------+-----------------+-----------------+\n | "); \
printf(cmc_test_color(0)); \
printf("Total Runtime : %32.0f milliseconds", timer.result); \
printf(" %s|\n", cmc_test_color(3)); \
printf( \
" +---------------------------------------------------------------+\n"); \
printf(cmc_test_color(0)); \
printf("\n\n"); \
\
return tinfo.failed; \
}
#define CMC_CREATE_TEST(TNAME, BODY) \
+9 -4
View File
@@ -1,27 +1,32 @@
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra
CFLAGS += -Wno-unused -Wno-missing-braces -DCMC_TEST_COLOR
CFLAGS += -Wno-unused -Wno-missing-braces
CVFLAGS = --coverage -O0
INCLUDE = ../../src/
main: FORCE
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE)
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
./main.exe
gcov ./main.c
dev: FORCE
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE)
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
./main.exe
gcov ./main.c -n
rm *.gcda *.gcno *.exe
windev: FORCE
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE)
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
./main.exe
gcov ./main.c -n
del *.gcda *.gcno *.exe
nocov: FORCE
$(CC) main.c -o main.exe $(CFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
./main.exe
rm *.exe
bare: FORCE
$(CC) main.c -o main.exe $(CFLAGS) -I $(INCLUDE)
./main.exe
rm *.exe
+42 -21
View File
@@ -16,35 +16,56 @@
#include "unt/treemap.c"
#include "unt/treeset.c"
#define cmc_run(unit, unit_fails, test_fails) \
do \
{ \
uintmax_t f = unit(); \
\
if (f != 0) \
unit_fails += 1; \
\
test_fails += f; \
\
} while (0)
int main(void)
{
struct cmc_timer timer;
cmc_timer_start(timer);
uintmax_t failed = 0;
uintmax_t tests = 0, units = 0, f;
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();
cmc_run(BidiMap, units, tests);
cmc_run(Deque, units, tests);
cmc_run(HashMap, units, tests);
cmc_run(HashSet, units, tests);
cmc_run(Heap, units, tests);
cmc_run(IntervalHeap, units, tests);
cmc_run(LinkedList, units, tests);
cmc_run(List, units, tests);
cmc_run(MultiMap, units, tests);
cmc_run(MultiSet, units, tests);
cmc_run(Queue, units, tests);
cmc_run(SortedList, units, tests);
cmc_run(Stack, units, tests);
cmc_run(TreeMap, units, tests);
cmc_run(TreeSet, units, tests);
cmc_timer_stop(timer);
printf("+--------------------------------------------------+\n");
printf("| Total Tests Failed : %14" PRIuMAX " tests |\n", failed);
printf("| Total Running Time : %14.0lf milliseconds |\n", timer.result);
printf("+--------------------------------------------------+\n");
printf(
" +---------------------------------------------------------------+\n");
printf(
" | SUMMARY |\n");
printf(
" +---------------------------------------------------------------+\n");
printf(" | Total Units Failed : %25" PRIuMAX " units |\n", tests);
printf(" | Total Tests Failed : %25" PRIuMAX " tests |\n", tests);
printf(" | Total Asserts Failed : %25" PRIuMAX " asserts |\n",
cmc_assert_failed);
printf(" | Total Runtime : %25.0lf milliseconds |\n", timer.result);
printf(
" +---------------------------------------------------------------+\n");
return failed;
return tests;
}
+26 -31
View File
@@ -5,39 +5,35 @@
#include "../src/bidimap.c"
struct bidimap_fkey *bm_fkey =
&(struct bidimap_fkey){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct bidimap_fkey *bm_fkey = &(struct bidimap_fkey){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
struct bidimap_fval *bm_fval =
&(struct bidimap_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct bidimap_fval *bm_fval = &(struct bidimap_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
struct bidimap_fkey *bm_fkey_counter =
&(struct bidimap_fkey){ .cmp = k_c_cmp,
.cpy = k_c_cpy,
.str = k_c_str,
.free = k_c_free,
.hash = k_c_hash,
.pri = k_c_pri };
struct bidimap_fkey *bm_fkey_counter = &(struct bidimap_fkey){ .cmp = k_c_cmp,
.cpy = k_c_cpy,
.str = k_c_str,
.free = k_c_free,
.hash = k_c_hash,
.pri = k_c_pri };
struct bidimap_fval *bm_fval_counter =
&(struct bidimap_fval){ .cmp = v_c_cmp,
.cpy = v_c_cpy,
.str = v_c_str,
.free = v_c_free,
.hash = v_c_hash,
.pri = v_c_pri };
struct bidimap_fval *bm_fval_counter = &(struct bidimap_fval){ .cmp = v_c_cmp,
.cpy = v_c_cpy,
.str = v_c_str,
.free = v_c_free,
.hash = v_c_hash,
.pri = v_c_pri };
CMC_CREATE_UNIT(bidimap_test, true, {
CMC_CREATE_UNIT(BidiMap, true, {
CMC_CREATE_TEST(new, {
struct bidimap *map = bm_new(100, 0.6, bm_fkey, bm_fval);
@@ -194,8 +190,7 @@ CMC_CREATE_UNIT(bidimap_test, true, {
node.free = free;
node.calloc = calloc;
map =
bm_new_custom(100, 0.6, bm_fkey, bm_fval, &node, callbacks);
map = bm_new_custom(100, 0.6, bm_fkey, bm_fval, &node, callbacks);
cmc_assert_not_equals(ptr, NULL, map);
+7 -8
View File
@@ -5,15 +5,14 @@
#include "../src/deque.c"
struct deque_fval *d_fval =
&(struct deque_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct deque_fval *d_fval = &(struct deque_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(deque_test, true, {
CMC_CREATE_UNIT(Deque, true, {
CMC_CREATE_TEST(new, {
struct deque *d = d_new(1000000, d_fval);
+18 -21
View File
@@ -5,23 +5,21 @@
#include "../src/hashmap.c"
struct hashmap_fkey *hm_fkey =
&(struct hashmap_fkey){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct hashmap_fkey *hm_fkey = &(struct hashmap_fkey){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
struct hashmap_fval *hm_fval =
&(struct hashmap_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct hashmap_fval *hm_fval = &(struct hashmap_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(hashmap_test, true, {
CMC_CREATE_UNIT(HashMap, true, {
CMC_CREATE_TEST(new, {
struct hashmap *map = hm_new(943722, 0.6, hm_fkey, hm_fval);
@@ -40,8 +38,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
});
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
struct hashmap *map =
hm_new(UINT64_MAX, 0.99, hm_fkey, hm_fval);
struct hashmap *map = hm_new(UINT64_MAX, 0.99, hm_fkey, hm_fval);
cmc_assert_equals(ptr, NULL, map);
});
@@ -104,7 +101,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
cmc_assert_equals(size_t, capacity - 1, map->buffer[capacity - 1].key);
cmc_assert_equals(size_t, capacity, map->buffer[0].key);
hm_fkey->hash = hash;
hm_fkey->hash = cmc_size_hash;
hm_free(map);
});
@@ -125,7 +122,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, map->buffer[i].dist);
hm_fkey->hash = hash;
hm_fkey->hash = cmc_size_hash;
hm_free(map);
});
@@ -151,7 +148,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
cmc_assert_equals(size_t, 0, map->buffer[capacity - 1].dist);
cmc_assert_equals(size_t, 1, map->buffer[0].dist);
hm_fkey->hash = hash;
hm_fkey->hash = cmc_size_hash;
hm_free(map);
});
@@ -172,7 +169,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
for (size_t i = 0; i < 6; i++)
cmc_assert_equals(size_t, i, hm_impl_get_entry(map, i)->dist);
hm_fkey->hash = hash;
hm_fkey->hash = cmc_size_hash;
hm_free(map);
});
+13 -16
View File
@@ -5,15 +5,14 @@
#include "../src/hashset.c"
struct hashset_fval *hs_fval =
&(struct hashset_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct hashset_fval *hs_fval = &(struct hashset_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(hashset_test, true, {
CMC_CREATE_UNIT(HashSet, true, {
CMC_CREATE_TEST(new, {
struct hashset *set = hs_new(943722, 0.6, hs_fval);
@@ -96,7 +95,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
set->buffer[capacity - 1].value);
cmc_assert_equals(size_t, capacity, set->buffer[0].value);
hs_fval->hash = hash;
hs_fval->hash = cmc_size_hash;
hs_free(set);
});
@@ -117,7 +116,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, set->buffer[i].dist);
hs_fval->hash = hash;
hs_fval->hash = cmc_size_hash;
hs_free(set);
});
@@ -143,7 +142,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, 0, set->buffer[capacity - 1].dist);
cmc_assert_equals(size_t, 1, set->buffer[0].dist);
hs_fval->hash = hash;
hs_fval->hash = cmc_size_hash;
hs_free(set);
});
@@ -164,7 +163,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 0; i < 6; i++)
cmc_assert_equals(size_t, i, hs_impl_get_entry(set, i)->dist);
hs_fval->hash = hash;
hs_fval->hash = cmc_size_hash;
hs_free(set);
});
@@ -339,8 +338,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
});
CMC_CREATE_TEST(full, {
struct hashset *set =
hs_new(cmc_hashtable_primes[0], 0.99999, hs_fval);
struct hashset *set = hs_new(cmc_hashtable_primes[0], 0.99999, hs_fval);
cmc_assert_not_equals(ptr, NULL, set);
@@ -481,8 +479,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
});
CMC_CREATE_TEST(callbacks, {
struct hashset *set =
hs_new_custom(100, 0.6, hs_fval, NULL, callbacks);
struct hashset *set = hs_new_custom(100, 0.6, hs_fval, NULL, callbacks);
cmc_assert_not_equals(ptr, NULL, set);
+8 -8
View File
@@ -5,14 +5,14 @@
#include "../src/heap.c"
struct heap_fval *h_fval = &(struct heap_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct heap_fval *h_fval = &(struct heap_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(heap_test, true, {
CMC_CREATE_UNIT(Heap, true, {
CMC_CREATE_TEST(new, {
struct heap *h = h_new(1000000, cmc_max_heap, h_fval);
@@ -136,7 +136,7 @@ CMC_CREATE_UNIT(heap_test, true, {
cmc_assert(h_remove(h));
}
cmc_assert_array_sorted_any(size_t, arr, cmp, 0, 99);
cmc_assert_array_sorted_any(size_t, arr, cmc_size_cmp, 0, 99);
h_free(h);
});
+8 -9
View File
@@ -6,14 +6,14 @@
#include "../src/intervalheap.c"
struct intervalheap_fval *ih_fval =
&(struct intervalheap_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
&(struct intervalheap_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(intervalheap_test, true, {
CMC_CREATE_UNIT(IntervalHeap, true, {
CMC_CREATE_TEST(new, {
struct intervalheap *ih = ih_new(1000000, ih_fval);
@@ -260,8 +260,7 @@ CMC_CREATE_UNIT(intervalheap_test, true, {
});
CMC_CREATE_TEST(callbacks, {
struct intervalheap *ih =
ih_new_custom(100, ih_fval, NULL, callbacks);
struct intervalheap *ih = ih_new_custom(100, ih_fval, NULL, callbacks);
cmc_assert_not_equals(ptr, NULL, ih);
+7 -7
View File
@@ -6,14 +6,14 @@
#include "../src/linkedlist.c"
struct linkedlist_fval *ll_fval =
&(struct linkedlist_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
&(struct linkedlist_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(linkedlist_test, true, {
CMC_CREATE_UNIT(LinkedList, true, {
CMC_CREATE_TEST(new, {
struct linkedlist *ll = ll_new(ll_fval);
+7 -7
View File
@@ -5,14 +5,14 @@
#include "../src/list.c"
struct list_fval *l_fval = &(struct list_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct list_fval *l_fval = &(struct list_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(list_test, true, {
CMC_CREATE_UNIT(List, true, {
CMC_CREATE_TEST(new, {
struct list *l = l_new(1000000, l_fval);
+14 -17
View File
@@ -5,23 +5,21 @@
#include "../src/multimap.c"
struct multimap_fkey *mm_fkey =
&(struct multimap_fkey){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct multimap_fkey *mm_fkey = &(struct multimap_fkey){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
struct multimap_fval *mm_fval =
&(struct multimap_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct multimap_fval *mm_fval = &(struct multimap_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(multimap_test, true, {
CMC_CREATE_UNIT(MultiMap, true, {
CMC_CREATE_TEST(new, {
struct multimap *map = mm_new(943722, 0.8, mm_fkey, mm_fval);
@@ -40,8 +38,7 @@ CMC_CREATE_UNIT(multimap_test, true, {
});
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
struct multimap *map =
mm_new(UINT64_MAX, 0.99, mm_fkey, mm_fval);
struct multimap *map = mm_new(UINT64_MAX, 0.99, mm_fkey, mm_fval);
cmc_assert_equals(ptr, NULL, map);
});
+7 -8
View File
@@ -5,15 +5,14 @@
#include "../src/multiset.c"
struct multiset_fval *ms_fval =
&(struct multiset_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct multiset_fval *ms_fval = &(struct multiset_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(multiset_test, true, {
CMC_CREATE_UNIT(MultiSet, true, {
CMC_CREATE_TEST(new, {
struct multiset *set = ms_new(943722, 0.6, ms_fval);
+7 -8
View File
@@ -5,15 +5,14 @@
#include "../src/queue.c"
struct queue_fval *q_fval =
&(struct queue_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct queue_fval *q_fval = &(struct queue_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(queue_test, true, {
CMC_CREATE_UNIT(Queue, true, {
CMC_CREATE_TEST(new, {
struct queue *q = q_new(1000000, q_fval);
+10 -10
View File
@@ -6,14 +6,14 @@
#include "../src/sortedlist.c"
struct sortedlist_fval *sl_fval =
&(struct sortedlist_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
&(struct sortedlist_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(sortedlist_test, true, {
CMC_CREATE_UNIT(SortedList, true, {
CMC_CREATE_TEST(new, {
struct sortedlist *sl = sl_new(1000000, sl_fval);
@@ -67,7 +67,8 @@ CMC_CREATE_UNIT(sortedlist_test, true, {
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);
cmc_assert_array_sorted_any(size_t, sl->buffer, cmc_size_cmp, 0,
sl->count - 1);
sl_free(sl);
});
@@ -235,8 +236,7 @@ CMC_CREATE_UNIT(sortedlist_test, true, {
});
CMC_CREATE_TEST(callbacks, {
struct sortedlist *sl =
sl_new_custom(100, sl_fval, NULL, callbacks);
struct sortedlist *sl = sl_new_custom(100, sl_fval, NULL, callbacks);
cmc_assert_not_equals(ptr, NULL, sl);
+7 -8
View File
@@ -5,15 +5,14 @@
#include "../src/stack.c"
struct stack_fval *s_fval =
&(struct stack_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct stack_fval *s_fval = &(struct stack_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(stack_test, true, {
CMC_CREATE_UNIT(Stack, true, {
CMC_CREATE_TEST(new, {
struct stack *s = s_new(1000000, s_fval);
+14 -17
View File
@@ -5,23 +5,21 @@
#include "../src/treemap.c"
struct treemap_fkey *tm_fkey =
&(struct treemap_fkey){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct treemap_fkey *tm_fkey = &(struct treemap_fkey){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
struct treemap_fval *tm_fval =
&(struct treemap_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct treemap_fval *tm_fval = &(struct treemap_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(treemap_test, true, {
CMC_CREATE_UNIT(TreeMap, true, {
CMC_CREATE_TEST(new, {
struct treemap *map = tm_new(tm_fkey, tm_fval);
@@ -142,8 +140,7 @@ CMC_CREATE_UNIT(treemap_test, true, {
});
CMC_CREATE_TEST(callbacks, {
struct treemap *map =
tm_new_custom(tm_fkey, tm_fval, NULL, callbacks);
struct treemap *map = tm_new_custom(tm_fkey, tm_fval, NULL, callbacks);
cmc_assert_not_equals(ptr, NULL, map);
+7 -8
View File
@@ -5,15 +5,14 @@
#include "../src/treeset.c"
struct treeset_fval *ts_fval =
&(struct treeset_fval){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct treeset_fval *ts_fval = &(struct treeset_fval){ .cmp = cmc_size_cmp,
.cpy = NULL,
.str = cmc_size_str,
.free = NULL,
.hash = cmc_size_hash,
.pri = cmc_size_cmp };
CMC_CREATE_UNIT(treeset_test, true, {
CMC_CREATE_UNIT(TreeSet, true, {
CMC_CREATE_TEST(new, {
struct treeset *set = ts_new(ts_fval);
+4 -40
View File
@@ -2,48 +2,12 @@
#ifndef CMC_UNIT_TEST_UTL__
#define CMC_UNIT_TEST_UTL__
#include <cmc/hashmap.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
int cmp(size_t a, size_t b)
{
return (a > b) - (a < b);
}
size_t copy(size_t a)
{
return a;
}
bool str(FILE *fptr, size_t a)
{
return fprintf(fptr, "%" PRIuMAX " ", a) > 0;
}
void custom_free(size_t a)
{
// blank
// Free any resources if necessary
}
size_t hash(size_t a)
{
a += ~(a << 15);
a ^= (a >> 10);
a += (a << 3);
a ^= (a >> 6);
a += ~(a << 11);
a ^= (a >> 16);
return a;
}
int pri(size_t a, size_t b)
{
// Could contain different logic
return cmp(a, b);
}
#include "cmc/hashmap.h"
#include "utl/futils.h"
size_t numhash(size_t a)
{
@@ -116,7 +80,7 @@ size_t k_c_hash(size_t x)
int k_c_pri(size_t a, size_t b)
{
k_total_pri++;
return cmp(a, b);
return cmc_size_cmp(a, b);
}
int v_c_cmp(size_t a, size_t b)
@@ -154,7 +118,7 @@ size_t v_c_hash(size_t x)
int v_c_pri(size_t a, size_t b)
{
v_total_pri++;
return cmp(a, b);
return cmc_size_cmp(a, b);
}
// callbacks