Added heap and list resize function and refactored some tests and added some more
This commit is contained in:
1 parent
9f8671f75f
commit
b9b507bf07
15 files changed
+841
-752
No files matched your search
+4
-20
@@ -346,26 +346,10 @@ static const char *cmc_string_fmt_deque = "%s at %p { buffer:%p, capacity:%" PRI
|
||||
if (PFX##_capacity(_deque_) == capacity) \
|
||||
return true; \
|
||||
\
|
||||
size_t new_capacity = 0; \
|
||||
if (capacity < PFX##_count(_deque_)) \
|
||||
return false; \
|
||||
\
|
||||
if (capacity < PFX##_capacity(_deque_)) \
|
||||
{ \
|
||||
/* Shrink */ \
|
||||
if (capacity < PFX##_count(_deque_)) \
|
||||
return false; \
|
||||
\
|
||||
new_capacity = capacity; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Grow */ \
|
||||
if (PFX##_capacity(_deque_) * 2 < capacity) \
|
||||
new_capacity = capacity; \
|
||||
else \
|
||||
new_capacity = PFX##_capacity(_deque_) * 2; \
|
||||
} \
|
||||
\
|
||||
V *new_buffer = malloc(sizeof(V) * new_capacity); \
|
||||
V *new_buffer = malloc(sizeof(V) * capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
@@ -380,7 +364,7 @@ static const char *cmc_string_fmt_deque = "%s at %p { buffer:%p, capacity:%" PRI
|
||||
free(_deque_->buffer); \
|
||||
\
|
||||
_deque_->buffer = new_buffer; \
|
||||
_deque_->capacity = new_capacity; \
|
||||
_deque_->capacity = capacity; \
|
||||
_deque_->front = 0; \
|
||||
_deque_->back = _deque_->count; \
|
||||
\
|
||||
|
||||
+18
-26
@@ -112,7 +112,6 @@ typedef enum cmc_heap_order_e
|
||||
bool PFX##_remove(SNAME *_heap_, V *result); \
|
||||
/* Element Access */ \
|
||||
V PFX##_peek(SNAME *_heap_); \
|
||||
V *PFX##_peek_ref(SNAME *_heap_); \
|
||||
/* Collection State */ \
|
||||
bool PFX##_contains(SNAME *_heap_, V element); \
|
||||
bool PFX##_empty(SNAME *_heap_); \
|
||||
@@ -120,6 +119,7 @@ typedef enum cmc_heap_order_e
|
||||
size_t PFX##_count(SNAME *_heap_); \
|
||||
size_t PFX##_capacity(SNAME *_heap_); \
|
||||
/* Collection Utility */ \
|
||||
bool PFX##_resize(SNAME *_heap_, size_t capacity); \
|
||||
SNAME *PFX##_copy_of(SNAME *_heap_, V (*copy_func)(V)); \
|
||||
bool PFX##_equals(SNAME *_heap1_, SNAME *_heap2_); \
|
||||
cmc_string PFX##_to_string(SNAME *_heap_); \
|
||||
@@ -159,7 +159,6 @@ typedef enum cmc_heap_order_e
|
||||
#define CMC_GENERATE_HEAP_SOURCE(PFX, SNAME, V) \
|
||||
\
|
||||
/* Implementation Detail Functions */ \
|
||||
static bool PFX##_impl_grow(SNAME *_heap_); \
|
||||
static bool PFX##_impl_float_up(SNAME *_heap_, size_t index); \
|
||||
static bool PFX##_impl_float_down(SNAME *_heap_, size_t index); \
|
||||
static SNAME##_iter PFX##_impl_it_start(SNAME *_heap_); \
|
||||
@@ -232,7 +231,7 @@ typedef enum cmc_heap_order_e
|
||||
{ \
|
||||
if (PFX##_full(_heap_)) \
|
||||
{ \
|
||||
if (!PFX##_impl_grow(_heap_)) \
|
||||
if (!PFX##_resize(_heap_, PFX##_count(_heap_) * 2)) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
@@ -275,14 +274,6 @@ typedef enum cmc_heap_order_e
|
||||
return _heap_->buffer[0]; \
|
||||
} \
|
||||
\
|
||||
V *PFX##_peek_ref(SNAME *_heap_) \
|
||||
{ \
|
||||
if (PFX##_empty(_heap_)) \
|
||||
return NULL; \
|
||||
\
|
||||
return &(_heap_->buffer[0]); \
|
||||
} \
|
||||
\
|
||||
bool PFX##_contains(SNAME *_heap_, V element) \
|
||||
{ \
|
||||
for (size_t i = 0; i < _heap_->count; i++) \
|
||||
@@ -314,6 +305,22 @@ typedef enum cmc_heap_order_e
|
||||
return _heap_->capacity; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_resize(SNAME *_heap_, size_t capacity) \
|
||||
{ \
|
||||
if (capacity < PFX##_count(_heap_)) \
|
||||
return false; \
|
||||
\
|
||||
V *new_buffer = realloc(_heap_->buffer, sizeof(V) * capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
\
|
||||
_heap_->buffer = new_buffer; \
|
||||
_heap_->capacity = capacity; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
SNAME *PFX##_copy_of(SNAME *_heap_, V (*copy_func)(V)) \
|
||||
{ \
|
||||
SNAME *result = PFX##_new(_heap_->capacity, _heap_->HO, _heap_->cmp); \
|
||||
@@ -526,21 +533,6 @@ typedef enum cmc_heap_order_e
|
||||
return iter->cursor; \
|
||||
} \
|
||||
\
|
||||
static bool PFX##_impl_grow(SNAME *_heap_) \
|
||||
{ \
|
||||
size_t new_capacity = _heap_->capacity * 2; \
|
||||
\
|
||||
V *new_buffer = realloc(_heap_->buffer, sizeof(V) * new_capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
\
|
||||
_heap_->buffer = new_buffer; \
|
||||
_heap_->capacity = new_capacity; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
static bool PFX##_impl_float_up(SNAME *_heap_, size_t index) \
|
||||
{ \
|
||||
/* Current index */ \
|
||||
|
||||
+617
-624
File diff suppressed because it is too large.
Load diff
+14
-14
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
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);
|
||||
@@ -49,7 +49,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
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);
|
||||
@@ -63,7 +63,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(buffer_growth[item_preservation], {
|
||||
CMC_CREATE_TEST(buffer_growth[item preservation], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -100,7 +100,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(push_front[item_preservation], {
|
||||
CMC_CREATE_TEST(push_front[item preservation], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -134,7 +134,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(push_back[item_preservation], {
|
||||
CMC_CREATE_TEST(push_back[item preservation], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -172,7 +172,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_front[item_preservation], {
|
||||
CMC_CREATE_TEST(pop_front[item preservation], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -213,7 +213,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_back[item_preservation], {
|
||||
CMC_CREATE_TEST(pop_back[item preservation], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -300,7 +300,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(front[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(front[count = 0], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -341,7 +341,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(back[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(back[count = 0], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -404,7 +404,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(contains[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(contains[count = 0], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -414,7 +414,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(contains[edge_case count = 1], {
|
||||
CMC_CREATE_TEST(contains[count = 1], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -509,7 +509,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(resize[item_preservation], {
|
||||
CMC_CREATE_TEST(resize[item preservation], {
|
||||
deque *d = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d);
|
||||
@@ -616,7 +616,7 @@ CMC_CREATE_UNIT(deque_test, true, {
|
||||
d_free(d2, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(equals[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(equals[count = 0], {
|
||||
deque *d1 = d_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, d1);
|
||||
|
||||
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
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], {
|
||||
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
|
||||
hashmap *map = hm_new(UINT64_MAX, 0.99, cmp, hash);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, map);
|
||||
@@ -59,7 +59,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
hm_free(map, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(insert[edge_case smallest capacity], {
|
||||
CMC_CREATE_TEST(insert[smallest capacity], {
|
||||
hashmap *map = hm_new(1, 0.99, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, map);
|
||||
@@ -190,7 +190,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
hm_free(map, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(remove[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(remove[count = 0], {
|
||||
hashmap *map = hm_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, map);
|
||||
@@ -233,7 +233,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
hm_free(map, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(max[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(max[count = 0], {
|
||||
hashmap *map = hm_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, map);
|
||||
@@ -261,7 +261,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
hm_free(map, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(min[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(min[count = 0], {
|
||||
hashmap *map = hm_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, map);
|
||||
@@ -283,7 +283,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
hm_free(map, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(get[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(get[count = 0], {
|
||||
hashmap *map = hm_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, map);
|
||||
@@ -308,7 +308,7 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
hm_free(map, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(get_ref[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(get_ref[count = 0], {
|
||||
hashmap *map = hm_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, map);
|
||||
@@ -330,6 +330,16 @@ CMC_CREATE_UNIT(hashmap_test, true, {
|
||||
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);
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(hashset_test, true, {
|
||||
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], {
|
||||
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
|
||||
hashset *set = hs_new(UINT64_MAX, 0.99, cmp, hash);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, set);
|
||||
@@ -59,7 +59,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
|
||||
hs_free(set, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(insert[edge_case smallest capacity], {
|
||||
CMC_CREATE_TEST(insert[smallest capacity], {
|
||||
hashset *set = hs_new(1, 0.99, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, set);
|
||||
@@ -162,7 +162,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
|
||||
hs_free(set, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(remove[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(remove[count = 0], {
|
||||
hashset *set = hs_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, set);
|
||||
@@ -203,7 +203,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
|
||||
hs_free(set, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(max[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(max[count = 0], {
|
||||
hashset *set = hs_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, set);
|
||||
@@ -229,7 +229,7 @@ CMC_CREATE_UNIT(hashset_test, true, {
|
||||
hs_free(set, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(min[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(min[count = 0], {
|
||||
hashset *set = hs_new(100, 0.6, cmp, hash);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, set);
|
||||
@@ -251,6 +251,16 @@ CMC_CREATE_UNIT(hashset_test, true, {
|
||||
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);
|
||||
|
||||
|
||||
+101
-1
@@ -55,10 +55,110 @@ CMC_CREATE_UNIT(heap_test, true, {
|
||||
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, 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, h_impl_default_value(), h_peek(h));
|
||||
|
||||
h_free(h, NULL);
|
||||
});
|
||||
});
|
||||
@@ -19,7 +19,7 @@ CMC_CREATE_UNIT(intervalheap_test, true, {
|
||||
ih_free(ih, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new[edge_case capacity = 0], {
|
||||
CMC_CREATE_TEST(new[capacity = 0], {
|
||||
intervalheap *ih = ih_new(0, cmp);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, ih);
|
||||
@@ -28,7 +28,7 @@ CMC_CREATE_UNIT(intervalheap_test, true, {
|
||||
ih_free(ih, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new[edge_case capacity = UINT64_MAX], {
|
||||
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
|
||||
intervalheap *ih = ih_new(UINT64_MAX, cmp);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, ih);
|
||||
@@ -55,7 +55,7 @@ CMC_CREATE_UNIT(intervalheap_test, true, {
|
||||
ih_free(ih, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(buffer_growth[edge_case capacity = 1], {
|
||||
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
|
||||
intervalheap *ih = ih_new(1, cmp);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, ih);
|
||||
|
||||
@@ -36,7 +36,7 @@ CMC_CREATE_UNIT(linkedlist_test, true, {
|
||||
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);
|
||||
@@ -62,7 +62,7 @@ CMC_CREATE_UNIT(linkedlist_test, true, {
|
||||
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);
|
||||
|
||||
+17
-17
@@ -19,19 +19,19 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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++)
|
||||
@@ -49,7 +49,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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;
|
||||
@@ -79,7 +79,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -121,7 +121,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -135,7 +135,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -151,7 +151,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -167,7 +167,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -210,7 +210,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -237,7 +237,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -253,7 +253,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -262,7 +262,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -286,7 +286,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
l_free(l, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_at[edge_case count = 0], {
|
||||
CMC_CREATE_TEST(pop_at[count = 0], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
@@ -295,7 +295,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
l_free(l, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_at[edge_case count = 1], {
|
||||
CMC_CREATE_TEST(pop_at[count = 1], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
@@ -319,7 +319,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
@@ -328,7 +328,7 @@ CMC_CREATE_UNIT(list_test, true, {
|
||||
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);
|
||||
|
||||
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(multimap_test, true, {
|
||||
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], {
|
||||
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
|
||||
multimap *map = mm_new(UINT64_MAX, 0.99, cmp, hash);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, map);
|
||||
@@ -79,7 +79,7 @@ CMC_CREATE_UNIT(multimap_test, true, {
|
||||
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);
|
||||
@@ -91,7 +91,7 @@ CMC_CREATE_UNIT(multimap_test, true, {
|
||||
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);
|
||||
@@ -104,7 +104,7 @@ CMC_CREATE_UNIT(multimap_test, true, {
|
||||
mm_free(map, NULL);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
@@ -19,13 +19,13 @@ CMC_CREATE_UNIT(multiset_test, true, {
|
||||
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 = UINT64_MAX], {
|
||||
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
|
||||
multiset *set = ms_new(UINT64_MAX, 0.99, cmp, hash);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, set);
|
||||
|
||||
@@ -20,13 +20,13 @@ CMC_CREATE_UNIT(queue_test, true, {
|
||||
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);
|
||||
@@ -50,7 +50,7 @@ CMC_CREATE_UNIT(queue_test, true, {
|
||||
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);
|
||||
|
||||
@@ -20,13 +20,13 @@ CMC_CREATE_UNIT(sortedlist_test, true, {
|
||||
sl_free(sl, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new[edge_case capacity = 0], {
|
||||
CMC_CREATE_TEST(new[capacity = 0], {
|
||||
sortedlist *sl = sl_new(0, cmp);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, sl);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new[edge_case capacity = UINT64_MAX], {
|
||||
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
|
||||
sortedlist *sl = sl_new(UINT64_MAX, cmp);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, sl);
|
||||
@@ -50,7 +50,7 @@ CMC_CREATE_UNIT(sortedlist_test, true, {
|
||||
sl_free(sl, NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(buffer_growth[edge_case capacity = 1], {
|
||||
CMC_CREATE_TEST(buffer_growth[capacity = 1], {
|
||||
sortedlist *sl = sl_new(1, cmp);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, sl);
|
||||
|
||||
+18
-18
@@ -20,13 +20,13 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -50,7 +50,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -90,7 +90,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -134,7 +134,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -151,7 +151,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -177,7 +177,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -191,7 +191,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -217,7 +217,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -262,7 +262,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -287,7 +287,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -304,7 +304,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -318,7 +318,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -389,7 +389,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -412,7 +412,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -517,7 +517,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -531,7 +531,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
@@ -584,7 +584,7 @@ CMC_CREATE_UNIT(stack_test, true, {
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user