Added the possibility of running tests from each collection separately
Also added CMC_BITSET_WORD_TYPE so that the type of the bitset buffer can be defined with the -D flag
This commit is contained in:
1 parent
981fef3def
commit
bf3535970e
19 files changed
+527
-156
No files matched your search
+5
-1
@@ -41,7 +41,11 @@
|
||||
* ------------------------------------------------------------------------- */
|
||||
/* Defines the underlaying data type for the bitset array */
|
||||
/* Possible values: uint64_t, uint32_t, uint16_t, uint8_t, size_t */
|
||||
typedef uint32_t cmc_bitset_word;
|
||||
#ifndef CMC_BITSET_WORD_TYPE
|
||||
#define CMC_BITSET_WORD_TYPE uint32_t
|
||||
#endif /* CMC_BITSET_WORD_TYPE */
|
||||
|
||||
typedef CMC_BITSET_WORD_TYPE cmc_bitset_word;
|
||||
|
||||
/* to_string format */
|
||||
static const char *cmc_string_fmt_bitset = "struct %s "
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ static void cmc_test_log(const char *unit_name, const char *current_test,
|
||||
printf( \
|
||||
" +---------------------------------------------------------------+\n"); \
|
||||
printf("%s", cmc_test_color(0)); \
|
||||
printf("\n\n"); \
|
||||
printf("\n"); \
|
||||
\
|
||||
return tinfo.failed; \
|
||||
}
|
||||
|
||||
+74
-12
@@ -4,24 +4,13 @@ CFLAGS += -Wno-unused -Wno-missing-braces
|
||||
DBFLAGS = -g3
|
||||
CVFLAGS = --coverage -O0
|
||||
INCLUDE = ../../src/
|
||||
UNIT = ./unt
|
||||
|
||||
main: FORCE
|
||||
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
gcov ./main.c
|
||||
|
||||
dev: FORCE
|
||||
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
gcov ./main.c -n
|
||||
rm *.gcda *.gcno *.exe
|
||||
|
||||
windev: FORCE
|
||||
$(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
gcov ./main.c -n
|
||||
del *.gcda *.gcno *.exe
|
||||
|
||||
nocov: FORCE
|
||||
$(CC) main.c -o main.exe $(CFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
@@ -38,4 +27,77 @@ debug: FORCE
|
||||
valgrind: debug
|
||||
valgrind --leak-check=full ./main.exe
|
||||
|
||||
all: bitset deque hashbidimap hashmap hashmultimap hashmultiset hashset heap intervalheap linkedlist list queue sortedlist stack treemap treeset
|
||||
rm ./main.exe
|
||||
|
||||
bitset: $(UNIT)/bitset.c $(INCLUDE)/cmc/bitset.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint8_t
|
||||
./main.exe
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint16_t
|
||||
./main.exe
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint32_t
|
||||
./main.exe
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint64_t
|
||||
./main.exe
|
||||
|
||||
deque: $(UNIT)/deque.c $(INCLUDE)/cmc/deque.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
hashbidimap: $(UNIT)/hashbidimap.c $(INCLUDE)/cmc/hashbidimap.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
hashmap: $(UNIT)/hashmap.c $(INCLUDE)/cmc/hashmap.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
hashmultimap: $(UNIT)/hashmultimap.c $(INCLUDE)/cmc/hashmultimap.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
hashmultiset: $(UNIT)/hashmultiset.c $(INCLUDE)/cmc/hashmultiset.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
hashset: $(UNIT)/hashset.c $(INCLUDE)/cmc/hashset.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
heap: $(UNIT)/heap.c $(INCLUDE)/cmc/heap.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
intervalheap: $(UNIT)/intervalheap.c $(INCLUDE)/cmc/intervalheap.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
linkedlist: $(UNIT)/linkedlist.c $(INCLUDE)/cmc/linkedlist.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
list: $(UNIT)/list.c $(INCLUDE)/cmc/list.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
queue: $(UNIT)/queue.c $(INCLUDE)/cmc/queue.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
sortedlist: $(UNIT)/sortedlist.c $(INCLUDE)/cmc/sortedlist.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
stack: $(UNIT)/stack.c $(INCLUDE)/cmc/stack.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
treemap: $(UNIT)/treemap.c $(INCLUDE)/cmc/treemap.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
treeset: $(UNIT)/treeset.c $(INCLUDE)/cmc/treeset.h
|
||||
$(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR
|
||||
./main.exe
|
||||
|
||||
FORCE:
|
||||
+58
-16
@@ -12,6 +12,10 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
const size_t word_bytes = sizeof(cmc_bitset_word);
|
||||
const size_t word_bits = sizeof(cmc_bitset_word) * CHAR_BIT;
|
||||
|
||||
printf("%s", cmc_test_color(5));
|
||||
printf(" BitSet<"CMC_TO_STRING(CMC_BITSET_WORD_TYPE)">\n");
|
||||
printf("%s", cmc_test_color(0));
|
||||
|
||||
CMC_CREATE_TEST(PFX##_new(), {
|
||||
struct bitset *bs = bs_new(64);
|
||||
|
||||
@@ -123,24 +127,24 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
struct bitset *bs = bs_new(word_bits);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, bs);
|
||||
cmc_assert(0 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[0]);
|
||||
|
||||
bs->flag = cmc_flags.ERROR;
|
||||
cmc_assert(bs_set(bs, 0));
|
||||
cmc_assert(1 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 1, bs->buffer[0]);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, bs->flag);
|
||||
|
||||
bs->buffer[0] = 0;
|
||||
|
||||
cmc_assert(bs_set(bs, word_bits - 1));
|
||||
cmc_assert(((cmc_bitset_word)1 << (word_bits - 1)) == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 1)), bs->buffer[0]);
|
||||
|
||||
cmc_assert(bs_set(bs, word_bits * 8 - 1));
|
||||
cmc_assert(((cmc_bitset_word)1 << (word_bits - 1)) ==
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 1)),
|
||||
bs->buffer[bs_bit_to_index(word_bits * 8 - 1)]);
|
||||
|
||||
cmc_assert(bs_set(bs, word_bits * 18 - 2));
|
||||
cmc_assert(((cmc_bitset_word)1 << (word_bits - 2)) ==
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 2)),
|
||||
bs->buffer[bs_bit_to_index(word_bits * 18 - 2)]);
|
||||
|
||||
bs_free(bs);
|
||||
@@ -150,7 +154,7 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
struct bitset *bs = bs_new(word_bits);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, bs);
|
||||
cmc_assert(0 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[0]);
|
||||
|
||||
bs->flag = cmc_flags.ERROR;
|
||||
cmc_assert(bs_set_range(bs, 0, 0));
|
||||
@@ -166,18 +170,24 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
cmc_assert_equals(uint8_t, 244, bs->buffer[0]);
|
||||
|
||||
cmc_assert(bs_set_range(bs, word_bits * 6 - 2, word_bits * 6 - 2));
|
||||
cmc_assert(((cmc_bitset_word)1 << (word_bits - 2)) ==
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 2)),
|
||||
bs->buffer[bs_bit_to_index(word_bits * 6 - 2)]);
|
||||
|
||||
// Make sure we have at leats word_bits * 40 slots
|
||||
// Make sure we have at least word_bits * 40 slots
|
||||
bs_set(bs, word_bits * 40);
|
||||
|
||||
cmc_assert(bs_set_range(bs, word_bits * 20, word_bits * 21 - 1));
|
||||
cmc_assert((~(cmc_bitset_word)0) ==
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, (~(cmc_bitset_word)0),
|
||||
bs->buffer[bs_bit_to_index(word_bits * 20)]);
|
||||
|
||||
cmc_assert(0 == bs->buffer[bs_bit_to_index(word_bits * 20 - 1)]);
|
||||
cmc_assert(0 == bs->buffer[bs_bit_to_index(word_bits * 21 + 1)]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[bs_bit_to_index(word_bits * 20 - 1)]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[bs_bit_to_index(word_bits * 21 + 1)]);
|
||||
|
||||
cmc_assert(bs_set_range(bs, 0, word_bits * 100 - 1));
|
||||
cmc_assert_equals(size_t, 100, bs->capacity);
|
||||
|
||||
for (size_t i = 0; i < bs->capacity; i++)
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0), bs->buffer[i]);
|
||||
|
||||
bs_free(bs);
|
||||
});
|
||||
@@ -186,16 +196,16 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
struct bitset *bs = bs_new(word_bits * 10 - 1);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, bs);
|
||||
cmc_assert(0 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[0]);
|
||||
|
||||
bs->buffer[0] = 1; // 0001
|
||||
cmc_assert(bs_clear(bs, 0));
|
||||
cmc_assert(0 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[0]);
|
||||
|
||||
bs->buffer[0] = 10; // 1010
|
||||
cmc_assert(bs_clear(bs, 1));
|
||||
cmc_assert(bs_clear(bs, 3));
|
||||
cmc_assert(0 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[0]);
|
||||
|
||||
cmc_assert(bs_clear(bs, word_bits * 100 - 1));
|
||||
cmc_assert_equals(size_t, 100, bs->capacity);
|
||||
@@ -207,9 +217,9 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
struct bitset *bs = bs_new(word_bits * 10 - 1);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, bs);
|
||||
cmc_assert(0 == bs->buffer[0]);
|
||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[0]);
|
||||
|
||||
cmc_assert(bs_clear(bs, word_bits * 100 - 1));
|
||||
cmc_assert(bs_clear_range(bs, 0, word_bits * 100 - 1));
|
||||
cmc_assert_equals(size_t, 100, bs->capacity);
|
||||
|
||||
cmc_assert(bs_set_range(bs, word_bits * 20, word_bits * 21 - 1));
|
||||
@@ -218,6 +228,16 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
cmc_assert_equals(uint32_t, 0,
|
||||
bs->buffer[bs_bit_to_index(word_bits * 20)]);
|
||||
|
||||
for (size_t i = 0; i < bs->capacity; i++)
|
||||
bs->buffer[i] = ~((cmc_bitset_word)0);
|
||||
|
||||
cmc_assert(bs_clear_range(bs, 0, word_bits * 200 - 1));
|
||||
|
||||
cmc_assert_equals(size_t, 200, bs->capacity);
|
||||
|
||||
for (size_t i = 0; i < bs->capacity; i++)
|
||||
cmc_assert_equals(size_t, 0, bs->buffer[0]);
|
||||
|
||||
bs_free(bs);
|
||||
});
|
||||
|
||||
@@ -243,6 +263,13 @@ CMC_CREATE_UNIT(BitSet, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(BitSetIter, true, {
|
||||
const size_t word_bytes = sizeof(cmc_bitset_word);
|
||||
const size_t word_bits = sizeof(cmc_bitset_word) * CHAR_BIT;
|
||||
|
||||
printf("%s", cmc_test_color(5));
|
||||
printf(" BitSet<"CMC_TO_STRING(CMC_BITSET_WORD_TYPE)">\n");
|
||||
printf("%s", cmc_test_color(0));
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_start(), {
|
||||
struct bitset *bs = bs_new(64);
|
||||
|
||||
@@ -251,3 +278,18 @@ CMC_CREATE_UNIT(BitSetIter, true, {
|
||||
bs_free(bs);
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = BitSet() + BitSetIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | BitSet Suit : %-47s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1724,3 +1724,18 @@ CMC_CREATE_UNIT(DequeIter, true, {
|
||||
d_free(d);
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = Deque() + DequeIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | Deque Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -824,3 +824,22 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(HashBidiMapIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = HashBidiMap() + HashBidiMapIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | HashBidiMap Suit : %-42s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1336,3 +1336,18 @@ CMC_CREATE_UNIT(HashMapIter, true, {
|
||||
hm_free(map);
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = HashMap() + HashMapIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | HashMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -936,3 +936,18 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
||||
hmm_free(map);
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = HashMultiMap() + HashMultiMapIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | HashMultiMap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -856,3 +856,18 @@ CMC_CREATE_UNIT(HashMultiSetIter, true, {
|
||||
hms_free(set);
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = HashMultiSet() + HashMultiSetIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | HashMultiSet Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1034,3 +1034,18 @@ CMC_CREATE_UNIT(HashSetIter, true, {
|
||||
hs_free(set);
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = HashSet() + HashSetIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | HashSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -290,3 +290,22 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(HeapIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = Heap() + HeapIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | Heap Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -612,3 +612,22 @@ CMC_CREATE_UNIT(IntervalHeap, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(IntervalHeapIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = IntervalHeap() + IntervalHeapIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | IntervalHeap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -342,3 +342,22 @@ CMC_CREATE_UNIT(LinkedList, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(LinkedListIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = LinkedList() + LinkedListIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | LinkedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -612,3 +612,22 @@ CMC_CREATE_UNIT(List, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
})
|
||||
|
||||
CMC_CREATE_UNIT(ListIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = List() + ListIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | List Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -544,3 +544,22 @@ CMC_CREATE_UNIT(Queue, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(QueueIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = Queue() + QueueIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | Queue Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -312,3 +312,22 @@ CMC_CREATE_UNIT(SortedList, true, {
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(SortedListIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = SortedList() + SortedListIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | SortedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
+143
-126
@@ -278,6 +278,134 @@ CMC_CREATE_UNIT(Stack, true, {
|
||||
s_free(s);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(flags, {
|
||||
struct stack *s = s_new(100, s_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// clear
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s_clear(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// customize
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s_customize(s, NULL, NULL);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// push
|
||||
s->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_push(s, 1));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// pop
|
||||
s->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_pop(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
cmc_assert(!s_pop(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.EMPTY, s_flag(s));
|
||||
|
||||
// top
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s_top(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.EMPTY, s_flag(s));
|
||||
|
||||
cmc_assert(s_push(s, 1));
|
||||
s_top(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// contains
|
||||
s->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_contains(s, 1));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// copy_of
|
||||
s->flag = cmc_flags.ERROR;
|
||||
struct stack *s2 = s_copy_of(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s2));
|
||||
|
||||
// equals
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s2->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_equals(s, s2));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s2));
|
||||
|
||||
s_free(s);
|
||||
s_free(s2);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(callbacks, {
|
||||
struct stack *s = s_new_custom(100, s_fval, NULL, callbacks);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, s);
|
||||
|
||||
total_create = 0;
|
||||
total_read = 0;
|
||||
total_update = 0;
|
||||
total_delete = 0;
|
||||
total_resize = 0;
|
||||
|
||||
cmc_assert(s_push(s, 10));
|
||||
cmc_assert_equals(int32_t, 1, total_create);
|
||||
|
||||
cmc_assert(s_pop(s));
|
||||
cmc_assert_equals(int32_t, 1, total_delete);
|
||||
|
||||
cmc_assert(s_push(s, 1));
|
||||
cmc_assert_equals(int32_t, 2, total_create);
|
||||
|
||||
cmc_assert_equals(size_t, 1, s_top(s));
|
||||
cmc_assert_equals(int32_t, 1, total_read);
|
||||
|
||||
cmc_assert(s_contains(s, 1));
|
||||
cmc_assert_equals(int32_t, 2, total_read);
|
||||
|
||||
cmc_assert(s_resize(s, 1000));
|
||||
cmc_assert_equals(int32_t, 1, total_resize);
|
||||
|
||||
cmc_assert(s_resize(s, 10));
|
||||
cmc_assert_equals(int32_t, 2, total_resize);
|
||||
|
||||
cmc_assert_equals(int32_t, 2, total_create);
|
||||
cmc_assert_equals(int32_t, 2, total_read);
|
||||
cmc_assert_equals(int32_t, 0, total_update);
|
||||
cmc_assert_equals(int32_t, 1, total_delete);
|
||||
cmc_assert_equals(int32_t, 2, total_resize);
|
||||
|
||||
s_customize(s, NULL, NULL);
|
||||
|
||||
s_clear(s);
|
||||
cmc_assert(s_push(s, 10));
|
||||
cmc_assert(s_pop(s));
|
||||
cmc_assert(s_push(s, 1));
|
||||
cmc_assert_equals(size_t, 1, s_top(s));
|
||||
cmc_assert(s_contains(s, 1));
|
||||
cmc_assert(s_resize(s, 1000));
|
||||
cmc_assert(s_resize(s, 10));
|
||||
|
||||
cmc_assert_equals(int32_t, 2, total_create);
|
||||
cmc_assert_equals(int32_t, 2, total_read);
|
||||
cmc_assert_equals(int32_t, 0, total_update);
|
||||
cmc_assert_equals(int32_t, 1, total_delete);
|
||||
cmc_assert_equals(int32_t, 2, total_resize);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, s->callbacks);
|
||||
|
||||
s_free(s);
|
||||
|
||||
total_create = 0;
|
||||
total_read = 0;
|
||||
total_update = 0;
|
||||
total_delete = 0;
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(StackIter, true, {
|
||||
CMC_CREATE_TEST(iter_alloc, {
|
||||
struct stack *s = s_new(100, s_fval);
|
||||
|
||||
@@ -608,130 +736,19 @@ CMC_CREATE_UNIT(Stack, true, {
|
||||
|
||||
s_free(s);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(flags, {
|
||||
struct stack *s = s_new(100, s_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// clear
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s_clear(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// customize
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s_customize(s, NULL, NULL);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// push
|
||||
s->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_push(s, 1));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// pop
|
||||
s->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_pop(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
cmc_assert(!s_pop(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.EMPTY, s_flag(s));
|
||||
|
||||
// top
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s_top(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.EMPTY, s_flag(s));
|
||||
|
||||
cmc_assert(s_push(s, 1));
|
||||
s_top(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// contains
|
||||
s->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_contains(s, 1));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
|
||||
// copy_of
|
||||
s->flag = cmc_flags.ERROR;
|
||||
struct stack *s2 = s_copy_of(s);
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s2));
|
||||
|
||||
// equals
|
||||
s->flag = cmc_flags.ERROR;
|
||||
s2->flag = cmc_flags.ERROR;
|
||||
cmc_assert(s_equals(s, s2));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s));
|
||||
cmc_assert_equals(int32_t, cmc_flags.OK, s_flag(s2));
|
||||
|
||||
s_free(s);
|
||||
s_free(s2);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(callbacks, {
|
||||
struct stack *s = s_new_custom(100, s_fval, NULL, callbacks);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, s);
|
||||
|
||||
total_create = 0;
|
||||
total_read = 0;
|
||||
total_update = 0;
|
||||
total_delete = 0;
|
||||
total_resize = 0;
|
||||
|
||||
cmc_assert(s_push(s, 10));
|
||||
cmc_assert_equals(int32_t, 1, total_create);
|
||||
|
||||
cmc_assert(s_pop(s));
|
||||
cmc_assert_equals(int32_t, 1, total_delete);
|
||||
|
||||
cmc_assert(s_push(s, 1));
|
||||
cmc_assert_equals(int32_t, 2, total_create);
|
||||
|
||||
cmc_assert_equals(size_t, 1, s_top(s));
|
||||
cmc_assert_equals(int32_t, 1, total_read);
|
||||
|
||||
cmc_assert(s_contains(s, 1));
|
||||
cmc_assert_equals(int32_t, 2, total_read);
|
||||
|
||||
cmc_assert(s_resize(s, 1000));
|
||||
cmc_assert_equals(int32_t, 1, total_resize);
|
||||
|
||||
cmc_assert(s_resize(s, 10));
|
||||
cmc_assert_equals(int32_t, 2, total_resize);
|
||||
|
||||
cmc_assert_equals(int32_t, 2, total_create);
|
||||
cmc_assert_equals(int32_t, 2, total_read);
|
||||
cmc_assert_equals(int32_t, 0, total_update);
|
||||
cmc_assert_equals(int32_t, 1, total_delete);
|
||||
cmc_assert_equals(int32_t, 2, total_resize);
|
||||
|
||||
s_customize(s, NULL, NULL);
|
||||
|
||||
s_clear(s);
|
||||
cmc_assert(s_push(s, 10));
|
||||
cmc_assert(s_pop(s));
|
||||
cmc_assert(s_push(s, 1));
|
||||
cmc_assert_equals(size_t, 1, s_top(s));
|
||||
cmc_assert(s_contains(s, 1));
|
||||
cmc_assert(s_resize(s, 1000));
|
||||
cmc_assert(s_resize(s, 10));
|
||||
|
||||
cmc_assert_equals(int32_t, 2, total_create);
|
||||
cmc_assert_equals(int32_t, 2, total_read);
|
||||
cmc_assert_equals(int32_t, 0, total_update);
|
||||
cmc_assert_equals(int32_t, 1, total_delete);
|
||||
cmc_assert_equals(int32_t, 2, total_resize);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, s->callbacks);
|
||||
|
||||
s_free(s);
|
||||
|
||||
total_create = 0;
|
||||
total_read = 0;
|
||||
total_update = 0;
|
||||
total_delete = 0;
|
||||
total_resize = 0;
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = Stack() + StackIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | Stack Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -212,3 +212,22 @@ CMC_CREATE_UNIT(TreeMap, true, {
|
||||
tm_free(map);
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(TreeMapIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = TreeMap() + TreeMapIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | TreeMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -164,3 +164,22 @@ CMC_CREATE_UNIT(TreeSet, true, {
|
||||
ts_free(set);
|
||||
});
|
||||
});
|
||||
|
||||
CMC_CREATE_UNIT(TreeSetIter, true, {
|
||||
|
||||
});
|
||||
|
||||
#ifdef CMC_TEST_MAIN
|
||||
int main(void)
|
||||
{
|
||||
int result = TreeSet() + TreeSetIter();
|
||||
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n");
|
||||
printf(" | TreeSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||
printf(" +---------------------------------------------------------------+");
|
||||
printf("\n\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user