test/test_list.cpp

changeset 639
309e8b08c60e
parent 638
eafb45eefc51
child 641
d402fead3386
--- a/test/test_list.cpp	Mon Jan 23 20:22:11 2023 +0100
+++ b/test/test_list.cpp	Mon Jan 23 20:34:18 2023 +0100
@@ -169,17 +169,17 @@
     int s;
 
     s = 2;
-    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cx_cmp_int, &s), 0);
+    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 0);
     s = 4;
-    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cx_cmp_int, &s), 1);
+    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 1);
     s = 6;
-    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cx_cmp_int, &s), 2);
+    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 2);
     s = 8;
-    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cx_cmp_int, &s), 3);
+    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 3);
     s = 10;
-    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cx_cmp_int, &s), 4);
+    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 4);
     s = -2;
-    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, false, cx_cmp_int, &s), 4);
+    EXPECT_EQ(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s), 4);
 }
 
 TEST(LinkedList_LowLevel, cx_linked_list_compare) {
@@ -188,11 +188,11 @@
     auto tc = create_nodes_test_data({2, 4, 6, 9});
     auto la = ta.begin, lb = tb.begin, lc = tc.begin;
 
-    EXPECT_GT(cx_linked_list_compare(la, lb, loc_next, loc_data, false, false, cx_cmp_int), 0);
-    EXPECT_LT(cx_linked_list_compare(lb, la, loc_next, loc_data, false, false, cx_cmp_int), 0);
-    EXPECT_GT(cx_linked_list_compare(lc, la, loc_next, loc_data, false, false, cx_cmp_int), 0);
-    EXPECT_LT(cx_linked_list_compare(la, lc, loc_next, loc_data, false, false, cx_cmp_int), 0);
-    EXPECT_EQ(cx_linked_list_compare(la, la, loc_next, loc_data, false, false, cx_cmp_int), 0);
+    EXPECT_GT(cx_linked_list_compare(la, lb, loc_next, loc_data, cx_cmp_int), 0);
+    EXPECT_LT(cx_linked_list_compare(lb, la, loc_next, loc_data, cx_cmp_int), 0);
+    EXPECT_GT(cx_linked_list_compare(lc, la, loc_next, loc_data, cx_cmp_int), 0);
+    EXPECT_LT(cx_linked_list_compare(la, lc, loc_next, loc_data, cx_cmp_int), 0);
+    EXPECT_EQ(cx_linked_list_compare(la, la, loc_next, loc_data, cx_cmp_int), 0);
 }
 
 TEST(LinkedList_LowLevel, cx_linked_list_add) {
@@ -518,8 +518,7 @@
     void *begin = scrambled.begin;
     void *end = cx_linked_list_last(begin, loc_next);
 
-    cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data,
-                        false, cx_cmp_int);
+    cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, cx_cmp_int);
 
     node *check = reinterpret_cast<node *>(begin);
     node *check_last = nullptr;
@@ -547,7 +546,7 @@
     cx_linked_list_reverse(&begin, &end, loc_prev, loc_next);
     EXPECT_EQ(end, orig_begin);
     EXPECT_EQ(begin, orig_end);
-    EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, false, false, cx_cmp_int), 0);
+    EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, cx_cmp_int), 0);
 }
 
 class HighLevelTest : public ::testing::Test {
@@ -574,13 +573,6 @@
         return list;
     }
 
-    auto pointerLinkedListFromTestData() const -> CxList * {
-        auto list = autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int));
-        // note: cannot use cxListAddArray() because we don't have a list of pointers
-        cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]);
-        return list;
-    }
-
     auto arrayListFromTestData() const -> CxList * {
         auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), testdata_len));
         cxListAddArray(list, testdata.data.data(), testdata_len);
@@ -795,9 +787,6 @@
 class LinkedList : public HighLevelTest {
 };
 
-class PointerLinkedList : public HighLevelTest {
-};
-
 class ArrayList : public HighLevelTest {
 };
 
@@ -809,14 +798,6 @@
     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);
-}
-
 TEST_F(ArrayList, cxArrayListCreate) {
     CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
     ASSERT_NE(list, nullptr);
@@ -830,11 +811,6 @@
     verifyAdd(list, false);
 }
 
-TEST_F(PointerLinkedList, cxListAdd) {
-    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int));
-    verifyAdd(list, true);
-}
-
 TEST_F(ArrayList, cxListAdd) {
     CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
     verifyAdd(list, false);
@@ -844,10 +820,6 @@
     verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
 }
 
-TEST_F(PointerLinkedList, cxListInsert) {
-    verifyInsert(autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int)));
-}
-
 TEST_F(ArrayList, cxListInsert) {
     verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2)));
 }
@@ -856,11 +828,6 @@
     verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
 }
 
-TEST_F(PointerLinkedList, cxListInsertArray) {
-    //TODO: this is unfixably broken - solve with issue #234
-    //verifyInsertArray(autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int)));
-}
-
 TEST_F(ArrayList, cxListInsertArray) {
     verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)));
 }
@@ -869,10 +836,6 @@
     verifyRemove(linkedListFromTestData());
 }
 
-TEST_F(PointerLinkedList, cxListRemove) {
-    verifyRemove(pointerLinkedListFromTestData());
-}
-
 TEST_F(ArrayList, cxListRemove) {
     verifyRemove(arrayListFromTestData());
 }
@@ -881,10 +844,6 @@
     verifyAt(linkedListFromTestData());
 }
 
-TEST_F(PointerLinkedList, cxListAt) {
-    verifyAt(pointerLinkedListFromTestData());
-}
-
 TEST_F(ArrayList, cxListAt) {
     verifyAt(arrayListFromTestData());
 }
@@ -893,10 +852,6 @@
     verifyFind(linkedListFromTestData());
 }
 
-TEST_F(PointerLinkedList, cxListFind) {
-    verifyFind(pointerLinkedListFromTestData());
-}
-
 TEST_F(ArrayList, cxListFind) {
     verifyFind(arrayListFromTestData());
 }
@@ -905,10 +860,6 @@
     verifySort(linkedListFromTestData());
 }
 
-TEST_F(PointerLinkedList, cxListSort) {
-    verifySort(pointerLinkedListFromTestData());
-}
-
 TEST_F(ArrayList, cxListSort) {
     verifySort(arrayListFromTestData());
 }
@@ -917,10 +868,6 @@
     verifyIterator(linkedListFromTestData());
 }
 
-TEST_F(PointerLinkedList, Iterator) {
-    verifyIterator(pointerLinkedListFromTestData());
-}
-
 TEST_F(ArrayList, Iterator) {
     verifyIterator(arrayListFromTestData());
 }
@@ -932,14 +879,6 @@
     verifyInsertViaIterator(list);
 }
 
-TEST_F(PointerLinkedList, InsertViaIterator) {
-    int fivenums[] = {0, 1, 2, 3, 4, 5};
-    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cx_cmp_int));
-    // note: don't use cxListAddArray() here, because we don't have a list of pointers
-    cx_for_n (i, 5) cxListAdd(list, &fivenums[i]);
-    verifyInsertViaIterator(list);
-}
-
 TEST_F(ArrayList, InsertViaIterator) {
     int fivenums[] = {0, 1, 2, 3, 4, 5};
     CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4));
@@ -951,10 +890,6 @@
     verifyReverse(linkedListFromTestData());
 }
 
-TEST_F(PointerLinkedList, cxListReverse) {
-    verifyReverse(pointerLinkedListFromTestData());
-}
-
 TEST_F(ArrayList, cxListReverse) {
     verifyReverse(arrayListFromTestData());
 }
@@ -965,83 +900,20 @@
     verifyCompare(left, right);
 }
 
-TEST_F(LinkedList, cxListCompareWithPtrList) {
-    auto left = linkedListFromTestData();
-    auto right = pointerLinkedListFromTestData();
-    verifyCompare(left, right);
-}
-
 TEST_F(LinkedList, cxListCompareWithArrayList) {
     auto left = linkedListFromTestData();
     auto right = arrayListFromTestData();
     verifyCompare(left, right);
 }
 
-TEST_F(PointerLinkedList, cxListCompare) {
-    auto left = pointerLinkedListFromTestData();
-    auto right = pointerLinkedListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(PointerLinkedList, cxListCompareWithNormalList) {
-    auto left = pointerLinkedListFromTestData();
-    auto right = linkedListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(PointerLinkedList, cxListCompareWithArrayList) {
-    auto left = pointerLinkedListFromTestData();
-    auto right = arrayListFromTestData();
-    verifyCompare(left, right);
-}
-
 TEST_F(ArrayList, cxListCompare) {
     auto left = arrayListFromTestData();
     auto right = arrayListFromTestData();
     verifyCompare(left, right);
 }
 
-TEST_F(ArrayList, cxListCompareWithPtrList) {
-    auto left = arrayListFromTestData();
-    auto right = pointerLinkedListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(ArrayList, cxListCompareWithNormalList) {
+TEST_F(ArrayList, cxListCompareWithLinkedList) {
     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);
-    cxListAdd(list, item);
-    ASSERT_FALSE(testingAllocator.verify());
-    cxListDestroy(list);
-    EXPECT_FALSE(testingAllocator.verify());
-    cxFree(&testingAllocator, item);
-    EXPECT_TRUE(testingAllocator.verify());
-}
-
-TEST_F(PointerLinkedList, SimpleDestructor) {
-    int item = 0;
-    auto list = cxPointerLinkedListCreate(cxDefaultAllocator, cx_cmp_int);
-    list->content_destructor_type = CX_DESTRUCTOR_SIMPLE;
-    list->simple_destructor = [](void *elem) { *(int *) elem = 42; };
-    cxListAdd(list, &item);
-    cxListDestroy(list);
-    EXPECT_EQ(item, 42);
-}
-
-TEST_F(PointerLinkedList, AdvancedDestructor) {
-    void *item = cxMalloc(&testingAllocator, sizeof(int));
-    auto list = cxPointerLinkedListCreate(cxDefaultAllocator, cx_cmp_int);
-    list->content_destructor_type = CX_DESTRUCTOR_ADVANCED;
-    list->advanced_destructor.data = &testingAllocator;
-    list->advanced_destructor.func = (cx_destructor_func2) cxFree;
-    cxListAdd(list, item);
-    ASSERT_FALSE(testingAllocator.verify());
-    cxListDestroy(list);
-    EXPECT_TRUE(testingAllocator.verify());
-}

mercurial