Fast forward codecov

This commit is contained in:
Leonardo committed 2019-10-23 01:14:10 -03:00
1 parent 616327f054
commit 122d012ffd
32 files changed
+6944 -2101

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/bidimap.c"
CMC_CREATE_UNIT(bidimap_test, false, {
CMC_CREATE_TEST(new, {
bidimap *map = bm_new(100, 0.6, cmp, hash, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
bm_free(map, NULL);
});
CMC_CREATE_TEST(clear[count], {
bidimap *map = bm_new(100, 0.6, cmp, hash, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 50; i++)
cmc_assert(bm_insert(map, i, i));
cmc_assert_equals(size_t, 50, bm_count(map));
bm_clear(map, NULL);
cmc_assert_equals(size_t, 0, bm_count(map));
bm_free(map, NULL);
});
});
+579 -9
View File
@@ -1,5 +1,8 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/deque.c"
CMC_CREATE_UNIT(deque_test, false, {
@@ -11,16 +14,16 @@ CMC_CREATE_UNIT(deque_test, false, {
cmc_assert_equals(size_t, 1000000, d->capacity);
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d);
d_free(d, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[capacity = 0], {
deque *d = d_new(0);
cmc_assert_equals(ptr, NULL, d);
});
CMC_CREATE_TEST(new[edge_case:capacity = UINT64_MAX], {
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
deque *d = d_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, d);
@@ -36,15 +39,15 @@ CMC_CREATE_UNIT(deque_test, false, {
cmc_assert_equals(size_t, 50, d_count(d));
d_clear(d);
d_clear(d, NULL);
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert_equals(size_t, 100, d_capacity(d));
d_free(d);
d_free(d, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
deque *d = d_new(1);
cmc_assert_not_equals(ptr, NULL, d);
@@ -55,7 +58,574 @@ CMC_CREATE_UNIT(deque_test, false, {
cmc_assert_equals(size_t, 50, d_count(d));
cmc_assert_lesser_equals(size_t, d_capacity(d), d_count(d));
d_free(d);
d_free(d, NULL);
});
CMC_CREATE_TEST(buffer_growth[item preservation], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 1200; i++)
{
if (i % 2 == 0)
d_push_front(d, i);
else
d_push_back(d, i);
}
size_t sum = 0;
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);
});
CMC_CREATE_TEST(push_front[count capacity], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 0; i < 150; i++)
cmc_assert(d_push_front(d, i));
cmc_assert_equals(size_t, 150, d_count(d));
cmc_assert_greater(size_t, 100, d_capacity(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(push_front[item preservation], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 100; i++)
cmc_assert(d_push_front(d, i));
size_t sum = 0;
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);
});
CMC_CREATE_TEST(push_back[count capacity], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 0; i < 150; i++)
cmc_assert(d_push_back(d, i));
cmc_assert_equals(size_t, 150, d_count(d));
cmc_assert_greater(size_t, 100, d_capacity(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(push_back[item preservation], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 100; i++)
cmc_assert(d_push_back(d, i));
size_t sum = 0;
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);
});
CMC_CREATE_TEST(pop_front[count capacity], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(d_push_front(d, 10));
cmc_assert(d_pop_front(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_pop_front(d));
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(pop_front[item preservation], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 200; i++)
cmc_assert(d_push_front(d, i));
for (size_t i = 0; i < 100; i++)
cmc_assert(d_pop_front(d));
size_t sum = 0;
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);
});
CMC_CREATE_TEST(pop_back[count capacity], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(d_push_front(d, 10));
cmc_assert(d_pop_back(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_pop_back(d));
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(pop_back[item preservation], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 200; i++)
cmc_assert(d_push_back(d, i));
for (size_t i = 0; i < 100; i++)
cmc_assert(d_pop_back(d));
size_t sum = 0;
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);
});
CMC_CREATE_TEST(Mixed IO, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(d_push_front(d, 10));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_pop_back(d));
cmc_assert(d_pop_back(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_pop_back(d));
cmc_assert(d_pop_back(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_pop_front(d));
cmc_assert(d_pop_front(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_pop_front(d));
cmc_assert(d_pop_front(d));
cmc_assert_equals(size_t, 0, d_count(d));
// ----------
cmc_assert(d_push_back(d, 10));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_pop_back(d));
cmc_assert(d_pop_front(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_pop_front(d));
cmc_assert(d_pop_back(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_pop_back(d));
cmc_assert(d_pop_front(d));
cmc_assert_equals(size_t, 0, d_count(d));
cmc_assert(d_push_front(d, 10));
cmc_assert(d_push_back(d, 10));
cmc_assert(d_pop_front(d));
cmc_assert(d_pop_back(d));
cmc_assert_equals(size_t, 0, d_count(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(front[count = 0], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
size_t r = d_front(d);
cmc_assert_equals(size_t, (size_t){0}, r);
d_free(d, NULL);
});
CMC_CREATE_TEST(front[sum], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
size_t sum = 0;
for (size_t i = 0; i <= 100; i++)
{
if (i % 2 == 0)
cmc_assert(d_push_back(d, i));
else
cmc_assert(d_push_front(d, i));
}
while (!d_empty(d))
{
size_t r = d_front(d);
sum += r;
cmc_assert(d_pop_front(d));
}
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
});
CMC_CREATE_TEST(back[count = 0], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
size_t r = d_back(d);
cmc_assert_equals(size_t, (size_t){0}, r);
d_free(d, NULL);
});
CMC_CREATE_TEST(back[sum], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
size_t sum = 0;
for (size_t i = 0; i <= 100; i++)
{
if (i % 2 == 0)
cmc_assert(d_push_back(d, i));
else
cmc_assert(d_push_front(d, i));
}
while (!d_empty(d))
{
size_t r = d_back(d);
sum += r;
cmc_assert(d_pop_back(d));
}
cmc_assert_equals(size_t, 5050, sum);
d_free(d, NULL);
});
CMC_CREATE_TEST(contains, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 20; i++)
cmc_assert(d_push_back(d, i));
for (size_t i = 1; i <= 20; i++)
cmc_assert(d_contains(d, i, cmp));
d_clear(d, NULL);
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));
d_free(d, NULL);
});
CMC_CREATE_TEST(contains[count = 0], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(!d_contains(d, 10, cmp));
d_free(d, NULL);
});
CMC_CREATE_TEST(contains[count = 1], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(!d_contains(d, 10, cmp));
cmc_assert(d_push_back(d, 100));
cmc_assert(d_contains(d, 100, cmp));
cmc_assert(!d_contains(d, 101, cmp));
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));
d_free(d, NULL);
});
CMC_CREATE_TEST(empty, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(d_empty(d));
cmc_assert(d_push_front(d, 1));
cmc_assert(!d_empty(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(full, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert(!d_full(d));
for (size_t i = 0; i != d_capacity(d); i++)
cmc_assert(d_push_front(d, i));
cmc_assert(d_full(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(count, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert_equals(size_t, 0, d_count(d));
for (size_t i = 0; i < 100; i++)
cmc_assert(d_push_back(d, i));
cmc_assert_equals(size_t, 100, d_count(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(capacity, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
cmc_assert_equals(size_t, 100, d_capacity(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(resize, {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 0; i < 150; i++)
{
if (i % 2 == 0)
cmc_assert(d_push_back(d, i));
else
cmc_assert(d_push_front(d, i));
}
cmc_assert_equals(size_t, 150, d_count(d));
cmc_assert(d_resize(d, d_count(d)));
cmc_assert_equals(size_t, 150, d_capacity(d));
d_free(d, NULL);
});
CMC_CREATE_TEST(resize[item preservation], {
deque *d = d_new(100);
cmc_assert_not_equals(ptr, NULL, d);
for (size_t i = 1; i <= 150; i++)
{
if (i % 2 != 0)
cmc_assert(d_push_back(d, i));
else
cmc_assert(d_push_front(d, i));
}
cmc_assert(d_resize(d, d_count(d)));
size_t sum = 0;
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);
});
CMC_CREATE_TEST(copy_of, {
deque *d1 = d_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
for (size_t i = 1; i <= 150; i++)
{
if (i % 2 != 0)
cmc_assert(d_push_back(d1, i));
else
cmc_assert(d_push_front(d1, i));
}
deque *d2 = d_copy_of(d1, NULL);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert_equals(size_t, d_count(d1), d_count(d2));
for (size_t i1 = d1->front, i2 = d2->front, j = 0; j < d1->count; j++)
{
cmc_assert_equals(size_t, d1->buffer[i1], d2->buffer[i2]);
i1 = (i1 + 1) % d1->capacity;
i2 = (i2 + 1) % d2->capacity;
}
d_free(d1, NULL);
d_free(d2, NULL);
});
CMC_CREATE_TEST(equals, {
deque *d1 = d_new(100);
deque *d2 = d_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
cmc_assert_not_equals(ptr, NULL, d2);
for (size_t i = 1; i <= 150; i++)
{
if (i % 2 != 0)
{
cmc_assert(d_push_back(d1, i));
cmc_assert(d_push_back(d2, i));
}
else
{
cmc_assert(d_push_front(d1, i));
cmc_assert(d_push_front(d2, i));
}
}
cmc_assert(d_equals(d1, d2, cmp));
d_free(d1, NULL);
d_free(d2, NULL);
});
CMC_CREATE_TEST(equals[from copy], {
deque *d1 = d_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
for (size_t i = 1; i <= 150; i++)
{
if (i % 2 != 0)
cmc_assert(d_push_back(d1, i));
else
cmc_assert(d_push_front(d1, i));
}
deque *d2 = d_copy_of(d1, NULL);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert(d_equals(d1, d2, cmp));
d_free(d1, NULL);
d_free(d2, NULL);
});
CMC_CREATE_TEST(equals[count = 0], {
deque *d1 = d_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
deque *d2 = d_copy_of(d1, NULL);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert(d_equals(d1, d2, cmp));
d_free(d1, NULL);
d_free(d2, NULL);
});
});
+415 -10
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/hashmap.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/hashmap.c"
CMC_CREATE_UNIT(hashmap_test, false, {
CMC_CREATE_TEST(new, {
@@ -13,17 +14,17 @@ CMC_CREATE_UNIT(hashmap_test, false, {
cmc_assert_equals(size_t, 0, hm_count(map));
cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(map));
hm_free(map);
hm_free(map, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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], {
hashmap *map = hm_new(UINT64_MAX, 0.6, cmp, hash);
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
hashmap *map = hm_new(UINT64_MAX, 0.99, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
});
@@ -38,11 +39,415 @@ CMC_CREATE_UNIT(hashmap_test, false, {
cmc_assert_equals(size_t, 50, hm_count(map));
hm_clear(map);
hm_clear(map, NULL);
cmc_assert_equals(size_t, 0, hm_count(map));
hm_free(map);
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_insert(map, 1, 1));
cmc_assert_equals(size_t, 1, hm_count(map));
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert[smallest capacity], {
hashmap *map = hm_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hm_capacity(map));
cmc_assert(hm_insert(map, 1, 1));
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert[element position], {
// Using the numhash the key is the hash itself
hashmap *map = hm_new(1, 0.99, cmp, numhash);
cmc_assert_not_equals(ptr, NULL, map);
size_t capacity = hm_capacity(map);
cmc_assert_greater(size_t, 0, capacity);
cmc_assert(hm_insert(map, capacity - 1, capacity - 1));
cmc_assert(hm_insert(map, capacity, capacity));
cmc_assert_equals(size_t, capacity - 1, map->buffer[capacity - 1].key);
cmc_assert_equals(size_t, capacity, map->buffer[0].key);
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert[distance], {
hashmap *map = hm_new(500, 0.6, cmp, hash0);
cmc_assert_not_equals(ptr, NULL, map);
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
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, map->buffer[i].dist);
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert[distance wrap], {
hashmap *map = hm_new(1, 0.99, cmp, hashcapminus1);
cmc_assert_not_equals(ptr, NULL, map);
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, capacity - 1, hashcapminus1(0));
cmc_assert(hm_insert(map, 0, 0));
cmc_assert(hm_insert(map, 1, 1));
cmc_assert_equals(size_t, 0, map->buffer[capacity - 1].dist);
cmc_assert_equals(size_t, 1, map->buffer[0].dist);
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert[distances], {
hashmap *map = hm_new(1, 0.99, cmp, hashcapminus4);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hm_capacity(map));
for (size_t i = 0; i < 6; i++)
cmc_assert(hm_insert(map, i, i));
for (size_t i = 0; i < 6; i++)
cmc_assert_equals(size_t, i, hm_impl_get_entry(map, i)->dist);
hm_free(map, NULL);
});
CMC_CREATE_TEST(insert[buffer growth and item preservation], {
hashmap *map = hm_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hm_capacity(map));
size_t p = 0;
for (size_t i = 0; i < 100000; i++)
{
if (hm_full(map))
p++;
cmc_assert(hm_insert(map, i, i));
}
cmc_assert_equals(size_t, cmc_hashtable_primes[p], hm_capacity(map));
for (size_t i = 0; i < 100000; i++)
cmc_assert(hm_contains(map, i));
hm_free(map, NULL);
});
CMC_CREATE_TEST(update, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_insert(map, 1, 1));
size_t old;
cmc_assert(hm_update(map, 1, 2, &old));
cmc_assert_equals(size_t, 1, old);
hm_free(map, NULL);
});
CMC_CREATE_TEST(update[key not found], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 100; i++)
cmc_assert(hm_insert(map, i, i));
cmc_assert(!hm_update(map, 120, 120, NULL));
hm_free(map, NULL);
});
CMC_CREATE_TEST(remove, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 100; i++)
cmc_assert(hm_insert(map, i, i));
for (size_t i = 0; i < 100; i++)
cmc_assert(hm_remove(map, i, NULL));
hm_free(map, NULL);
});
CMC_CREATE_TEST(remove[count = 0], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 100; i < 200; i++)
cmc_assert(!hm_remove(map, i, NULL));
hm_free(map, NULL);
});
CMC_CREATE_TEST(remove[key not found], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 100; i++)
cmc_assert(hm_insert(map, i, i));
for (size_t i = 100; i < 200; i++)
cmc_assert(!hm_remove(map, i, NULL));
hm_free(map, NULL);
});
CMC_CREATE_TEST(max, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 1; i <= 100; i++)
cmc_assert(hm_insert(map, i, i));
size_t key;
size_t val;
cmc_assert(hm_max(map, &key, &val));
cmc_assert_equals(size_t, 100, key);
cmc_assert_equals(size_t, 100, val);
hm_free(map, NULL);
});
CMC_CREATE_TEST(max[count = 0], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(!hm_min(map, NULL, NULL));
hm_free(map, NULL);
});
CMC_CREATE_TEST(min, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 1; i <= 100; i++)
cmc_assert(hm_insert(map, i, i));
size_t key;
size_t val;
cmc_assert(hm_min(map, &key, &val));
cmc_assert_equals(size_t, 1, key);
cmc_assert_equals(size_t, 1, val);
hm_free(map, NULL);
});
CMC_CREATE_TEST(min[count = 0], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(!hm_min(map, NULL, NULL));
hm_free(map, NULL);
});
CMC_CREATE_TEST(get, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_insert(map, 4321, 1234));
cmc_assert_equals(size_t, 1234, hm_get(map, 4321));
hm_free(map, NULL);
});
CMC_CREATE_TEST(get[count = 0], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, (size_t){0}, hm_get(map, 4321));
hm_free(map, NULL);
});
CMC_CREATE_TEST(get_ref, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_insert(map, 4321, 1234));
size_t *result = hm_get_ref(map, 4321);
cmc_assert_not_equals(ptr, NULL, result);
cmc_assert_equals(size_t, 1234, *result);
hm_free(map, NULL);
});
CMC_CREATE_TEST(get_ref[count = 0], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(ptr, NULL, hm_get_ref(map, 4321));
hm_free(map, NULL);
});
CMC_CREATE_TEST(contains, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_insert(map, 987654321, 1));
cmc_assert(hm_contains(map, 987654321));
hm_free(map, NULL);
});
CMC_CREATE_TEST(contains[count = 0], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(!hm_contains(map, 987654321));
hm_free(map, NULL);
});
CMC_CREATE_TEST(contains[sum], {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 101; i <= 200; i++)
cmc_assert(hm_insert(map, i, i));
size_t sum = 0;
for (size_t i = 1; i <= 300; i++)
if (hm_contains(map, i))
sum += i;
cmc_assert_equals(size_t, 15050, sum);
hm_free(map, NULL);
});
CMC_CREATE_TEST(empty, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert(hm_empty(map));
cmc_assert(hm_insert(map, 1, 1));
cmc_assert(!hm_empty(map));
hm_free(map, NULL);
});
CMC_CREATE_TEST(full, {
hashmap *map = hm_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hm_capacity(map));
for (size_t i = 0; i < hm_capacity(map); i++)
cmc_assert(hm_insert(map, i, i));
cmc_assert(hm_full(map));
cmc_assert(hm_insert(map, 10000, 10000));
cmc_assert_equals(size_t, cmc_hashtable_primes[1], hm_capacity(map));
cmc_assert(!hm_full(map));
hm_free(map, NULL);
});
CMC_CREATE_TEST(count, {
hashmap *map = hm_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 1; i < 100; i++)
{
cmc_assert(hm_insert(map, i, i));
cmc_assert_equals(size_t, i, hm_count(map));
}
hm_free(map, NULL);
});
CMC_CREATE_TEST(capacity, {
hashmap *map = hm_new(2500, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6), hm_capacity(map));
hm_free(map, NULL);
});
CMC_CREATE_TEST(capacity[small], {
hashmap *map = hm_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hm_capacity(map));
hm_free(map, NULL);
});
CMC_CREATE_TEST(load, {
hashmap *map = hm_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
cmc_assert_in_range(double, 0.99 - 0.0001, 0.99 + 0.0001, hm_load(map));
hm_free(map, NULL);
});
});
+320 -10
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/hashset.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/hashset.c"
CMC_CREATE_UNIT(hashset_test, false, {
CMC_CREATE_TEST(new, {
@@ -13,17 +14,17 @@ CMC_CREATE_UNIT(hashset_test, false, {
cmc_assert_equals(size_t, 0, hs_count(set));
cmc_assert_greater_equals(size_t, (943722 / 0.6), hs_capacity(set));
hs_free(set);
hs_free(set, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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], {
hashset *set = hs_new(UINT64_MAX, 0.6, cmp, hash);
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
hashset *set = hs_new(UINT64_MAX, 0.99, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
});
@@ -38,11 +39,320 @@ CMC_CREATE_UNIT(hashset_test, false, {
cmc_assert_equals(size_t, 50, hs_count(set));
hs_clear(set);
hs_clear(set, NULL);
cmc_assert_equals(size_t, 0, hs_count(set));
hs_free(set);
hs_free(set, NULL);
});
CMC_CREATE_TEST(insert, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(hs_insert(set, 1));
cmc_assert_equals(size_t, 1, hs_count(set));
hs_free(set, NULL);
});
CMC_CREATE_TEST(insert[smallest capacity], {
hashset *set = hs_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
cmc_assert(hs_insert(set, 1));
hs_free(set, NULL);
});
CMC_CREATE_TEST(insert[element position], {
// Using the numhash the key is the hash itself
hashset *set = hs_new(1, 0.99, cmp, numhash);
cmc_assert_not_equals(ptr, NULL, set);
size_t capacity = hs_capacity(set);
cmc_assert_greater(size_t, 0, capacity);
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, set->buffer[0].value);
hs_free(set, NULL);
});
CMC_CREATE_TEST(insert[distance], {
hashset *set = hs_new(500, 0.6, cmp, hash0);
cmc_assert_not_equals(ptr, NULL, set);
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
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, set->buffer[i].dist);
hs_free(set, NULL);
});
CMC_CREATE_TEST(insert[distance wrap], {
hashset *set = hs_new(1, 0.99, cmp, hashcapminus1);
cmc_assert_not_equals(ptr, NULL, set);
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, capacity - 1, hashcapminus1(0));
cmc_assert(hs_insert(set, 0));
cmc_assert(hs_insert(set, 1));
cmc_assert_equals(size_t, 0, set->buffer[capacity - 1].dist);
cmc_assert_equals(size_t, 1, set->buffer[0].dist);
hs_free(set, NULL);
});
CMC_CREATE_TEST(insert[buffer growth and item preservation], {
hashset *set = hs_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
size_t p = 0;
for (size_t i = 0; i < 100000; i++)
{
if (hs_full(set))
p++;
cmc_assert(hs_insert(set, i));
}
cmc_assert_equals(size_t, cmc_hashtable_primes[p], hs_capacity(set));
for (size_t i = 0; i < 100000; i++)
cmc_assert(hs_contains(set, i));
hs_free(set, NULL);
});
CMC_CREATE_TEST(remove, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 0; i < 100; i++)
cmc_assert(hs_insert(set, i));
for (size_t i = 0; i < 100; i++)
cmc_assert(hs_remove(set, i));
hs_free(set, NULL);
});
CMC_CREATE_TEST(remove[count = 0], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 100; i < 200; i++)
cmc_assert(!hs_remove(set, i));
hs_free(set, NULL);
});
CMC_CREATE_TEST(remove[key not found], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 0; i < 100; i++)
cmc_assert(hs_insert(set, i));
for (size_t i = 100; i < 200; i++)
cmc_assert(!hs_remove(set, i));
hs_free(set, NULL);
});
CMC_CREATE_TEST(max, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 1; i <= 100; i++)
cmc_assert(hs_insert(set, i));
size_t val;
cmc_assert(hs_max(set, &val));
cmc_assert_equals(size_t, 100, val);
hs_free(set, NULL);
});
CMC_CREATE_TEST(max[count = 0], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(!hs_min(set, NULL));
hs_free(set, NULL);
});
CMC_CREATE_TEST(min, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 1; i <= 100; i++)
cmc_assert(hs_insert(set, i));
size_t val;
cmc_assert(hs_min(set, &val));
cmc_assert_equals(size_t, 1, val);
hs_free(set, NULL);
});
CMC_CREATE_TEST(min[count = 0], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(!hs_min(set, NULL));
hs_free(set, NULL);
});
CMC_CREATE_TEST(contains, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(hs_insert(set, 987654321));
cmc_assert(hs_contains(set, 987654321));
hs_free(set, NULL);
});
CMC_CREATE_TEST(contains[count = 0], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(!hs_contains(set, 987654321));
hs_free(set, NULL);
});
CMC_CREATE_TEST(contains[sum], {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 101; i <= 200; i++)
cmc_assert(hs_insert(set, i));
size_t sum = 0;
for (size_t i = 1; i <= 300; i++)
if (hs_contains(set, i))
sum += i;
cmc_assert_equals(size_t, 15050, sum);
hs_free(set, NULL);
});
CMC_CREATE_TEST(empty, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(hs_empty(set));
cmc_assert(hs_insert(set, 1));
cmc_assert(!hs_empty(set));
hs_free(set, NULL);
});
CMC_CREATE_TEST(full, {
hashset *set = hs_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
for (size_t i = 0; i < hs_capacity(set); i++)
cmc_assert(hs_insert(set, i));
cmc_assert(hs_full(set));
cmc_assert(hs_insert(set, 10000));
cmc_assert_equals(size_t, cmc_hashtable_primes[1], hs_capacity(set));
cmc_assert(!hs_full(set));
hs_free(set, NULL);
});
CMC_CREATE_TEST(count, {
hashset *set = hs_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 1; i < 100; i++)
{
cmc_assert(hs_insert(set, i));
cmc_assert_equals(size_t, i, hs_count(set));
}
hs_free(set, NULL);
});
CMC_CREATE_TEST(capacity, {
hashset *set = hs_new(2500, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6), hs_capacity(set));
hs_free(set, NULL);
});
CMC_CREATE_TEST(capacity[small], {
hashset *set = hs_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
hs_free(set, NULL);
});
CMC_CREATE_TEST(load, {
hashset *set = hs_new(1, 0.99, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_in_range(double, 0.99 - 0.0001, 0.99 + 0.0001, hs_load(set));
hs_free(set, NULL);
});
});
+112 -12
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/heap.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/heap.c"
CMC_CREATE_UNIT(heap_test, false, {
CMC_CREATE_TEST(new, {
@@ -13,16 +14,16 @@ CMC_CREATE_UNIT(heap_test, false, {
cmc_assert_equals(size_t, 1000000, h_capacity(h));
cmc_assert_equals(size_t, 0, h_count(h));
h_free(h);
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);
@@ -38,25 +39,124 @@ CMC_CREATE_UNIT(heap_test, false, {
cmc_assert_equals(size_t, 50, h_count(h));
h_clear(h);
h_clear(h, NULL);
cmc_assert_equals(size_t, 0, h_count(h));
cmc_assert_equals(size_t, 100, h_capacity(h));
h_free(h);
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);
for (size_t i = 0; i < 50; i++)
h_insert(h, i);
cmc_assert(h_insert(h, i));
cmc_assert_equals(size_t, 50, h_count(h));
h_free(h);
h_free(h, NULL);
});
CMC_CREATE_TEST(insert, {
heap *h = h_new(100, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
cmc_assert(h_insert(h, 10));
h_free(h, NULL);
});
CMC_CREATE_TEST(insert[item preservation], {
heap *h = h_new(50, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
for (size_t i = 0; i <= 100; i++)
cmc_assert(h_insert(h, i));
size_t sum = 0;
for (size_t i = 0; i < h_count(h); i++)
sum += h->buffer[i];
cmc_assert_equals(size_t, 5050, sum);
h_free(h, NULL);
});
CMC_CREATE_TEST(remove, {
heap *h = h_new(50, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
for (size_t i = 0; i <= 100; i++)
cmc_assert(h_insert(h, i));
size_t r;
cmc_assert(h_remove(h, &r));
cmc_assert_equals(size_t, 100, r);
h_free(h, NULL);
});
CMC_CREATE_TEST(remove[count = 0], {
heap *h = h_new(100, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
size_t _;
cmc_assert(!h_remove(h, &_));
h_free(h, NULL);
});
CMC_CREATE_TEST(remove[sorted], {
heap *h = h_new(100, cmc_min_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
for (size_t i = 1; i <= 100; i++)
cmc_assert(h_insert(h, i));
size_t r;
size_t i = 0;
size_t arr[100];
while (!h_empty(h))
{
cmc_assert(h_remove(h, &r));
arr[i++] = r;
}
cmc_assert_array_sorted_any(size_t, arr, cmp, 0, 99);
h_free(h, NULL);
});
CMC_CREATE_TEST(peek, {
heap *h = h_new(100, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
for (size_t i = 1; i <= 100; i++)
cmc_assert(h_insert(h, i));
cmc_assert_equals(size_t, 100, h_peek(h));
h_free(h, NULL);
});
CMC_CREATE_TEST(peek[count = 0], {
heap *h = h_new(100, cmc_max_heap, cmp);
cmc_assert_not_equals(ptr, NULL, h);
cmc_assert_equals(size_t, (size_t){0}, h_peek(h));
h_free(h, NULL);
});
});
+132
View File
@@ -0,0 +1,132 @@
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/intervalheap.c"
CMC_CREATE_UNIT(intervalheap_test, false, {
CMC_CREATE_TEST(new, {
intervalheap *ih = ih_new(1000000, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert_not_equals(ptr, NULL, ih->buffer);
cmc_assert_equals(size_t, 500000, ih_capacity(ih));
cmc_assert_equals(size_t, 0, ih_count(ih));
ih_free(ih, NULL);
});
CMC_CREATE_TEST(new[capacity = 0], {
intervalheap *ih = ih_new(0, cmp);
cmc_assert_equals(ptr, NULL, ih);
if (ih)
ih_free(ih, NULL);
});
CMC_CREATE_TEST(new[capacity], {
intervalheap *ih = ih_new(1, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert_equals(size_t, 1, ih_capacity(ih));
ih_free(ih, NULL);
ih = ih_new(2, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert_equals(size_t, 1, ih_capacity(ih));
ih_free(ih, NULL);
ih = ih_new(3, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert_equals(size_t, 2, ih_capacity(ih));
ih_free(ih, NULL);
ih = ih_new(4, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert_equals(size_t, 2, ih_capacity(ih));
ih_free(ih, NULL);
});
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
intervalheap *ih = ih_new(UINT64_MAX, cmp);
cmc_assert_equals(ptr, NULL, ih);
if (ih)
ih_free(ih, NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
intervalheap *ih = ih_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
for (size_t i = 0; i < 50; i++)
cmc_assert(ih_insert(ih, i));
cmc_assert_equals(size_t, 50, ih_count(ih));
ih_clear(ih, NULL);
cmc_assert_equals(size_t, 0, ih_count(ih));
cmc_assert_equals(size_t, 50, ih_capacity(ih));
ih_free(ih, NULL);
});
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
intervalheap *ih = ih_new(1, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
for (size_t i = 0; i < 50; i++)
cmc_assert(ih_insert(ih, i));
cmc_assert_equals(size_t, 50, ih_count(ih));
cmc_assert_greater(size_t, 50, ih_capacity(ih) * 2);
ih_free(ih, NULL);
});
CMC_CREATE_TEST(insert[count], {
intervalheap *ih = ih_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert(ih_insert(ih, 1));
cmc_assert(ih_insert(ih, 0));
cmc_assert_equals(size_t, 2, ih_count(ih));
ih_free(ih, NULL);
});
CMC_CREATE_TEST(insert[max min], {
intervalheap *ih = ih_new(1, cmp);
cmc_assert_not_equals(ptr, NULL, ih);
cmc_assert(ih_insert(ih, 1));
cmc_assert(ih_insert(ih, 0));
size_t min;
size_t max;
cmc_assert(ih_min(ih, &min));
cmc_assert(ih_max(ih, &max));
cmc_assert_equals(size_t, 0, min);
cmc_assert_equals(size_t, 1, max);
ih_free(ih, NULL);
});
});
+14 -12
View File
@@ -1,5 +1,8 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/linkedlist.c"
CMC_CREATE_UNIT(linkedlist_test, false, {
@@ -11,7 +14,7 @@ CMC_CREATE_UNIT(linkedlist_test, false, {
cmc_assert_equals(ptr, NULL, ll->head);
cmc_assert_equals(ptr, NULL, ll->tail);
ll_free(ll);
ll_free(ll, NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
@@ -24,23 +27,23 @@ CMC_CREATE_UNIT(linkedlist_test, false, {
cmc_assert_equals(size_t, 50, ll_count(ll));
ll_clear(ll);
ll_clear(ll, NULL);
cmc_assert_equals(size_t, 0, ll_count(ll));
ll_free(ll);
ll_free(ll, NULL);
});
CMC_CREATE_TEST(clear[edge_case:count = 0], {
CMC_CREATE_TEST(clear[count = 0], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
ll_clear(ll);
ll_clear(ll, NULL);
cmc_assert_equals(size_t, 0, ll_count(ll));
ll_free(ll);
ll_free(ll, NULL);
});
CMC_CREATE_TEST(push_front[count], {
@@ -54,10 +57,10 @@ CMC_CREATE_UNIT(linkedlist_test, false, {
cmc_assert_not_equals(ptr, NULL, ll->tail);
cmc_assert_equals(size_t, 1, ll_count(ll));
ll_free(ll);
ll_free(ll, NULL);
});
CMC_CREATE_TEST(push_front[item_preservation], {
CMC_CREATE_TEST(push_front[item preservation], {
linkedlist *ll = ll_new();
cmc_assert_not_equals(ptr, NULL, ll);
@@ -68,7 +71,6 @@ CMC_CREATE_UNIT(linkedlist_test, false, {
for (size_t i = 0; i < ll_count(ll); i++)
cmc_assert_equals(size_t, ll_get(ll, i), ll_count(ll) - i - 1);
ll_free(ll);
ll_free(ll, NULL);
});
});
+54 -51
View File
@@ -1,5 +1,8 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/list.c"
CMC_CREATE_UNIT(list_test, false, {
@@ -11,22 +14,22 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_equals(size_t, 1000000, l_capacity(l));
cmc_assert_equals(size_t, 0, l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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[capacity = UINT64_MAX], {
list *l = l_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, l);
});
CMC_CREATE_TEST(new_from[count item_preservation], {
CMC_CREATE_TEST(new_from[count and item preservation], {
size_t v[5];
for (size_t i = 0; i < 5; i++)
@@ -41,10 +44,10 @@ CMC_CREATE_UNIT(list_test, false, {
for (size_t i = 0; i < 5; i++)
cmc_assert_equals(size_t, i, l_get(l, i));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(new_from[edge_case:size = 1], {
CMC_CREATE_TEST(new_from[size = 1], {
size_t a = 10;
size_t *values = &a;
@@ -53,7 +56,7 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_not_equals(ptr, NULL, l);
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(clear[count capacity], {
@@ -66,15 +69,15 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_equals(size_t, 50, l_count(l));
l_clear(l);
l_clear(l, NULL);
cmc_assert_equals(size_t, 0, l_count(l));
cmc_assert_equals(size_t, 100, l_capacity(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
list *l = l_new(1);
cmc_assert_not_equals(ptr, NULL, l);
@@ -87,7 +90,7 @@ CMC_CREATE_UNIT(list_test, false, {
for (size_t i = 0; i < 100; i++)
cmc_assert_equals(size_t, i, l_get(l, i));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push_front[count], {
@@ -100,7 +103,7 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_equals(size_t, 250, l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push_front[capacity], {
@@ -113,10 +116,10 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_lesser_equals(size_t, l_capacity(l), l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push_front[item_preservation], {
CMC_CREATE_TEST(push_front[item preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -127,10 +130,10 @@ CMC_CREATE_UNIT(list_test, false, {
for (size_t i = 0; i < l_count(l); i++)
cmc_assert_equals(size_t, l_get(l, i), l_count(l) - i - 1);
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push[count], {
CMC_CREATE_TEST(push_at[count], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -139,14 +142,14 @@ CMC_CREATE_UNIT(list_test, false, {
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(l_push_at(l, i, l_count(l) - 1));
cmc_assert_equals(size_t, 250, l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push[capacity], {
CMC_CREATE_TEST(push_at[capacity], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -155,14 +158,14 @@ CMC_CREATE_UNIT(list_test, false, {
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(l_push_at(l, i, l_count(l) - 1));
cmc_assert_lesser_equals(size_t, l_capacity(l), l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push[item_preservation], {
CMC_CREATE_TEST(push_at[item preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -171,12 +174,12 @@ CMC_CREATE_UNIT(list_test, false, {
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(l_push_at(l, i, l_count(l) - 1));
for (size_t i = 0; i < l_count(l); i++)
cmc_assert_equals(size_t, l_get(l, i), i);
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push_back[count], {
@@ -189,7 +192,7 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_equals(size_t, 250, l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push_back[capacity], {
@@ -202,10 +205,10 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_lesser_equals(size_t, l_capacity(l), l_count(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(push_back[item_preservation], {
CMC_CREATE_TEST(push_back[item preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -216,7 +219,7 @@ CMC_CREATE_UNIT(list_test, false, {
for (size_t i = 0; i < l_count(l); i++)
cmc_assert_equals(size_t, l_get(l, i), i);
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[count], {
@@ -229,10 +232,10 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert(l_pop_front(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[item_preservation], {
CMC_CREATE_TEST(pop_front[item preservation], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
@@ -245,26 +248,26 @@ CMC_CREATE_UNIT(list_test, false, {
for (size_t i = 0; i < l_count(l); i++)
cmc_assert_equals(size_t, l_get(l, i), i + 1);
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[edge_case:count = 0], {
CMC_CREATE_TEST(pop_front[count = 0], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(!l_pop_front(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[edge_case:count = 1], {
CMC_CREATE_TEST(pop_front[count = 1], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(l_push_back(l, 10));
cmc_assert(l_pop_front(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_front[buffer_clear], {
@@ -278,58 +281,58 @@ CMC_CREATE_UNIT(list_test, false, {
cmc_assert_equals(size_t, 0, l->buffer[1]);
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop[edge_case:count = 0], {
CMC_CREATE_TEST(pop_at[count = 0], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(!l_pop(l, 1));
cmc_assert(!l_pop_at(l, 1));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop[edge_case:count = 1], {
CMC_CREATE_TEST(pop_at[count = 1], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(l_push_back(l, 1));
cmc_assert(l_pop(l, 0));
cmc_assert(l_pop_at(l, 0));
cmc_assert_equals(size_t, 0, l->buffer[0]);
l_free(l);
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);
cmc_assert(l_push_back(l, 1));
cmc_assert(l_push_back(l, 2));
cmc_assert(l_push_back(l, 3));
cmc_assert(l_pop(l, 1));
cmc_assert(l_pop_at(l, 1));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_back[edge_case:count = 0], {
CMC_CREATE_TEST(pop_back[count = 0], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(!l_pop_back(l));
l_free(l);
l_free(l, NULL);
});
CMC_CREATE_TEST(pop_back[edge_case:count = 1], {
CMC_CREATE_TEST(pop_back[count = 1], {
list *l = l_new(100);
cmc_assert_not_equals(ptr, NULL, l);
cmc_assert(l_push_back(l, 10));
cmc_assert(l_pop_back(l));
l_free(l);
l_free(l, NULL);
});
})
+36 -51
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/multimap.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/multimap.c"
CMC_CREATE_UNIT(multimap_test, false, {
CMC_CREATE_TEST(new, {
@@ -13,17 +14,17 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert_equals(size_t, 0, mm_count(map));
cmc_assert_greater_equals(size_t, (943722 / 0.8), mm_capacity(map));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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], {
multimap *map = mm_new(UINT64_MAX, 0.8, cmp, hash);
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
multimap *map = mm_new(UINT64_MAX, 0.99, cmp, hash);
cmc_assert_equals(ptr, NULL, map);
});
@@ -38,11 +39,11 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert_equals(size_t, 50, mm_count(map));
mm_clear(map);
mm_clear(map, NULL);
cmc_assert_equals(size_t, 0, mm_count(map));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(insert[count], {
@@ -50,12 +51,12 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 200; i++)
for (size_t i = 0; i < 100; i++)
cmc_assert(mm_insert(map, i % 20, i % 20));
cmc_assert_equals(size_t, 200, mm_count(map));
cmc_assert_equals(size_t, 100, mm_count(map));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(remove[count], {
@@ -73,10 +74,10 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert_equals(size_t, 140, mm_count(map));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(remove[edge_case:count = 0], {
CMC_CREATE_TEST(remove[count = 0], {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
@@ -85,10 +86,10 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert(!mm_remove(map, 10, &r));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(remove[edge_case:count = 1], {
CMC_CREATE_TEST(remove[count = 1], {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
@@ -98,41 +99,10 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert(mm_insert(map, 10, 11));
cmc_assert(mm_remove(map, 10, &r));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(insert_if, {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 1; i <= 100; i++)
cmc_assert(mm_insert_if(map, i % 20, i, i % 2 == 0) || i % 2 != 0);
cmc_assert_equals(size_t, 50, mm_count(map));
mm_free(map);
});
CMC_CREATE_TEST(remove_if, {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 1; i <= 100; i++)
cmc_assert(mm_insert(map, i % 20, i));
size_t r;
for (size_t i = 1; i <= 100; i++)
cmc_assert(mm_remove_if(map, i % 20, &r, i % 2 == 0) || i % 2 != 0);
cmc_assert_equals(size_t, 50, mm_count(map));
mm_free(map);
});
CMC_CREATE_TEST(get[key_ordering], {
CMC_CREATE_TEST(get[key ordering], {
multimap *map = mm_new(100, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
@@ -145,7 +115,22 @@ CMC_CREATE_UNIT(multimap_test, false, {
cmc_assert_equals(size_t, 100, mm_get(map, 10));
mm_free(map);
mm_free(map, NULL);
});
CMC_CREATE_TEST(key_count, {
multimap *map = mm_new(50, 0.8, cmp, hash);
cmc_assert_not_equals(ptr, NULL, map);
for (size_t i = 0; i < 1000; i++)
cmc_assert(mm_insert(map, i % 20, i % 20));
cmc_assert_equals(size_t, 1000, mm_count(map));
for (size_t i = 0; i < 20; i++)
cmc_assert_equals(size_t, 50, mm_key_count(map, i));
mm_free(map, NULL);
});
});
+82 -17
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/multiset.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/multiset.c"
CMC_CREATE_UNIT(multiset_test, false, {
CMC_CREATE_TEST(new, {
@@ -13,17 +14,17 @@ CMC_CREATE_UNIT(multiset_test, false, {
cmc_assert_equals(size_t, 0, ms_count(set));
cmc_assert_greater_equals(size_t, ((size_t)(943722 / 0.6)), ms_capacity(set));
ms_free(set);
ms_free(set, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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], {
multiset *set = ms_new(UINTMAX_MAX, 0.99, cmp, hash);
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
multiset *set = ms_new(UINT64_MAX, 0.99, cmp, hash);
cmc_assert_equals(ptr, NULL, set);
});
@@ -38,11 +39,11 @@ CMC_CREATE_UNIT(multiset_test, false, {
cmc_assert_equals(size_t, 50, ms_count(set));
ms_clear(set);
ms_clear(set, NULL);
cmc_assert_equals(size_t, 0, ms_count(set));
ms_free(set);
ms_free(set, NULL);
});
CMC_CREATE_TEST(insert[count cardinality multiplicity], {
@@ -63,24 +64,88 @@ CMC_CREATE_UNIT(multiset_test, false, {
for (size_t i = 0; i <= 3; i++)
cmc_assert_equals(size_t, i, ms_multiplicity_of(set, i));
ms_free(set);
ms_free(set, NULL);
});
CMC_CREATE_TEST(multiplicity, {
CMC_CREATE_TEST(remove[count cardinality multiplicity], {
multiset *set = ms_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 0; i < 100; i++)
cmc_assert(ms_insert(set, 1));
cmc_assert(ms_insert(set, 2));
cmc_assert(ms_insert(set, 2));
cmc_assert(ms_insert(set, 3));
cmc_assert(ms_insert(set, 3));
cmc_assert(ms_insert(set, 3));
cmc_assert_equals(size_t, 3, ms_count(set));
cmc_assert_equals(size_t, 6, ms_cardinality(set));
for (size_t i = 0; i <= 3; i++)
cmc_assert_equals(size_t, i, ms_multiplicity_of(set, i));
cmc_assert(ms_remove(set, 1));
cmc_assert(ms_remove(set, 2));
cmc_assert(ms_remove(set, 3));
cmc_assert_equals(size_t, 2, ms_count(set));
cmc_assert_equals(size_t, 3, ms_cardinality(set));
cmc_assert_equals(size_t, 0, ms_multiplicity_of(set, 0));
cmc_assert_equals(size_t, 0, ms_multiplicity_of(set, 1));
cmc_assert_equals(size_t, 1, ms_multiplicity_of(set, 2));
cmc_assert_equals(size_t, 2, ms_multiplicity_of(set, 3));
ms_free(set, NULL);
});
CMC_CREATE_TEST(remove_all[count cardinality multiplicity], {
multiset *set = ms_new(100, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(ms_insert(set, 1));
cmc_assert(ms_insert(set, 2));
cmc_assert(ms_insert(set, 2));
cmc_assert(ms_insert(set, 3));
cmc_assert(ms_insert(set, 3));
cmc_assert(ms_insert(set, 3));
cmc_assert_equals(size_t, 3, ms_count(set));
cmc_assert_equals(size_t, 6, ms_cardinality(set));
for (size_t i = 0; i <= 3; i++)
cmc_assert_equals(size_t, i, ms_multiplicity_of(set, i));
cmc_assert(ms_remove_all(set, 1));
cmc_assert(ms_remove_all(set, 3));
cmc_assert_equals(size_t, 1, ms_count(set));
cmc_assert_equals(size_t, 2, ms_cardinality(set));
cmc_assert_equals(size_t, 0, ms_multiplicity_of(set, 0));
cmc_assert_equals(size_t, 0, ms_multiplicity_of(set, 1));
cmc_assert_equals(size_t, 2, ms_multiplicity_of(set, 2));
cmc_assert_equals(size_t, 0, ms_multiplicity_of(set, 3));
ms_free(set, NULL);
});
CMC_CREATE_TEST(multiplicity, {
multiset *set = ms_new(50, 0.6, cmp, hash);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 0; i < 1000; i++)
cmc_assert(ms_insert(set, i % 20));
cmc_assert_equals(size_t, 20, ms_count(set));
cmc_assert_equals(size_t, 100, ms_cardinality(set));
cmc_assert_equals(size_t, 1000, ms_cardinality(set));
for (size_t i = 0; i < 20; i++)
cmc_assert_equals(size_t, 5, ms_multiplicity_of(set, i));
cmc_assert_equals(size_t, 50, ms_multiplicity_of(set, i));
ms_free(set);
ms_free(set, NULL);
});
});
+356 -9
View File
@@ -1,5 +1,8 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/queue.c"
CMC_CREATE_UNIT(queue_test, false, {
@@ -12,16 +15,16 @@ CMC_CREATE_UNIT(queue_test, false, {
cmc_assert_equals(size_t, 0, q_count(q));
cmc_assert_not_equals(ptr, NULL, q->buffer);
q_free(q);
q_free(q, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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[capacity = UINT64_MAX], {
queue *q = q_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, q);
@@ -37,15 +40,15 @@ CMC_CREATE_UNIT(queue_test, false, {
cmc_assert_equals(size_t, 50, q_count(q));
q_clear(q);
q_clear(q, NULL);
cmc_assert_equals(size_t, 0, q_count(q));
cmc_assert_equals(size_t, 100, q_capacity(q));
q_free(q);
q_free(q, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
queue *q = q_new(1);
cmc_assert_not_equals(ptr, NULL, q);
@@ -55,7 +58,351 @@ CMC_CREATE_UNIT(queue_test, false, {
cmc_assert_equals(size_t, 50, q_count(q));
q_free(q);
q_free(q, NULL);
});
CMC_CREATE_TEST(buffer_growth[item preservation], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 1; i <= 1200; i++)
{
q_enqueue(q, i);
}
size_t sum = 0;
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));
cmc_assert_equals(size_t, 720600, sum);
q_free(q, NULL);
});
CMC_CREATE_TEST(enqueue[count capacity], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 0; i < 150; i++)
cmc_assert(q_enqueue(q, i));
cmc_assert_equals(size_t, 150, q_count(q));
cmc_assert_greater(size_t, 100, q_capacity(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(enqueue[item preservation], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 1; i <= 100; i++)
cmc_assert(q_enqueue(q, i));
size_t sum = 0;
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, 5050, sum);
q_free(q, NULL);
});
CMC_CREATE_TEST(dequeue[count capacity], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert(q_enqueue(q, 10));
cmc_assert(q_dequeue(q));
cmc_assert_equals(size_t, 0, q_count(q));
cmc_assert(q_enqueue(q, 10));
cmc_assert(q_dequeue(q));
cmc_assert_equals(size_t, 0, q_count(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(dequeue[item preservation], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 200; i > 0; i--)
cmc_assert(q_enqueue(q, i));
for (size_t i = 0; i < 100; i++)
cmc_assert(q_dequeue(q));
size_t sum = 0;
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, 5050, sum);
q_free(q, NULL);
});
CMC_CREATE_TEST(peek[count = 0], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
size_t r = q_peek(q);
cmc_assert_equals(size_t, (size_t){0}, r);
q_free(q, NULL);
});
CMC_CREATE_TEST(peek[sum], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
size_t sum = 0;
for (size_t i = 0; i <= 100; i++)
cmc_assert(q_enqueue(q, i));
while (!q_empty(q))
{
size_t r = q_peek(q);
sum += r;
cmc_assert(q_dequeue(q));
}
cmc_assert_equals(size_t, 5050, sum);
q_free(q, NULL);
});
CMC_CREATE_TEST(contains, {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 1; i <= 20; i++)
cmc_assert(q_enqueue(q, i));
for (size_t i = 1; i <= 20; i++)
cmc_assert(q_contains(q, i, cmp));
q_clear(q, NULL);
for (size_t i = 1; i <= 20; i++)
cmc_assert(!q_contains(q, i, cmp));
q_free(q, NULL);
});
CMC_CREATE_TEST(contains[count = 0], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert(!q_contains(q, 10, cmp));
q_free(q, NULL);
});
CMC_CREATE_TEST(contains[count = 1], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert(!q_contains(q, 10, cmp));
cmc_assert(q_enqueue(q, 100));
cmc_assert(q_contains(q, 100, cmp));
cmc_assert(!q_contains(q, 101, cmp));
q_free(q, NULL);
});
CMC_CREATE_TEST(empty, {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert(q_empty(q));
cmc_assert(q_enqueue(q, 1));
cmc_assert(!q_empty(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(full, {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert(!q_full(q));
for (size_t i = 0; i != q_capacity(q); i++)
cmc_assert(q_enqueue(q, i));
cmc_assert(q_full(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(count, {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert_equals(size_t, 0, q_count(q));
for (size_t i = 0; i < 100; i++)
cmc_assert(q_enqueue(q, i));
cmc_assert_equals(size_t, 100, q_count(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(capacity, {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
cmc_assert_equals(size_t, 100, q_capacity(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(resize, {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 0; i < 150; i++)
cmc_assert(q_enqueue(q, i));
cmc_assert_equals(size_t, 150, q_count(q));
cmc_assert(q_resize(q, q_count(q)));
cmc_assert_equals(size_t, 150, q_capacity(q));
q_free(q, NULL);
});
CMC_CREATE_TEST(resize[item preservation], {
queue *q = q_new(100);
cmc_assert_not_equals(ptr, NULL, q);
for (size_t i = 1; i <= 150; i++)
cmc_assert(q_enqueue(q, i));
cmc_assert(q_resize(q, q_count(q)));
size_t sum = 0;
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, 11325, sum);
q_free(q, NULL);
});
CMC_CREATE_TEST(copy_of, {
queue *d1 = q_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
for (size_t i = 1; i <= 150; i++)
cmc_assert(q_enqueue(d1, i));
queue *d2 = q_copy_of(d1, NULL);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert_equals(size_t, q_count(d1), q_count(d2));
for (size_t i1 = d1->front, i2 = d2->front, j = 0; j < d1->count; j++)
{
cmc_assert_equals(size_t, d1->buffer[i1], d2->buffer[i2]);
i1 = (i1 + 1) % d1->capacity;
i2 = (i2 + 1) % d2->capacity;
}
q_free(d1, NULL);
q_free(d2, NULL);
});
CMC_CREATE_TEST(equals, {
queue *d1 = q_new(100);
queue *d2 = q_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
cmc_assert_not_equals(ptr, NULL, d2);
for (size_t i = 1; i <= 150; i++)
{
cmc_assert(q_enqueue(d1, i));
cmc_assert(q_enqueue(d2, i));
}
cmc_assert(q_equals(d1, d2, cmp));
q_free(d1, NULL);
q_free(d2, NULL);
});
CMC_CREATE_TEST(equals[from copy], {
queue *d1 = q_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
for (size_t i = 1; i <= 150; i++)
{
cmc_assert(q_enqueue(d1, i));
}
queue *d2 = q_copy_of(d1, NULL);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert(q_equals(d1, d2, cmp));
q_free(d1, NULL);
q_free(d2, NULL);
});
CMC_CREATE_TEST(equals[count = 0], {
queue *d1 = q_new(100);
cmc_assert_not_equals(ptr, NULL, d1);
queue *d2 = q_copy_of(d1, NULL);
cmc_assert_not_equals(ptr, NULL, d2);
cmc_assert(q_equals(d1, d2, cmp));
q_free(d1, NULL);
q_free(d2, NULL);
});
});
+138
View File
@@ -0,0 +1,138 @@
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/sortedlist.c"
CMC_CREATE_UNIT(sortedlist_test, false, {
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[capacity = 0], {
sortedlist *sl = sl_new(0, cmp);
cmc_assert_equals(ptr, NULL, sl);
});
CMC_CREATE_TEST(new[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[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);
});
CMC_CREATE_TEST(insert, {
sortedlist *sl = sl_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
cmc_assert(sl_insert(sl, 1));
sl_free(sl, NULL);
});
CMC_CREATE_TEST(remove, {
sortedlist *sl = sl_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
cmc_assert(sl_insert(sl, 32));
cmc_assert(sl_remove(sl, 0));
sl_free(sl, NULL);
});
CMC_CREATE_TEST(remove[count = 0], {
sortedlist *sl = sl_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
cmc_assert(!sl_remove(sl, 0));
sl_free(sl, NULL);
});
CMC_CREATE_TEST(remove[out of range], {
sortedlist *sl = sl_new(100, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
cmc_assert(sl_insert(sl, 32));
cmc_assert(!sl_remove(sl, 2));
sl_free(sl, NULL);
});
CMC_CREATE_TEST(indexof, {
sortedlist *sl = sl_new(1, cmp);
cmc_assert_not_equals(ptr, NULL, sl);
for (size_t i = 0; i < 20; i++)
cmc_assert(sl_insert(sl, i % 10));
/* 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 */
cmc_assert_equals(size_t, 4, sl_indexof(sl, 2, true));
cmc_assert_equals(size_t, 5, sl_indexof(sl, 2, false));
cmc_assert_equals(size_t, 0, sl_indexof(sl, 0, true));
cmc_assert_equals(size_t, 1, sl_indexof(sl, 0, false));
cmc_assert(sl_remove(sl, 0));
cmc_assert_equals(size_t, 0, sl_indexof(sl, 0, true));
cmc_assert_equals(size_t, 0, sl_indexof(sl, 0, false));
cmc_assert(sl_remove(sl, 0));
cmc_assert_equals(size_t, sl_count(sl), sl_indexof(sl, 0, true));
cmc_assert_equals(size_t, sl_count(sl), sl_indexof(sl, 0, false));
sl_free(sl, NULL);
});
});
+64 -95
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/stack.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/stack.c"
CMC_CREATE_UNIT(stack_test, false, {
CMC_CREATE_TEST(new, {
@@ -14,16 +15,16 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 0, s_count(s));
cmc_assert_not_equals(ptr, NULL, s->buffer);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(new[edge_case:capacity = 0], {
CMC_CREATE_TEST(new[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[capacity = UINT64_MAX], {
stack *s = s_new(UINT64_MAX);
cmc_assert_equals(ptr, NULL, s);
@@ -39,15 +40,15 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 50, s_count(s));
s_clear(s);
s_clear(s, NULL);
cmc_assert_equals(size_t, 0, s_count(s));
cmc_assert_equals(size_t, 100, s_capacity(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(buffer_growth[edge_case:capacity = 1], {
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
stack *s = s_new(1);
cmc_assert_not_equals(ptr, NULL, s);
@@ -58,7 +59,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 50, s_count(s));
cmc_assert_lesser_equals(size_t, s_capacity(s), s_count(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(push[count], {
@@ -71,7 +72,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 250, s_count(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(push[capacity], {
@@ -84,10 +85,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_lesser_equals(size_t, s_capacity(s), s_count(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(push[item_preservation], {
CMC_CREATE_TEST(push[item preservation], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -98,7 +99,7 @@ CMC_CREATE_UNIT(stack_test, false, {
for (size_t i = 0; i < s_count(s); i++)
cmc_assert_equals(size_t, i, s->buffer[i]);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(pop[count], {
@@ -113,7 +114,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 249, s_count(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(pop[capacity], {
@@ -128,10 +129,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_lesser_equals(size_t, s_capacity(s), s_count(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(pop[item_preservation], {
CMC_CREATE_TEST(pop[item preservation], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -145,48 +146,17 @@ CMC_CREATE_UNIT(stack_test, false, {
for (size_t i = 0; i < s_count(s); i++)
cmc_assert_equals(size_t, i, s->buffer[i]);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(pop[edge_case:count = 0], {
CMC_CREATE_TEST(pop[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
cmc_assert_equals(bool, false, s_pop(s));
s_free(s);
});
CMC_CREATE_TEST(push_if, {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
for (size_t i = 0; i < 250; i++)
s_push_if(s, i, i % 2 == 0);
for (size_t i = 0; i < s_count(s); i++)
cmc_assert(s->buffer[i] % 2 == 0);
s_free(s);
});
CMC_CREATE_TEST(pop_if, {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
for (size_t i = 0; i < 250; i++)
{
s_push(s, i);
s_pop_if(s, s_top(s) % 2 == 0);
}
for (size_t i = 0; i < s_count(s); i++)
cmc_assert_not_equals(uint32_t, 0, s->buffer[i] % 2);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(top, {
@@ -202,10 +172,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 247, s_top(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(top[edge_case:count = 0], {
CMC_CREATE_TEST(top[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -214,12 +184,12 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_pop(s));
cmc_assert_equals(size_t, s_impl_default_value(), s_top(s));
cmc_assert_equals(size_t, (size_t){0}, s_top(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(top[edge_case:count = 1], {
CMC_CREATE_TEST(top[count = 1], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -228,7 +198,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 1, s_count(s));
cmc_assert_equals(size_t, 10, s_top(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(contains, {
@@ -242,17 +212,17 @@ CMC_CREATE_UNIT(stack_test, false, {
for (size_t i = 0; i < 150; i++)
cmc_assert(s_contains(s, i, cmp));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(contains[edge_case:count = 0], {
CMC_CREATE_TEST(contains[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
cmc_assert_equals(bool, false, s_contains(s, 10, cmp));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(empty, {
@@ -262,7 +232,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_empty(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(empty[after_io], {
@@ -274,7 +244,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_pop(s));
cmc_assert(s_empty(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(full, {
@@ -287,10 +257,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_full(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(full[edge_case:capacity = 1], {
CMC_CREATE_TEST(full[capacity = 1], {
stack *s = s_new(1);
cmc_assert_not_equals(ptr, NULL, s);
@@ -299,7 +269,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_full(s));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_alloc, {
@@ -312,10 +282,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_not_equals(ptr, NULL, iter);
s_iter_free(iter);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_init[edge_case:count = 0], {
CMC_CREATE_TEST(iter_init[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -329,10 +299,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(iter.start);
cmc_assert(iter.end);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_start[edge_case:count = 0], {
CMC_CREATE_TEST(iter_start[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -343,10 +313,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_iter_start(&iter));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_end[edge_case:count = 0], {
CMC_CREATE_TEST(iter_end[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -357,7 +327,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert(s_iter_end(&iter));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration, {
@@ -384,7 +354,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 40200, total);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[while loop], {
@@ -414,10 +384,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 40200, total);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[edge_case:count = 1], {
CMC_CREATE_TEST(iteration[count = 1], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -437,10 +407,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 20, total);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[edge_case:count = capacity], {
CMC_CREATE_TEST(iteration[count = capacity], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -466,7 +436,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 2000, total);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iteration[to_start = it_start and to_end = it_end], {
@@ -501,10 +471,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(bool, it1.start, it2.start);
cmc_assert_equals(bool, it1.end, it2.end);
s_free(s);
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);
@@ -520,10 +490,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(bool, false, s_iter_prev(&iter));
s_free(s);
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);
@@ -542,10 +512,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(bool, false, s_iter_prev(&iter));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_value[edge_case:count = 0], {
CMC_CREATE_TEST(iter_value[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -554,12 +524,12 @@ CMC_CREATE_UNIT(stack_test, false, {
s_iter_init(&iter, s);
cmc_assert_equals(size_t, s_impl_default_value(), s_iter_value(&iter));
cmc_assert_equals(size_t, (size_t){0}, s_iter_value(&iter));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(iter_rvalue[edge_case:count = 0], {
CMC_CREATE_TEST(iter_rvalue[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -570,7 +540,7 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(ptr, NULL, s_iter_rvalue(&iter));
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(index, {
@@ -585,12 +555,12 @@ CMC_CREATE_UNIT(stack_test, false, {
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));
}
@@ -609,10 +579,10 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 90, total);
s_free(s);
s_free(s, NULL);
});
CMC_CREATE_TEST(index[edge_case:count = 0], {
CMC_CREATE_TEST(index[count = 0], {
stack *s = s_new(100);
cmc_assert_not_equals(ptr, NULL, s);
@@ -622,7 +592,6 @@ CMC_CREATE_UNIT(stack_test, false, {
cmc_assert_equals(size_t, 0, s_iter_index(&iter));
s_free(s);
s_free(s, NULL);
});
});
+8 -8
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/treemap.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/treemap.c"
CMC_CREATE_UNIT(treemap_test, false, {
CMC_CREATE_TEST(new, {
@@ -10,7 +11,7 @@ CMC_CREATE_UNIT(treemap_test, false, {
cmc_assert_not_equals(ptr, NULL, map);
tm_free(map);
tm_free(map, NULL);
});
CMC_CREATE_TEST(clear[count], {
@@ -23,12 +24,11 @@ CMC_CREATE_UNIT(treemap_test, false, {
cmc_assert_equals(size_t, 50, tm_count(map));
tm_clear(map);
tm_clear(map, NULL);
cmc_assert_equals(size_t, 0, tm_count(map));
cmc_assert_equals(ptr, NULL, map->root);
tm_free(map);
tm_free(map, NULL);
});
});
+8 -8
View File
@@ -1,8 +1,9 @@
#include "utl/assert.h"
#include "utl/test.h"
#include "../src/treeset.c"
#include "utl.c"
#include <utl/assert.h>
#include <utl/log.h>
#include <utl/test.h>
#include "../src/treeset.c"
CMC_CREATE_UNIT(treeset_test, false, {
CMC_CREATE_TEST(new, {
@@ -10,7 +11,7 @@ CMC_CREATE_UNIT(treeset_test, false, {
cmc_assert_not_equals(ptr, NULL, set);
ts_free(set);
ts_free(set, NULL);
});
CMC_CREATE_TEST(clear[count], {
@@ -23,12 +24,11 @@ CMC_CREATE_UNIT(treeset_test, false, {
cmc_assert_equals(size_t, 50, ts_count(set));
ts_clear(set);
ts_clear(set, NULL);
cmc_assert_equals(size_t, 0, ts_count(set));
cmc_assert_equals(ptr, NULL, set->root);
ts_free(set);
ts_free(set, NULL);
});
});
+21
View File
@@ -3,6 +3,7 @@
#define CMC_UNIT_TEST_UTL__
#include <stdlib.h>
#include <cmc/hashmap.h>
int cmp(size_t a, size_t b)
{
@@ -20,4 +21,24 @@ size_t hash(size_t a)
return a;
}
size_t numhash(size_t a)
{
return a;
}
size_t hashcapminus1(size_t a)
{
return cmc_hashtable_primes[0] - 1;
}
size_t hashcapminus4(size_t a)
{
return cmc_hashtable_primes[0] - 1;
}
size_t hash0(size_t a)
{
return 0;
}
#endif /* CMC_UNIT_TEST_UTL__ */