Fast forward changes (read desc)

Freezing tests outside of ./tests/main
Formatting all files in ./src and ./tests except for ./tests/codecov
Created makefile for automated code formatting using clang-format
Now bidimap and deque operate with Functions Tables
This commit is contained in:
Leonardo committed 2020-01-30 18:20:35 -03:00
1 parent b2bef4e3cc
commit 9344440f41
30 files changed
+985 -894

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ addons:
script:
- sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
- export CC=gcc-7
- make -C ./tests/
# - make -C ./tests/
- make -C ./tests/main/
- make -C ./tests/codecov/
after_success:
+19 -2
View File
@@ -1,5 +1,22 @@
# This file is useful to format all the source files and header in this library using clang-format
.PHONY
main:
.PHONY: all cmc dev sac utl tests FORCE
all: cmc dev sac utl tests
cmc: FORCE
clang-format --style=file -i ./src/cmc/*.h
dev: FORCE
clang-format --style=file -i ./src/dev/*.h
sac: FORCE
clang-format --style=file -i ./src/sac/*.h
utl: FORCE
clang-format --style=file -i ./utl/sac/*.h
tests: FORCE
clang-format --style=file -i ./tests/main/unt/*.c ./tests/*.c
FORCE:
+5 -2
View File
@@ -76,7 +76,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
@@ -275,7 +275,7 @@ struct cmc_callbacks_bidimap
int (*cmp)(V, V); \
\
/* Copy function */ \
K (*cpy)(V); \
V (*cpy)(V); \
\
/* To string function */ \
bool (*str)(FILE *, V); \
@@ -412,6 +412,9 @@ struct cmc_callbacks_bidimap
if (capacity >= UINTMAX_MAX * load) \
return NULL; \
\
if (!f_val) \
return NULL; \
\
size_t real_capacity = PFX##_impl_calculate_size(capacity / load); \
\
struct SNAME *_map_ = alloc->malloc(sizeof(struct SNAME)); \
+606 -564
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -69,7 +69,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -69,7 +69,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -80,7 +80,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -71,7 +71,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -78,7 +78,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -93,7 +93,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -93,7 +93,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -71,7 +71,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -93,7 +93,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -72,7 +72,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -78,7 +78,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -69,7 +69,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+1 -1
View File
@@ -69,7 +69,7 @@ static struct
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int INVALID; // Invalid argument
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
+7 -4
View File
@@ -1,7 +1,7 @@
#include "../src/macro_collections.h"
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
int intcmp(int a, int b)
{
@@ -51,9 +51,12 @@ int main(void)
struct mmap *mm = mm_new(1000, 0.8, intcmp, inthash);
struct mset *ms = ms_new(1000, 0.6, intcmp, inthash);
bool a[13] = {false, false, false, false, false, false, false, false, false, false, false, false, false},
b[13] = {false, false, false, false, false, false, false, false, false, false, false, false, false},
c[13] = {true, true, true, true, true, true, true, true, true, true, true, true, true};
bool a[13] = { false, false, false, false, false, false, false,
false, false, false, false, false, false },
b[13] = { false, false, false, false, false, false, false,
false, false, false, false, false, false },
c[13] = { true, true, true, true, true, true, true,
true, true, true, true, true, true };
b[0] = d_contains(d, 1, intcmp);
b[1] = hm_contains(hm, 1);
+22 -62
View File
@@ -1,7 +1,7 @@
#include "../src/macro_collections.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
int intcmp(int a, int b)
{
@@ -81,62 +81,42 @@ int main(void)
assert(ms_insert(ms, i));
}
int sums[16] = {0};
int sums[16] = { 0 };
CMC_FOR_EACH(d, deque, d, {
sums[0] += d_iter_value(&iter);
});
CMC_FOR_EACH(d, deque, d, { sums[0] += d_iter_value(&iter); });
CMC_FOR_EACH(hm, hmap, hm, {
sums[1] += hm_iter_key(&iter);
sums[2] += hm_iter_value(&iter);
});
CMC_FOR_EACH(hs, hset, hs, {
sums[3] += hs_iter_value(&iter);
});
CMC_FOR_EACH(hs, hset, hs, { sums[3] += hs_iter_value(&iter); });
CMC_FOR_EACH(h, heap, h, {
sums[4] += h_iter_value(&iter);
});
CMC_FOR_EACH(h, heap, h, { sums[4] += h_iter_value(&iter); });
CMC_FOR_EACH(ll, linked, ll, {
sums[5] += ll_iter_value(&iter);
});
CMC_FOR_EACH(ll, linked, ll, { sums[5] += ll_iter_value(&iter); });
CMC_FOR_EACH(l, list, l, {
sums[6] += l_iter_value(&iter);
});
CMC_FOR_EACH(l, list, l, { sums[6] += l_iter_value(&iter); });
CMC_FOR_EACH(q, queue, q, {
sums[7] += q_iter_value(&iter);
});
CMC_FOR_EACH(q, queue, q, { sums[7] += q_iter_value(&iter); });
CMC_FOR_EACH(s, stack, s, {
sums[8] += s_iter_value(&iter);
});
CMC_FOR_EACH(s, stack, s, { sums[8] += s_iter_value(&iter); });
CMC_FOR_EACH(tm, tmap, tm, {
sums[9] += tm_iter_key(&iter);
sums[10] += tm_iter_value(&iter);
});
CMC_FOR_EACH(ts, tset, ts, {
sums[11] += ts_iter_value(&iter);
});
CMC_FOR_EACH(ts, tset, ts, { sums[11] += ts_iter_value(&iter); });
CMC_FOR_EACH(ih, iheap, ih, {
sums[12] += ih_iter_value(&iter);
});
CMC_FOR_EACH(ih, iheap, ih, { sums[12] += ih_iter_value(&iter); });
CMC_FOR_EACH(mm, mmap, mm, {
sums[13] += mm_iter_key(&iter);
sums[14] += mm_iter_value(&iter);
});
CMC_FOR_EACH(ms, mset, ms, {
sums[15] += ms_iter_value(&iter);
});
CMC_FOR_EACH(ms, mset, ms, { sums[15] += ms_iter_value(&iter); });
printf("\n-------------------- CMC_FOR_EACH --------------------\n");
if (sums[0] == 50005000)
@@ -196,60 +176,40 @@ int main(void)
memset(sums, 0, sizeof sums);
CMC_FOR_EACH_REV(d, deque, d, {
sums[0] += d_iter_value(&iter);
});
CMC_FOR_EACH_REV(d, deque, d, { sums[0] += d_iter_value(&iter); });
CMC_FOR_EACH_REV(hm, hmap, hm, {
sums[1] += hm_iter_key(&iter);
sums[2] += hm_iter_value(&iter);
});
CMC_FOR_EACH_REV(hs, hset, hs, {
sums[3] += hs_iter_value(&iter);
});
CMC_FOR_EACH_REV(hs, hset, hs, { sums[3] += hs_iter_value(&iter); });
CMC_FOR_EACH_REV(h, heap, h, {
sums[4] += h_iter_value(&iter);
});
CMC_FOR_EACH_REV(h, heap, h, { sums[4] += h_iter_value(&iter); });
CMC_FOR_EACH_REV(ll, linked, ll, {
sums[5] += ll_iter_value(&iter);
});
CMC_FOR_EACH_REV(ll, linked, ll, { sums[5] += ll_iter_value(&iter); });
CMC_FOR_EACH_REV(l, list, l, {
sums[6] += l_iter_value(&iter);
});
CMC_FOR_EACH_REV(l, list, l, { sums[6] += l_iter_value(&iter); });
CMC_FOR_EACH_REV(q, queue, q, {
sums[7] += q_iter_value(&iter);
});
CMC_FOR_EACH_REV(q, queue, q, { sums[7] += q_iter_value(&iter); });
CMC_FOR_EACH_REV(s, stack, s, {
sums[8] += s_iter_value(&iter);
});
CMC_FOR_EACH_REV(s, stack, s, { sums[8] += s_iter_value(&iter); });
CMC_FOR_EACH_REV(tm, tmap, tm, {
sums[9] += tm_iter_key(&iter);
sums[10] += tm_iter_value(&iter);
});
CMC_FOR_EACH_REV(ts, tset, ts, {
sums[11] += ts_iter_value(&iter);
});
CMC_FOR_EACH_REV(ts, tset, ts, { sums[11] += ts_iter_value(&iter); });
CMC_FOR_EACH_REV(ih, iheap, ih, {
sums[12] += ih_iter_value(&iter);
});
CMC_FOR_EACH_REV(ih, iheap, ih, { sums[12] += ih_iter_value(&iter); });
CMC_FOR_EACH_REV(mm, mmap, mm, {
sums[13] += mm_iter_key(&iter);
sums[14] += mm_iter_value(&iter);
});
CMC_FOR_EACH_REV(ms, mset, ms, {
sums[15] += ms_iter_value(&iter);
});
CMC_FOR_EACH_REV(ms, mset, ms, { sums[15] += ms_iter_value(&iter); });
printf("-------------------- CMC_FOR_EACH_REV --------------------\n");
if (sums[0] == 50005000)
+79 -58
View File
@@ -33,66 +33,87 @@ CMC_COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* K */, int)
CMC_COLLECTION_GENERATE(MULTIMAP, mm, mmap, int, double)
CMC_COLLECTION_GENERATE(MULTISET, ms, mset, /* K */, int)
#define ITERATOR_TEST(NAME, PFX, sname, initfunc, insertbody, sumbody, validation1, validation2) \
void NAME##_iterator_test(void) \
{ \
int sum1 = 0; \
double sum2 = 0.0; \
\
struct sname *coll = initfunc; \
for (int i = 0; i < 10; i++) \
{ \
insertbody; \
} \
\
struct sname##_iter iter; \
PFX##_iter_init(&iter, coll); \
\
for (int j = 0; j < 4; j++) \
{ \
while (!PFX##_iter_end(&iter)) \
{ \
sumbody; \
PFX##_iter_next(&iter); \
} \
while (!PFX##_iter_start(&iter)) \
{ \
sumbody; \
PFX##_iter_prev(&iter); \
} \
} \
\
for (PFX##_iter_to_start(&iter); !PFX##_iter_end(&iter); PFX##_iter_next(&iter)) \
{ \
sumbody; \
} \
\
for (PFX##_iter_to_end(&iter); !PFX##_iter_start(&iter); PFX##_iter_prev(&iter)) \
{ \
sumbody; \
} \
\
PFX##_free(coll, NULL); \
\
if ((validation1) && (validation2)) \
printf("%12s PASSED\n", #NAME); \
else \
printf("%12s FAILED\n", #NAME); \
#define ITERATOR_TEST(NAME, PFX, sname, initfunc, insertbody, sumbody, \
validation1, validation2) \
void NAME##_iterator_test(void) \
{ \
int sum1 = 0; \
double sum2 = 0.0; \
\
struct sname *coll = initfunc; \
for (int i = 0; i < 10; i++) \
{ \
insertbody; \
} \
\
struct sname##_iter iter; \
PFX##_iter_init(&iter, coll); \
\
for (int j = 0; j < 4; j++) \
{ \
while (!PFX##_iter_end(&iter)) \
{ \
sumbody; \
PFX##_iter_next(&iter); \
} \
while (!PFX##_iter_start(&iter)) \
{ \
sumbody; \
PFX##_iter_prev(&iter); \
} \
} \
\
for (PFX##_iter_to_start(&iter); !PFX##_iter_end(&iter); \
PFX##_iter_next(&iter)) \
{ \
sumbody; \
} \
\
for (PFX##_iter_to_end(&iter); !PFX##_iter_start(&iter); \
PFX##_iter_prev(&iter)) \
{ \
sumbody; \
} \
\
PFX##_free(coll, NULL); \
\
if ((validation1) && (validation2)) \
printf("%12s PASSED\n", #NAME); \
else \
printf("%12s FAILED\n", #NAME); \
}
ITERATOR_TEST(DEQUE, d, deque, d_new(20), d_push_front(coll, i), sum1 += d_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(HASHMAP, hm, hmap, hm_new(50, 0.6, intcmp, inthash), hm_insert(coll, i, (double)i / 10.0), sum1 += hm_iter_key(&iter); sum2 += hm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
ITERATOR_TEST(HASHSET, hs, hset, hs_new(50, 0.6, intcmp, inthash), hs_insert(coll, i), sum1 += hs_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(HEAP, h, heap, h_new(20, cmc_max_heap, intcmp), h_insert(coll, i), sum1 += h_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(LINKEDLIST, ll, linked, ll_new(), ll_push_back(coll, i), sum1 += ll_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(LIST, l, list, l_new(20), l_push_back(coll, i), sum1 += l_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(QUEUE, q, queue, q_new(20), q_enqueue(coll, i), sum1 += q_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(STACK, s, stack, s_new(20), s_push(coll, i), sum1 += s_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(TREEMAP, tm, tmap, tm_new(intcmp), tm_insert(coll, i, (double)i / 10.0), sum1 += tm_iter_key(&iter); sum2 += tm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
ITERATOR_TEST(TREESET, ts, tset, ts_new(intcmp), ts_insert(coll, i), sum1 += ts_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(INTERVALHEAP, ih, iheap, ih_new(20, intcmp), ih_insert(coll, i), sum1 += ih_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(MULTIMAP, mm, mmap, mm_new(50, 0.8, intcmp, inthash), mm_insert(coll, i, (double)i / 10.0), sum1 += mm_iter_key(&iter); sum2 += mm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
ITERATOR_TEST(MULTISET, ms, mset, ms_new(50, 0.6, intcmp, inthash), ms_insert(coll, i), sum1 += ms_iter_value(&iter); sum2 += ms_iter_multiplicity(&iter), sum1 == 450, (size_t)sum2 == 100)
ITERATOR_TEST(DEQUE, d, deque, d_new(20), d_push_front(coll, i),
sum1 += d_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(HASHMAP, hm, hmap, hm_new(50, 0.6, intcmp, inthash),
hm_insert(coll, i, (double)i / 10.0), sum1 += hm_iter_key(&iter);
sum2 += hm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
ITERATOR_TEST(HASHSET, hs, hset, hs_new(50, 0.6, intcmp, inthash),
hs_insert(coll, i), sum1 += hs_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(HEAP, h, heap, h_new(20, cmc_max_heap, intcmp), h_insert(coll, i),
sum1 += h_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(LINKEDLIST, ll, linked, ll_new(), ll_push_back(coll, i),
sum1 += ll_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(LIST, l, list, l_new(20), l_push_back(coll, i),
sum1 += l_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(QUEUE, q, queue, q_new(20), q_enqueue(coll, i),
sum1 += q_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(STACK, s, stack, s_new(20), s_push(coll, i),
sum1 += s_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(TREEMAP, tm, tmap, tm_new(intcmp),
tm_insert(coll, i, (double)i / 10.0), sum1 += tm_iter_key(&iter);
sum2 += tm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
ITERATOR_TEST(TREESET, ts, tset, ts_new(intcmp), ts_insert(coll, i),
sum1 += ts_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(INTERVALHEAP, ih, iheap, ih_new(20, intcmp), ih_insert(coll, i),
sum1 += ih_iter_value(&iter), sum1 == 450, 1)
ITERATOR_TEST(MULTIMAP, mm, mmap, mm_new(50, 0.8, intcmp, inthash),
mm_insert(coll, i, (double)i / 10.0), sum1 += mm_iter_key(&iter);
sum2 += mm_iter_value(&iter), sum1 == 450, (int)sum2 == (int)45)
ITERATOR_TEST(MULTISET, ms, mset, ms_new(50, 0.6, intcmp, inthash),
ms_insert(coll, i), sum1 += ms_iter_value(&iter);
sum2 += ms_iter_multiplicity(&iter), sum1 == 450,
(size_t)sum2 == 100)
int main(void)
{
+46 -47
View File
@@ -7,23 +7,21 @@
CMC_GENERATE_BIDIMAP(bm, bidimap, size_t, size_t)
struct bidimap_ftab_key *bm_ftab_key = &(struct bidimap_ftab_key) {
.cmp = cmp,
.cpy = copy,
.str = to_string,
.free = custom_free,
.hash = hash,
.pri = priority
};
struct bidimap_ftab_key *bm_ftab_key =
&(struct bidimap_ftab_key){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct bidimap_ftab_val *bm_ftab_val = &(struct bidimap_ftab_val) {
.cmp = cmp,
.cpy = copy,
.str = to_string,
.free = custom_free,
.hash = hash,
.pri = priority
};
struct bidimap_ftab_val *bm_ftab_val =
&(struct bidimap_ftab_val){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
CMC_CREATE_UNIT(bidimap_test, true, {
CMC_CREATE_TEST(new, {
@@ -50,13 +48,13 @@ CMC_CREATE_UNIT(bidimap_test, true, {
});
CMC_CREATE_TEST(new_custom, {
struct bidimap *map = bm_new_custom(100, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
struct bidimap *map =
bm_new_custom(100, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){ .malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free },
&(struct cmc_callbacks_bidimap){ 0 });
cmc_assert_not_equals(ptr, NULL, map);
@@ -64,13 +62,13 @@ CMC_CREATE_UNIT(bidimap_test, true, {
});
CMC_CREATE_TEST(new_custom[insert remove], {
struct bidimap *map = bm_new_custom(500, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
struct bidimap *map =
bm_new_custom(500, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){ .malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free },
&(struct cmc_callbacks_bidimap){ 0 });
cmc_assert_not_equals(ptr, NULL, map);
@@ -233,13 +231,13 @@ CMC_CREATE_UNIT(bidimap_test, true, {
});
CMC_CREATE_TEST(remove_by_key[cleanup custom], {
struct bidimap *map = bm_new_custom(10000, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
struct bidimap *map =
bm_new_custom(10000, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){ .malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free },
&(struct cmc_callbacks_bidimap){ 0 });
cmc_assert_not_equals(ptr, NULL, map);
@@ -258,21 +256,21 @@ CMC_CREATE_UNIT(bidimap_test, true, {
struct bidimap_entry *k = map->key_buffer[i];
struct bidimap_entry *v = map->val_buffer[i];
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED)
&& (v == NULL || v == CMC_ENTRY_DELETED));
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) &&
(v == NULL || v == CMC_ENTRY_DELETED));
}
bm_free(map);
});
CMC_CREATE_TEST(remove_by_val[cleanup custom], {
struct bidimap *map = bm_new_custom(10000, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){
.malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free},
&(struct cmc_callbacks_bidimap){0});
struct bidimap *map =
bm_new_custom(10000, 0.6, bm_ftab_key, bm_ftab_val,
&(struct cmc_alloc_node){ .malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free },
&(struct cmc_callbacks_bidimap){ 0 });
cmc_assert_not_equals(ptr, NULL, map);
@@ -291,7 +289,8 @@ CMC_CREATE_UNIT(bidimap_test, true, {
struct bidimap_entry *k = map->key_buffer[i];
struct bidimap_entry *v = map->val_buffer[i];
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) && (v == NULL || v == CMC_ENTRY_DELETED));
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) &&
(v == NULL || v == CMC_ENTRY_DELETED));
}
bm_free(map);
+112 -91
View File
@@ -7,32 +7,40 @@
CMC_GENERATE_DEQUE(d, deque, size_t)
struct deque_ftab_val *d_ftab_val =
&(struct deque_ftab_val){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
CMC_CREATE_UNIT(deque_test, true, {
CMC_CREATE_TEST(new, {
struct deque *d = d_new(1000000);
struct deque *d = d_new(1000000, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert_not_equals(ptr, NULL, d->buffer);
cmc_assert_equals(size_t, 1000000, d->capacity);
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(new[capacity = 0], {
struct deque *d = d_new(0);
struct deque *d = d_new(0, d_ftab_val);
cmc_assert_equals(ptr, NULL, d);
});
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
struct deque *d = d_new(UINT64_MAX);
struct deque *d = d_new(UINT64_MAX, d_ftab_val);
cmc_assert_equals(ptr, NULL, d);
});
CMC_CREATE_TEST(clear[count capacity], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -41,16 +49,16 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 50, d_count(d));
d_clear(d, NULL);
d_clear(d);
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert_equals(size_t, 100, d_capacity(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
struct deque *d = d_new(1);
struct deque *d = d_new(1, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -60,11 +68,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 50, d_count(d));
cmc_assert_lesser_equals(size_t, d_capacity(d), d_count(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(buffer_growth[item preservation], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -77,17 +85,18 @@ CMC_CREATE_UNIT(deque_test, true, {
}
size_t sum = 0;
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
for (size_t i = d->front, j = 0; j < d->count;
i = (i + 1) % d->capacity, j++)
sum += d->buffer[i];
cmc_assert_equals(size_t, 1200, d_count(d));
cmc_assert_equals(size_t, 720600, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(push_front[count capacity], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -97,11 +106,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 150, d_count(d));
cmc_assert_greater(size_t, 100, d_capacity(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(push_front[item preservation], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -110,18 +119,19 @@ CMC_CREATE_UNIT(deque_test, true, {
size_t sum = 0;
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
for (size_t i = d->front, j = 0; j < d->count;
i = (i + 1) % d->capacity, j++)
{
sum += d->buffer[i];
}
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(push_back[count capacity], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -131,11 +141,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 150, d_count(d));
cmc_assert_greater(size_t, 100, d_capacity(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(push_back[item preservation], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -144,18 +154,19 @@ CMC_CREATE_UNIT(deque_test, true, {
size_t sum = 0;
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
for (size_t i = d->front, j = 0; j < d->count;
i = (i + 1) % d->capacity, j++)
{
sum += d->buffer[i];
}
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(pop_front[count capacity], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -169,11 +180,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(pop_front[item preservation], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -185,18 +196,19 @@ CMC_CREATE_UNIT(deque_test, true, {
size_t sum = 0;
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
for (size_t i = d->front, j = 0; j < d->count;
i = (i + 1) % d->capacity, j++)
{
sum += d->buffer[i];
}
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(pop_back[count capacity], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -210,11 +222,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(pop_back[item preservation], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -226,18 +238,19 @@ CMC_CREATE_UNIT(deque_test, true, {
size_t sum = 0;
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
for (size_t i = d->front, j = 0; j < d->count;
i = (i + 1) % d->capacity, j++)
{
sum += d->buffer[i];
}
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(Mixed IO, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -297,23 +310,23 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(front[count = 0], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
size_t r = d_front(d);
cmc_assert_equals(size_t, (size_t){0}, r);
cmc_assert_equals(size_t, (size_t){ 0 }, r);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(front[sum], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -338,23 +351,23 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(back[count = 0], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
size_t r = d_back(d);
cmc_assert_equals(size_t, (size_t){0}, r);
cmc_assert_equals(size_t, (size_t){ 0 }, r);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(back[sum], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -379,11 +392,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(contains, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -391,52 +404,52 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert(d_push_back(d, i));
for (size_t i = 1; i <= 20; i++)
cmc_assert(d_contains(d, i, cmp));
cmc_assert(d_contains(d, i));
d_clear(d, NULL);
d_clear(d);
for (size_t i = 1; i <= 20; i++)
cmc_assert(d_push_front(d, i));
for (size_t i = 1; i <= 20; i++)
cmc_assert(d_contains(d, i, cmp));
cmc_assert(d_contains(d, i));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(contains[count = 0], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(!d_contains(d, 10, cmp));
cmc_assert(!d_contains(d, 10));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(contains[count = 1], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(!d_contains(d, 10, cmp));
cmc_assert(!d_contains(d, 10));
cmc_assert(d_push_back(d, 100));
cmc_assert(d_contains(d, 100, cmp));
cmc_assert(!d_contains(d, 101, cmp));
cmc_assert(d_contains(d, 100));
cmc_assert(!d_contains(d, 101));
cmc_assert(d_pop_front(d));
cmc_assert(d_push_front(d, 100));
cmc_assert(d_contains(d, 100, cmp));
cmc_assert(!d_contains(d, 101, cmp));
cmc_assert(d_contains(d, 100));
cmc_assert(!d_contains(d, 101));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(empty, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -446,11 +459,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert(!d_empty(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(full, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -461,11 +474,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert(d_full(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(count, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -476,21 +489,21 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert_equals(size_t, 100, d_count(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(capacity, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert_equals(size_t, 100, d_capacity(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(resize, {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -506,11 +519,11 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert(d_resize(d, d_count(d)));
cmc_assert_equals(size_t, 150, d_capacity(d));
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(resize[item preservation], {
struct deque *d = d_new(100);
struct deque *d = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d);
@@ -526,18 +539,19 @@ CMC_CREATE_UNIT(deque_test, true, {
size_t sum = 0;
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
for (size_t i = d->front, j = 0; j < d->count;
i = (i + 1) % d->capacity, j++)
{
sum += d->buffer[i];
}
cmc_assert_equals(size_t, 11325, sum);
d_free(d, NULL);
d_free(d);
});
CMC_CREATE_TEST(copy_of, {
struct deque *d1 = d_new(100);
struct deque *d1 = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d1);
@@ -549,7 +563,7 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert(d_push_front(d1, i));
}
struct deque *d2 = d_copy_of(d1, NULL);
struct deque *d2 = d_copy_of(d1);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert_equals(size_t, d_count(d1), d_count(d2));
@@ -562,13 +576,20 @@ CMC_CREATE_UNIT(deque_test, true, {
i2 = (i2 + 1) % d2->capacity;
}
d_free(d1, NULL);
d_free(d2, NULL);
cmc_assert(d_push_front(d1, 10));
cmc_assert(d_push_front(d2, 10));
cmc_assert(d_push_back(d1, 11));
cmc_assert(d_push_back(d2, 11));
cmc_assert(d_equals(d1, d2));
d_free(d1);
d_free(d2);
});
CMC_CREATE_TEST(equals, {
struct deque *d1 = d_new(100);
struct deque *d2 = d_new(100);
struct deque *d1 = d_new(100, d_ftab_val);
struct deque *d2 = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d1);
cmc_assert_not_equals(ptr, NULL, d2);
@@ -587,14 +608,14 @@ CMC_CREATE_UNIT(deque_test, true, {
}
}
cmc_assert(d_equals(d1, d2, cmp));
cmc_assert(d_equals(d1, d2));
d_free(d1, NULL);
d_free(d2, NULL);
d_free(d1);
d_free(d2);
});
CMC_CREATE_TEST(equals[from copy], {
struct deque *d1 = d_new(100);
struct deque *d1 = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d1);
@@ -606,28 +627,28 @@ CMC_CREATE_UNIT(deque_test, true, {
cmc_assert(d_push_front(d1, i));
}
struct deque *d2 = d_copy_of(d1, NULL);
struct deque *d2 = d_copy_of(d1);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert(d_equals(d1, d2, cmp));
cmc_assert(d_equals(d1, d2));
d_free(d1, NULL);
d_free(d2, NULL);
d_free(d1);
d_free(d2);
});
CMC_CREATE_TEST(equals[count = 0], {
struct deque *d1 = d_new(100);
struct deque *d1 = d_new(100, d_ftab_val);
cmc_assert_not_equals(ptr, NULL, d1);
struct deque *d2 = d_copy_of(d1, NULL);
struct deque *d2 = d_copy_of(d1);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert(d_equals(d1, d2, cmp));
cmc_assert(d_equals(d1, d2));
d_free(d1, NULL);
d_free(d2, NULL);
d_free(d1);
d_free(d2);
});
});
+9 -5
View File
@@ -97,7 +97,8 @@ CMC_CREATE_UNIT(hashmap_test, true, {
for (size_t i = 0; i < 200; i++)
cmc_assert(hm_insert(map, i, i));
// Everything is hashed to 0 so key 0 should have dist 0, key 1 dist 1, etc
// Everything is hashed to 0 so key 0 should have dist 0, key 1 dist 1,
// etc
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, map->buffer[i].dist);
@@ -112,7 +113,8 @@ CMC_CREATE_UNIT(hashmap_test, true, {
size_t capacity = hm_capacity(map);
// Just to be sure, not part of the test
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1, hashcapminus1(0));
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1,
hashcapminus1(0));
cmc_assert_equals(size_t, capacity - 1, hashcapminus1(0));
cmc_assert(hm_insert(map, 0, 0));
@@ -304,7 +306,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, (size_t){0}, hm_get(map, 4321));
cmc_assert_equals(size_t, (size_t){ 0 }, hm_get(map, 4321));
hm_free(map, NULL);
});
@@ -389,7 +391,8 @@ CMC_CREATE_UNIT(hashmap_test, true, {
});
CMC_CREATE_TEST(full, {
struct hashmap *map = hm_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
struct hashmap *map =
hm_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
@@ -428,7 +431,8 @@ CMC_CREATE_UNIT(hashmap_test, true, {
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6), hm_capacity(map));
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6),
hm_capacity(map));
hm_free(map, NULL);
});
+10 -5
View File
@@ -83,7 +83,8 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert(hs_insert(set, capacity - 1));
cmc_assert(hs_insert(set, capacity));
cmc_assert_equals(size_t, capacity - 1, set->buffer[capacity - 1].value);
cmc_assert_equals(size_t, capacity - 1,
set->buffer[capacity - 1].value);
cmc_assert_equals(size_t, capacity, set->buffer[0].value);
hs_free(set, NULL);
@@ -97,7 +98,8 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 0; i < 200; i++)
cmc_assert(hs_insert(set, i));
// Everything is hashed to 0 so key 0 should have dist 0, key 1 dist 1, etc
// Everything is hashed to 0 so key 0 should have dist 0, key 1 dist 1,
// etc
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, set->buffer[i].dist);
@@ -112,7 +114,8 @@ CMC_CREATE_UNIT(hashset_test, true, {
size_t capacity = hs_capacity(set);
// Just to be sure, not part of the test
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1, hashcapminus1(0));
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1,
hashcapminus1(0));
cmc_assert_equals(size_t, capacity - 1, hashcapminus1(0));
cmc_assert(hs_insert(set, 0));
@@ -294,7 +297,8 @@ CMC_CREATE_UNIT(hashset_test, true, {
});
CMC_CREATE_TEST(full, {
struct hashset *set = hs_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
struct hashset *set =
hs_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
@@ -333,7 +337,8 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6), hs_capacity(set));
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6),
hs_capacity(set));
hs_free(set, NULL);
});
+1 -1
View File
@@ -157,7 +157,7 @@ CMC_CREATE_UNIT(heap_test, true, {
cmc_assert_not_equals(ptr, NULL, h);
cmc_assert_equals(size_t, (size_t){0}, h_peek(h));
cmc_assert_equals(size_t, (size_t){ 0 }, h_peek(h));
h_free(h, NULL);
});
+2 -1
View File
@@ -14,7 +14,8 @@ CMC_CREATE_UNIT(multiset_test, true, {
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_not_equals(ptr, NULL, set->buffer);
cmc_assert_equals(size_t, 0, ms_count(set));
cmc_assert_greater_equals(size_t, ((size_t)(943722 / 0.6)), ms_capacity(set));
cmc_assert_greater_equals(size_t, ((size_t)(943722 / 0.6)),
ms_capacity(set));
ms_free(set, NULL);
});
+9 -5
View File
@@ -74,7 +74,8 @@ CMC_CREATE_UNIT(queue_test, true, {
}
size_t sum = 0;
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
for (size_t i = q->front, j = 0; j < q->count;
i = (i + 1) % q->capacity, j++)
sum += q->buffer[i];
cmc_assert_equals(size_t, 1200, q_count(q));
@@ -107,7 +108,8 @@ CMC_CREATE_UNIT(queue_test, true, {
size_t sum = 0;
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
for (size_t i = q->front, j = 0; j < q->count;
i = (i + 1) % q->capacity, j++)
{
sum += q->buffer[i];
}
@@ -148,7 +150,8 @@ CMC_CREATE_UNIT(queue_test, true, {
size_t sum = 0;
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
for (size_t i = q->front, j = 0; j < q->count;
i = (i + 1) % q->capacity, j++)
{
sum += q->buffer[i];
}
@@ -165,7 +168,7 @@ CMC_CREATE_UNIT(queue_test, true, {
size_t r = q_peek(q);
cmc_assert_equals(size_t, (size_t){0}, r);
cmc_assert_equals(size_t, (size_t){ 0 }, r);
q_free(q, NULL);
});
@@ -319,7 +322,8 @@ CMC_CREATE_UNIT(queue_test, true, {
size_t sum = 0;
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
for (size_t i = q->front, j = 0; j < q->count;
i = (i + 1) % q->capacity, j++)
{
sum += q->buffer[i];
}
+18 -10
View File
@@ -186,7 +186,7 @@ CMC_CREATE_UNIT(stack_test, true, {
cmc_assert(s_pop(s));
cmc_assert_equals(size_t, (size_t){0}, s_top(s));
cmc_assert_equals(size_t, (size_t){ 0 }, s_top(s));
s_free(s, NULL);
});
@@ -342,14 +342,16 @@ CMC_CREATE_UNIT(stack_test, true, {
size_t total = 0;
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it); s_iter_next(&it))
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it);
s_iter_next(&it))
{
total += s_iter_value(&it);
}
cmc_assert_equals(size_t, 20100, total);
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it); s_iter_prev(&it))
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it);
s_iter_prev(&it))
{
total += s_iter_value(&it);
}
@@ -397,12 +399,14 @@ CMC_CREATE_UNIT(stack_test, true, {
size_t total = 0;
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it); s_iter_next(&it))
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it);
s_iter_next(&it))
{
total += s_iter_value(&it);
}
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it); s_iter_prev(&it))
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it);
s_iter_prev(&it))
{
total += s_iter_value(&it);
}
@@ -424,14 +428,16 @@ CMC_CREATE_UNIT(stack_test, true, {
size_t total = 0;
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it); s_iter_next(&it))
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it);
s_iter_next(&it))
{
total += s_iter_value(&it);
}
cmc_assert_equals(size_t, 1000, total);
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it); s_iter_prev(&it))
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it);
s_iter_prev(&it))
{
total += *s_iter_rvalue(&it);
}
@@ -526,7 +532,7 @@ CMC_CREATE_UNIT(stack_test, true, {
s_iter_init(&iter, s);
cmc_assert_equals(size_t, (size_t){0}, s_iter_value(&iter));
cmc_assert_equals(size_t, (size_t){ 0 }, s_iter_value(&iter));
s_free(s, NULL);
});
@@ -567,14 +573,16 @@ CMC_CREATE_UNIT(stack_test, true, {
cmc_assert_equals(size_t, s_count(s) - 1, s_iter_index(&it));
}
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it); s_iter_next(&it))
for (struct stack_iter it = s->it_start(s); !s_iter_end(&it);
s_iter_next(&it))
{
total += s_iter_index(&it);
}
cmc_assert_equals(size_t, 45, total);
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it); s_iter_prev(&it))
for (struct stack_iter it = s->it_end(s); !s_iter_start(&it);
s_iter_prev(&it))
{
total += s_iter_index(&it);
}
+5 -4
View File
@@ -2,9 +2,10 @@
#ifndef CMC_UNIT_TEST_UTL__
#define CMC_UNIT_TEST_UTL__
#include <stdlib.h>
#include <inttypes.h>
#include <cmc/hashmap.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
int cmp(size_t a, size_t b)
{
@@ -16,7 +17,7 @@ size_t copy(size_t a)
return a;
}
bool to_string(FILE *fptr, size_t a)
bool str(FILE *fptr, size_t a)
{
return fprintf(fptr, "%" PRIuMAX " ", a) > 0;
}
@@ -38,7 +39,7 @@ size_t hash(size_t a)
return a;
}
int priority(size_t a, size_t b)
int pri(size_t a, size_t b)
{
// Could contain different logic
return cmp(a, b);
+21 -19
View File
@@ -2,26 +2,28 @@
#include "../src/macro_collections.h"
CMC_COLLECTION_GENERATE( BIDIMAP, bm, bmap, int, int)
CMC_COLLECTION_GENERATE( DEQUE, d, deque, /* K */, int)
CMC_COLLECTION_GENERATE( HASHMAP, hm, hmap, int, int)
CMC_COLLECTION_GENERATE( HASHSET, hs, hset, /* K */, int)
CMC_COLLECTION_GENERATE( HEAP, h, heap, /* K */, int)
CMC_COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* K */, int)
CMC_COLLECTION_GENERATE( LINKEDLIST, ll, linked, /* K */, int)
CMC_COLLECTION_GENERATE( LIST, l, list, /* K */, int)
CMC_COLLECTION_GENERATE( MULTIMAP, mm, mmap, int, int)
CMC_COLLECTION_GENERATE( MULTISET, ms, mset, /* K */, int)
CMC_COLLECTION_GENERATE( QUEUE, q, queue, /* K */, int)
CMC_COLLECTION_GENERATE( SORTEDLIST, sl, slist, /* K */, int)
CMC_COLLECTION_GENERATE( STACK, s, stack, /* K */, int)
CMC_COLLECTION_GENERATE( TREESET, ts, tset, /* K */, int)
CMC_COLLECTION_GENERATE( TREEMAP, tm, tmap, int, int)
CMC_COLLECTION_GENERATE(BIDIMAP, bm, bmap, int, int)
CMC_COLLECTION_GENERATE(DEQUE, d, deque, /* K */, int)
CMC_COLLECTION_GENERATE(HASHMAP, hm, hmap, int, int)
CMC_COLLECTION_GENERATE(HASHSET, hs, hset, /* K */, int)
CMC_COLLECTION_GENERATE(HEAP, h, heap, /* K */, int)
CMC_COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* K */, int)
CMC_COLLECTION_GENERATE(LINKEDLIST, ll, linked, /* K */, int)
CMC_COLLECTION_GENERATE(LIST, l, list, /* K */, int)
CMC_COLLECTION_GENERATE(MULTIMAP, mm, mmap, int, int)
CMC_COLLECTION_GENERATE(MULTISET, ms, mset, /* K */, int)
CMC_COLLECTION_GENERATE(QUEUE, q, queue, /* K */, int)
CMC_COLLECTION_GENERATE(SORTEDLIST, sl, slist, /* K */, int)
CMC_COLLECTION_GENERATE(STACK, s, stack, /* K */, int)
CMC_COLLECTION_GENERATE(TREESET, ts, tset, /* K */, int)
CMC_COLLECTION_GENERATE(TREEMAP, tm, tmap, int, int)
int main(void)
{
struct bmap *bm = bm_new_custom(100, 0.7, NULL, NULL, NULL, NULL);
struct deque *d = d_new_custom(100, NULL, NULL);
struct bmap *bm = bm_new_custom(100, 0.7, &(struct bmap_ftab_key){ 0 },
&(struct bmap_ftab_val){ 0 }, NULL, NULL);
struct deque *d =
d_new_custom(100, &(struct deque_ftab_val){ 0 }, NULL, NULL);
struct hmap *hm = hm_new_custom(100, 0.6, NULL, NULL, NULL, NULL);
struct hset *hs = hs_new_custom(100, 0.6, NULL, NULL, NULL, NULL);
struct heap *h = h_new_custom(100, cmc_max_heap, NULL, NULL, NULL);
@@ -52,8 +54,8 @@ int main(void)
printf("%s\n", tm_to_string(tm).s);
printf("%s\n", ts_to_string(ts).s);
bm_free(bm, NULL);
d_free(d, NULL);
bm_free(bm);
d_free(d);
hm_free(hm, NULL);
hs_free(hs, NULL);
h_free(h, NULL);