Many minor fixes, changes and first attempt of codecov
Changes on assert.h, foreach.h, test.h and timer.h Updated benchmarks, examples and tests Updated tests/Makefile for future Added list.c test Added CMC namespace to CONCATC and CONCATH on macro_collections.h
This commit is contained in:
1 parent
1edb12a83c
commit
7b349ea426
15 files changed
+1009
-742
No files matched your search
@@ -14,3 +14,5 @@ script:
|
||||
- export CC=gcc-7
|
||||
- cd ./tests
|
||||
- make
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
@@ -1,10 +1,18 @@
|
||||
# MAJOR.MINOR.ADJUSTMENTS
|
||||
|
||||
1.5.2
|
||||
Added utl/test.h
|
||||
Added utl/assert.h
|
||||
Added tests/list.c - UnitTest for LIST
|
||||
Small fixes on utl/foreach.h, utl/test.h and redone utl/timer.h
|
||||
Removed utl/log.h functions that were unnecessary
|
||||
Added the CMC namespace to CONCATC and CONCATH at macro_collections.h
|
||||
|
||||
1.5.1
|
||||
New queue benchmark
|
||||
Added sac/queue.h
|
||||
Added utl/timer.h
|
||||
Fixing descriptions other minor fixes
|
||||
Fixing descriptions and other minor fixes
|
||||
|
||||
1.5.0
|
||||
Changed tests compilation and execution to a single Makefile
|
||||
|
||||
+15
-16
@@ -13,7 +13,6 @@
|
||||
* - Output
|
||||
*/
|
||||
#include "macro_collections.h"
|
||||
#include "utl/timer.h"
|
||||
#include "util/twister.c"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
@@ -82,17 +81,17 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
\
|
||||
sname *coll = initfunc; \
|
||||
\
|
||||
TIMER_START(total) \
|
||||
TIMER_START(timer) \
|
||||
timer_start(total); \
|
||||
timer_start(timer); \
|
||||
\
|
||||
for (size_t i = 0; i < NTOTAL; i++) \
|
||||
{ \
|
||||
insertbody; \
|
||||
} \
|
||||
\
|
||||
TIMER_STOP(timer) \
|
||||
timer_stop(timer); \
|
||||
\
|
||||
TIMER_CALC(timer) \
|
||||
timer_calc(timer); \
|
||||
\
|
||||
size_t s1 = PFX##_count(coll); \
|
||||
\
|
||||
@@ -100,16 +99,16 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
\
|
||||
double input_time = timer.result; \
|
||||
\
|
||||
TIMER_START(timer) \
|
||||
timer_start(timer); \
|
||||
\
|
||||
for (size_t i = 0; i < s; i++) \
|
||||
{ \
|
||||
searchbody; \
|
||||
} \
|
||||
\
|
||||
TIMER_STOP(timer) \
|
||||
timer_stop(timer); \
|
||||
\
|
||||
TIMER_CALC(timer) \
|
||||
timer_calc(timer); \
|
||||
\
|
||||
printf(" SEARCH %10s TOOK %8.0lf milliseconds for %8" PRIuMAX " elements\n", #NAME, timer.result, s); \
|
||||
\
|
||||
@@ -117,30 +116,30 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
\
|
||||
sname##_iter iter; \
|
||||
\
|
||||
TIMER_START(timer) \
|
||||
timer_start(timer); \
|
||||
\
|
||||
for (PFX##_iter_init(&iter, coll); !PFX##_iter_end(&iter); PFX##_iter_next(&iter)) \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
TIMER_STOP(timer) \
|
||||
timer_stop(timer); \
|
||||
\
|
||||
TIMER_CALC(timer) \
|
||||
timer_calc(timer); \
|
||||
\
|
||||
printf("ITERATION %10s TOOK %8.0lf milliseconds for %8" PRIuMAX " elements\n", #NAME, timer.result, s1); \
|
||||
\
|
||||
double iter_time = timer.result; \
|
||||
\
|
||||
TIMER_START(timer); \
|
||||
timer_start(timer); \
|
||||
\
|
||||
for (size_t i = 0; i < NTOTAL; i++) \
|
||||
{ \
|
||||
removebody; \
|
||||
} \
|
||||
\
|
||||
TIMER_STOP(timer) \
|
||||
timer_stop(timer); \
|
||||
\
|
||||
TIMER_CALC(timer) \
|
||||
timer_calc(timer); \
|
||||
\
|
||||
size_t s2 = PFX##_count(coll); \
|
||||
\
|
||||
@@ -148,8 +147,8 @@ COLLECTION_GENERATE(HASHMAP, hm, hmap, /* FMOD */, int, int)
|
||||
\
|
||||
double output_time = timer.result; \
|
||||
\
|
||||
TIMER_STOP(total) \
|
||||
TIMER_CALC(total) \
|
||||
timer_stop(total); \
|
||||
timer_calc(total); \
|
||||
\
|
||||
PFX##_free(coll); \
|
||||
\
|
||||
|
||||
@@ -57,7 +57,7 @@ int main(void)
|
||||
// Inside, the variable 'iter' will be available and from it you can access
|
||||
// the key, value or index.
|
||||
printf("MAP[%4d] = %.3lf\n", hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
})
|
||||
});
|
||||
|
||||
hm_free(map);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ int main(int argc, char const *argv[])
|
||||
|
||||
map_insert(library, value->isbn, value->name);
|
||||
set_insert(counter, value->name);
|
||||
})
|
||||
});
|
||||
|
||||
printf("Library Size: %d\n", map_count(library));
|
||||
printf("Unique book titles: %d\n\n", set_count(counter));
|
||||
@@ -69,7 +69,7 @@ int main(int argc, char const *argv[])
|
||||
FOR_EACH(q, queue, shelf, {
|
||||
book *value = q_iter_value(&iter);
|
||||
printf("[ %d : %-45s ]\n", value->isbn, value->name);
|
||||
})
|
||||
});
|
||||
printf("\n");
|
||||
|
||||
set_free(counter);
|
||||
@@ -122,11 +122,11 @@ int main(int argc, char const *argv[])
|
||||
|
||||
if (chrcmp(buffer, value) == 0)
|
||||
il_push_back(search_list, key);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(il, intlist, search_list, {
|
||||
printf("[ %d ]\n", il_iter_value(&iter));
|
||||
})
|
||||
});
|
||||
|
||||
il_free(search_list);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ int main(int argc, char const *argv[])
|
||||
free(b->name);
|
||||
|
||||
free(b);
|
||||
})
|
||||
});
|
||||
|
||||
l_free(books);
|
||||
q_free(shelf);
|
||||
|
||||
@@ -67,7 +67,7 @@ int main(int argc, char const *argv[])
|
||||
printf("%d ]\n", value);
|
||||
else
|
||||
printf("%d, ", value);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(s, stack, s, {
|
||||
int value = s_iter_value(&iter);
|
||||
@@ -78,7 +78,7 @@ int main(int argc, char const *argv[])
|
||||
printf("%d ]\n", value);
|
||||
else
|
||||
printf("%d, ", value);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(q, queue, q, {
|
||||
int value = q_iter_value(&iter);
|
||||
@@ -89,7 +89,7 @@ int main(int argc, char const *argv[])
|
||||
printf("%d ]\n", value);
|
||||
else
|
||||
printf("%d, ", value);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(d, deque, d, {
|
||||
int value = d_iter_value(&iter);
|
||||
@@ -100,7 +100,7 @@ int main(int argc, char const *argv[])
|
||||
printf("%d ]\n", value);
|
||||
else
|
||||
printf("%d, ", value);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(ll, llist, ll, {
|
||||
int value = ll_iter_value(&iter);
|
||||
@@ -111,7 +111,7 @@ int main(int argc, char const *argv[])
|
||||
printf("%d ]\n", value);
|
||||
else
|
||||
printf("%d, ", value);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(ts, tset, ts, {
|
||||
int value = ts_iter_value(&iter);
|
||||
@@ -122,7 +122,7 @@ int main(int argc, char const *argv[])
|
||||
printf("%d ]\n", value);
|
||||
else
|
||||
printf("%d, ", value);
|
||||
})
|
||||
});
|
||||
|
||||
l_free(l);
|
||||
ll_free(ll);
|
||||
|
||||
@@ -186,7 +186,7 @@ int main(void)
|
||||
int sum = 0;
|
||||
FOR_EACH(il, int_list, integers, {
|
||||
sum += il_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
printf("\n\nSUM: %d\n", sum);
|
||||
|
||||
@@ -256,7 +256,7 @@ int main(void)
|
||||
|
||||
FOR_EACH(dq, deque, d, {
|
||||
sum3 += dq_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
printf("Deque sum: %d\n", sum3);
|
||||
|
||||
|
||||
@@ -11,22 +11,22 @@
|
||||
#ifndef CMC_MACRO_COLLECTIONS
|
||||
#define CMC_MACRO_COLLECTIONS
|
||||
|
||||
#define CONCATH_(C) C##_WRAPGEN_HEADER
|
||||
#define CONCATC_(C) C##_WRAPGEN_SOURCE
|
||||
#define CMC_CONCATH_(C) C##_WRAPGEN_HEADER
|
||||
#define CMC_CONCATC_(C) C##_WRAPGEN_SOURCE
|
||||
|
||||
#define CONCATH(C) CONCATH_(C)
|
||||
#define CONCATC(C) CONCATC_(C)
|
||||
#define CMC_CONCATH(C) CMC_CONCATH_(C)
|
||||
#define CMC_CONCATC(C) CMC_CONCATC_(C)
|
||||
|
||||
#define COLLECTION_GENERATE(C, PFX, SNAME, FMOD, K, V) \
|
||||
COLLECTION_GENERATE_HEADER(C, PFX, SNAME, FMOD, K, V) \
|
||||
COLLECTION_GENERATE_SOURCE(C, PFX, SNAME, FMOD, K, V)
|
||||
|
||||
#define COLLECTION_GENERATE_HEADER(C, PFX, SNAME, FMOD, K, V) \
|
||||
CONCATH(C) \
|
||||
CMC_CONCATH(C) \
|
||||
(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
#define COLLECTION_GENERATE_SOURCE(C, PFX, SNAME, FMOD, K, V) \
|
||||
CONCATC(C) \
|
||||
CMC_CONCATC(C) \
|
||||
(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
#include "cmc/deque.h"
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "sac/queue.h"
|
||||
#include "sac/stack.h"
|
||||
|
||||
#include "utl/assert.h"
|
||||
#include "utl/foreach.h"
|
||||
#include "utl/log.h"
|
||||
#include "utl/test.h"
|
||||
|
||||
+682
-665
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -24,7 +24,7 @@
|
||||
{ \
|
||||
BODY; \
|
||||
} \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define FOR_EACH_REV(PFX, SNAME, TARGET, BODY) \
|
||||
do \
|
||||
@@ -33,6 +33,6 @@
|
||||
{ \
|
||||
BODY; \
|
||||
} \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#endif /* CMC_FOR_EACH */
|
||||
+4
-4
@@ -103,10 +103,10 @@ static void cmc_test_log(const char *unit_name, const char *current_test, bool a
|
||||
tinfo.verbose = VERBOSE; \
|
||||
\
|
||||
/* Tests */ \
|
||||
TIMER_START(timer); \
|
||||
timer_start(timer); \
|
||||
BODY; \
|
||||
TIMER_STOP(timer); \
|
||||
TIMER_CALC(timer); \
|
||||
timer_stop(timer); \
|
||||
timer_calc(timer); \
|
||||
\
|
||||
unittest_abort: \
|
||||
if (tinfo.aborted) \
|
||||
@@ -133,7 +133,7 @@ static void cmc_test_log(const char *unit_name, const char *current_test, bool a
|
||||
\
|
||||
BODY; \
|
||||
\
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define CMC_TEST_PASS() \
|
||||
do \
|
||||
|
||||
+19
-6
@@ -22,13 +22,26 @@ typedef struct timer_s
|
||||
double result;
|
||||
} timer_t;
|
||||
|
||||
#define TIMER_START(timer) \
|
||||
timer.start = clock();
|
||||
#define timer_start(timer) \
|
||||
do \
|
||||
{ \
|
||||
(timer).start = clock(); \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#define TIMER_STOP(timer) \
|
||||
timer.stop = clock();
|
||||
#define timer_stop(timer) \
|
||||
do \
|
||||
{ \
|
||||
(timer).stop = clock(); \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#define TIMER_CALC(timer) \
|
||||
timer.result = (double)(((timer.stop - timer.start) * 1000.0) / CLOCKS_PER_SEC);
|
||||
#define timer_calc(timer) \
|
||||
do \
|
||||
{ \
|
||||
timer_t *t = &(timer); \
|
||||
t->result = (double)(t->stop - t->start) * 1000.0 / CLOCKS_PER_SEC; \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#endif /* CMC_TIMER_H */
|
||||
+14
-8
@@ -1,15 +1,21 @@
|
||||
CFLAGS= -Wno-unused-function -Wno-unused-paramter -Wno-unused-variable -std=c11 -Wall -Wextra
|
||||
CC = gcc
|
||||
CFLAGS = -std=c11 -Wall -Wextra
|
||||
CFLAGS += -Wno-unused-function -Wno-unused-paramter -Wno-unused-variable -Wno-unused-label
|
||||
CVFLAGS = --coverage -O0
|
||||
|
||||
main:
|
||||
gcc foreach.c -o foreach $(CFLAGS)
|
||||
$(CC) foreach.c -o foreach $(CFLAGS)
|
||||
./foreach
|
||||
gcc iterators.c -o iterators $(CFLAGS)
|
||||
$(CC) iterators.c -o iterators $(CFLAGS)
|
||||
./iterators
|
||||
gcc contains.c -o contains $(CFLAGS)
|
||||
$(CC) contains.c -o contains $(CFLAGS)
|
||||
./contains
|
||||
gcc types.c -o types $(CFLAGS)
|
||||
$(CC) types.c -o types $(CFLAGS)
|
||||
./types
|
||||
gcc -c ./sep/sep.c -o ./sep/sep.o $(CFLAGS)
|
||||
gcc -c ./sep/main.c -o ./sep/main.o $(CFLAGS)
|
||||
gcc ./sep/sep.o ./sep/main.o -o ./sep/sep
|
||||
$(CC) -c ./sep/sep.c -o ./sep/sep.o $(CFLAGS)
|
||||
$(CC) -c ./sep/main.c -o ./sep/main.o $(CFLAGS)
|
||||
$(CC) ./sep/sep.o ./sep/main.o -o ./sep/sep
|
||||
./sep/sep
|
||||
$(CC) list.c -o list $(CFLAGS) $(CVFLAGS)
|
||||
./list
|
||||
gcov ./list.c
|
||||
+20
-20
@@ -72,45 +72,45 @@ int main(void)
|
||||
|
||||
FOR_EACH(d, deque, d, {
|
||||
sum3 += d_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(hm, hmap, hm, {
|
||||
sum10 += hm_iter_key(&iter);
|
||||
sum11 += hm_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(hs, hset, hs, {
|
||||
sum9 += hs_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(h, heap, h, {
|
||||
sum5 += h_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(ll, linked, ll, {
|
||||
sum4 += ll_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(l, list, l, {
|
||||
sum0 += l_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(q, queue, q, {
|
||||
sum2 += q_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(s, stack, s, {
|
||||
sum1 += s_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(tm, tmap, tm, {
|
||||
sum7 += tm_iter_key(&iter);
|
||||
sum8 += tm_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH(ts, tset, ts, {
|
||||
sum6 += ts_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
printf("\n-------------------- FOR_EACH --------------------\n");
|
||||
if (sum3 == 50005000)
|
||||
@@ -161,45 +161,45 @@ int main(void)
|
||||
|
||||
FOR_EACH_REV(d, deque, d, {
|
||||
sum3 += d_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(hm, hmap, hm, {
|
||||
sum10 += hm_iter_key(&iter);
|
||||
sum11 += hm_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(hs, hset, hs, {
|
||||
sum9 += hs_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(h, heap, h, {
|
||||
sum5 += h_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(ll, linked, ll, {
|
||||
sum4 += ll_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(l, list, l, {
|
||||
sum0 += l_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(q, queue, q, {
|
||||
sum2 += q_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(s, stack, s, {
|
||||
sum1 += s_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(tm, tmap, tm, {
|
||||
sum7 += tm_iter_key(&iter);
|
||||
sum8 += tm_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
FOR_EACH_REV(ts, tset, ts, {
|
||||
sum6 += ts_iter_value(&iter);
|
||||
})
|
||||
});
|
||||
|
||||
printf("-------------------- FOR_EACH_REV --------------------\n");
|
||||
if (sum3 == 50005000)
|
||||
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
#include "../src/macro_collections.h"
|
||||
|
||||
LIST_GENERATE(l, list, , size_t)
|
||||
|
||||
CMC_CREATE_UNIT(list_test, true, {
|
||||
CMC_CREATE_TEST(new, {
|
||||
list *l = l_new(1000000);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
bool passed = l->capacity == 1000000 && l->count == 0 && l->buffer;
|
||||
|
||||
cmc_assert_equals(size_t, 1000000, l->capacity);
|
||||
cmc_assert_equals(size_t, 0, l_count(l));
|
||||
cmc_assert_not_equals(ptr, NULL, l->buffer);
|
||||
|
||||
if (passed)
|
||||
CMC_TEST_PASS();
|
||||
else
|
||||
CMC_TEST_FAIL();
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new [edge_case:capacity = 0], {
|
||||
list *l = l_new(0);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, l);
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(l == NULL);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new_from[count item_preservation], {
|
||||
size_t v[5];
|
||||
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
v[i] = i;
|
||||
}
|
||||
|
||||
list *l = l_new_from(v, 5);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
bool passed = true;
|
||||
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
cmc_assert_equals(size_t, i, l_get(l, i));
|
||||
|
||||
passed = passed && l_get(l, i) == i;
|
||||
}
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 5);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new_from [edge_case:size = 1], {
|
||||
size_t a = 10;
|
||||
|
||||
size_t *values = &a;
|
||||
|
||||
list *l = l_new_from(values, 1);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 1);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(clear[count capacity], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
for (size_t i = 0; i < 50; i++)
|
||||
l_push_back(l, i);
|
||||
|
||||
l_clear(l);
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 0 && l_capacity(l) == 100);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(push_front[count capacity item_preservation grow], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
for (size_t i = 0; i < 200; i++)
|
||||
l_push_front(l, i);
|
||||
|
||||
bool passed = true;
|
||||
|
||||
for (size_t i = 0; i < l_count(l); i++)
|
||||
{
|
||||
passed = passed && l_get(l, i) == (l_count(l) - i - 1);
|
||||
|
||||
cmc_assert_equals(size_t, l_get(l, i), l_count(l) - i - 1);
|
||||
}
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(push[count capacity item_preservation grow], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
for (size_t i = 0; i < 200; i++)
|
||||
l_push(l, i, l_count(l));
|
||||
|
||||
bool passed = true;
|
||||
|
||||
for (size_t i = 0; i < l_count(l); i++)
|
||||
{
|
||||
passed = passed && l_get(l, i) == i;
|
||||
|
||||
cmc_assert_equals(size_t, l_get(l, i), i);
|
||||
}
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(push_back[count capacity item_preservation grow], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
for (size_t i = 0; i < 200; i++)
|
||||
l_push_back(l, i);
|
||||
|
||||
bool passed = true;
|
||||
|
||||
for (size_t i = 0; i < l_count(l); i++)
|
||||
{
|
||||
passed = passed && l_get(l, i) == i;
|
||||
|
||||
cmc_assert_equals(size_t, l_get(l, i), i);
|
||||
}
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 200);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_front[count item_preservation], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, l);
|
||||
|
||||
for (size_t i = 0; i < 200; i++)
|
||||
l_push_back(l, i);
|
||||
|
||||
bool passed = l_pop_front(l);
|
||||
|
||||
for (size_t i = 0; i < l_count(l); i++)
|
||||
{
|
||||
passed = passed && l_get(l, i) == i + 1;
|
||||
|
||||
cmc_assert_equals(size_t, l_get(l, i), i + 1);
|
||||
}
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 199);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_front [edge_case: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));
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(l_count(l) == 0);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_front [edge_case:count = 2], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert(l_push_back(l, 10));
|
||||
cmc_assert(l_push_front(l, 10));
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(l_pop_front(l) && l_count(l) == 1);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(pop_front[buffer_clear], {
|
||||
list *l = l_new(100);
|
||||
|
||||
cmc_assert(l_push_back(l, 10));
|
||||
cmc_assert(l_push_front(l, 10));
|
||||
|
||||
// Default value is all bytes are 0
|
||||
bool passed = l_pop_front(l) && l->buffer[1] == 0;
|
||||
|
||||
cmc_assert_equals(size_t, 0, l->buffer[1]);
|
||||
|
||||
CMC_TEST_PASS_ELSE_FAIL(passed && l_count(l) == 1);
|
||||
|
||||
l_free(l);
|
||||
});
|
||||
})
|
||||
|
||||
int main(void)
|
||||
{
|
||||
list_test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user