--- a/test/test_list.cpp Sun Nov 06 16:11:11 2022 +0100 +++ b/test/test_list.cpp Sat Nov 12 15:56:58 2022 +0100 @@ -27,6 +27,7 @@ */ #include "cx/linked_list.h" +#include "cx/array_list.h" #include "cx/utils.h" #include "cx/compare.h" #include "util_allocator.h" @@ -563,11 +564,12 @@ int_test_data<testdata_len> testdata; auto autofree(CxList *list) const -> CxList * { - lists.insert(list); + if (list != nullptr) lists.insert(list); return list; } auto linkedListFromTestData() const -> CxList * { + // TODO: replace with cxListAddArray return autofree( cxLinkedListFromArray( &testingAllocator, @@ -585,17 +587,23 @@ return list; } + auto arrayListFromTestData() const -> CxList * { + auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), testdata_len)); + // TODO: replace with cxListAddArray + cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]); + return list; + } + void verifyCreate(CxList *list) const { EXPECT_EQ(list->content_destructor_type, CX_DESTRUCTOR_NONE); EXPECT_EQ(list->size, 0); - EXPECT_EQ(list->capacity, (size_t) -1); EXPECT_EQ(list->allocator, &testingAllocator); EXPECT_EQ(list->cmpfunc, cx_cmp_int); } void verifyAdd( CxList *list, - bool write_through + bool as_pointer ) { auto len = testdata_len; cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0); @@ -603,7 +611,7 @@ EXPECT_GE(list->capacity, list->size); cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); cx_for_n (i, len) ++testdata.data[i]; - if (write_through) { + if (as_pointer) { cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); } else { cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i] - 1); @@ -769,15 +777,22 @@ class PointerLinkedList : public HighLevelTest { }; +class ArrayList : public HighLevelTest { +}; + TEST_F(LinkedList, cxLinkedListCreate) { CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); + ASSERT_NE(list, nullptr); EXPECT_EQ(list->itemsize, sizeof(int)); + EXPECT_EQ(list->capacity, (size_t) -1); verifyCreate(list); } TEST_F(PointerLinkedList, cxPointerLinkedListCreate) { CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int)); + ASSERT_NE(list, nullptr); EXPECT_EQ(list->itemsize, sizeof(void *)); + EXPECT_EQ(list->capacity, (size_t) -1); verifyCreate(list); } @@ -786,9 +801,21 @@ cx_for_n (i, testdata_len) cxListAdd(expected, &testdata.data[i]); CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cx_cmp_int, sizeof(int), testdata_len, testdata.data.data())); + ASSERT_NE(list, nullptr); + EXPECT_EQ(list->itemsize, sizeof(int)); + EXPECT_EQ(list->capacity, (size_t) -1); + EXPECT_EQ(list->size, testdata_len); EXPECT_EQ(cxListCompare(list, expected), 0); } +TEST_F(ArrayList, cxArrayListCreate) { + CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); + ASSERT_NE(list, nullptr); + EXPECT_EQ(list->itemsize, sizeof(int)); + EXPECT_EQ(list->capacity, 8); + verifyCreate(list); +} + TEST_F(LinkedList, cxListAdd) { CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); verifyAdd(list, false); @@ -799,6 +826,12 @@ verifyAdd(list, true); } +TEST_F(ArrayList, cxListAdd) { + ASSERT_EQ(1,0); // TODO: remove when implemented + CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); + verifyAdd(list, false); +} + TEST_F(LinkedList, cxListInsert) { verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); } @@ -807,6 +840,11 @@ verifyInsert(autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int))); } +TEST_F(ArrayList, cxListInsert) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2))); +} + TEST_F(LinkedList, cxListRemove) { verifyRemove(linkedListFromTestData()); } @@ -815,6 +853,11 @@ verifyRemove(pointerLinkedListFromTestData()); } +TEST_F(ArrayList, cxListRemove) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifyRemove(arrayListFromTestData()); +} + TEST_F(LinkedList, cxListAt) { verifyAt(linkedListFromTestData()); } @@ -823,6 +866,11 @@ verifyAt(pointerLinkedListFromTestData()); } +TEST_F(ArrayList, cxListAt) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifyAt(arrayListFromTestData()); +} + TEST_F(LinkedList, cxListFind) { verifyFind(linkedListFromTestData()); } @@ -831,6 +879,11 @@ verifyFind(pointerLinkedListFromTestData()); } +TEST_F(ArrayList, cxListFind) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifyFind(arrayListFromTestData()); +} + TEST_F(LinkedList, cxListSort) { verifySort(linkedListFromTestData()); } @@ -839,6 +892,11 @@ verifySort(pointerLinkedListFromTestData()); } +TEST_F(ArrayList, cxListSort) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifySort(arrayListFromTestData()); +} + TEST_F(LinkedList, Iterator) { verifyIterator(linkedListFromTestData()); } @@ -847,6 +905,11 @@ verifyIterator(pointerLinkedListFromTestData()); } +TEST_F(ArrayList, Iterator) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifyIterator(arrayListFromTestData()); +} + TEST_F(LinkedList, InsertViaIterator) { int fivenums[] = {0, 1, 2, 3, 4, 5}; CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cx_cmp_int, sizeof(int), 5, fivenums)); @@ -860,6 +923,15 @@ verifyInsertViaIterator(list); } +TEST_F(ArrayList, InsertViaIterator) { + ASSERT_EQ(1,0); // TODO: remove when implemented + int fivenums[] = {0, 1, 2, 3, 4, 5}; + CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)); + // TODO: replace with cxListAddArray + cx_for_n (i, 5) cxListAdd(list, &fivenums[i]); + verifyInsertViaIterator(list); +} + TEST_F(LinkedList, cxListReverse) { verifyReverse(linkedListFromTestData()); } @@ -868,6 +940,11 @@ verifyReverse(pointerLinkedListFromTestData()); } +TEST_F(ArrayList, cxListReverse) { + ASSERT_EQ(1,0); // TODO: remove when implemented + verifyReverse(arrayListFromTestData()); +} + TEST_F(LinkedList, cxListCompare) { auto left = linkedListFromTestData(); auto right = linkedListFromTestData(); @@ -880,6 +957,13 @@ verifyCompare(left, right); } +TEST_F(LinkedList, cxListCompareWithArrayList) { + ASSERT_EQ(1,0); // TODO: remove when implemented + auto left = linkedListFromTestData(); + auto right = arrayListFromTestData(); + verifyCompare(left, right); +} + TEST_F(PointerLinkedList, cxListCompare) { auto left = pointerLinkedListFromTestData(); auto right = pointerLinkedListFromTestData(); @@ -892,6 +976,34 @@ verifyCompare(left, right); } +TEST_F(PointerLinkedList, cxListCompareWithArrayList) { + ASSERT_EQ(1,0); // TODO: remove when implemented + auto left = pointerLinkedListFromTestData(); + auto right = arrayListFromTestData(); + verifyCompare(left, right); +} + +TEST_F(ArrayList, cxListCompare) { + ASSERT_EQ(1,0); // TODO: remove when implemented + auto left = arrayListFromTestData(); + auto right = arrayListFromTestData(); + verifyCompare(left, right); +} + +TEST_F(ArrayList, cxListCompareWithPtrList) { + ASSERT_EQ(1,0); // TODO: remove when implemented + auto left = arrayListFromTestData(); + auto right = pointerLinkedListFromTestData(); + verifyCompare(left, right); +} + +TEST_F(ArrayList, cxListCompareWithNormalList) { + ASSERT_EQ(1,0); // TODO: remove when implemented + auto left = arrayListFromTestData(); + auto right = linkedListFromTestData(); + verifyCompare(left, right); +} + TEST_F(PointerLinkedList, NoDestructor) { void *item = cxMalloc(&testingAllocator, sizeof(int)); auto list = cxPointerLinkedListCreate(cxDefaultAllocator, cx_cmp_int);