complete migration of list tests - fixes #342

Fri, 12 Jan 2024 20:24:29 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Jan 2024 20:24:29 +0100
changeset 803
0711d869ce4d
parent 802
30473af255b4
child 804
5136f2fc32ec

complete migration of list tests - fixes #342

tests/test_list.c file | annotate | diff | comparison | revisions
tests/test_list.cpp file | annotate | diff | comparison | revisions
--- a/tests/test_list.c	Fri Jan 12 20:13:13 2024 +0100
+++ b/tests/test_list.c	Fri Jan 12 20:24:29 2024 +0100
@@ -29,6 +29,7 @@
 #include "cx/test.h"
 #include "util_allocator.h"
 #include "cx/compare.h"
+#include "cx/utils.h"
 
 #include "cx/array_list.h"
 #include "cx/linked_list.h"
@@ -854,6 +855,491 @@
     cx_testing_allocator_destroy(&talloc);
 }
 
+#define set_up_combo \
+    CxTestingAllocator talloc; \
+    cx_testing_allocator_init(&talloc); \
+    CxAllocator *alloc = &talloc.base; \
+    CX_TEST_DO {
+#define tear_down_combo \
+        cxListDestroy(list); \
+        CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));\
+    } \
+    cx_testing_allocator_destroy(&talloc);
+#define roll_out_test_combos(name, body) \
+static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \
+    __attribute__((__unused__)) bool isptrlist, \
+    __attribute__((__unused__)) bool islinkedlist) body \
+CX_TEST(test_list_ll_##name) { \
+    set_up_combo \
+        CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \
+        CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, true); \
+    tear_down_combo \
+} \
+CX_TEST(test_list_arl_##name) { \
+    set_up_combo \
+        CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \
+        CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, false); \
+    tear_down_combo \
+} \
+CX_TEST(test_list_pll_##name) { \
+    set_up_combo \
+        CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \
+        CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, true); \
+    tear_down_combo \
+} \
+CX_TEST(test_list_parl_##name) { \
+    set_up_combo \
+        CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \
+        CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, false); \
+    tear_down_combo \
+}
+#define array_init(...) {__VA_ARGS__}
+
+static inline int *int_test_data_added_to_list(CxList *list, bool isptrlist, size_t len) {
+    int *testdata = int_test_data(len);
+    if (isptrlist) {
+        cx_for_n(i, len) {
+            cxListAdd(list, &testdata[i]);
+        }
+    } else {
+        cxListAddArray(list, testdata, len);
+    }
+    return testdata;
+}
+
+roll_out_test_combos(add, {
+    const size_t len = 250;
+    int *testdata = int_test_data(len);
+    cx_for_n (i, len) CX_TEST_ASSERT(cxListAdd(list, &testdata[i]) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == len);
+    cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]);
+    cx_for_n (i, len) ++testdata[i];
+    if (isptrlist) {
+        cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]);
+    } else {
+        cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i] - 1);
+    }
+    free(testdata);
+})
+
+roll_out_test_combos(insert, {
+    int a = 5;
+    int b = 47;
+    int c = 13;
+    int d = 42;
+    CX_TEST_ASSERT(cxListInsert(list, 1, &a) != 0);
+    CX_TEST_ASSERT(cxListSize(list) == 0);
+    CX_TEST_ASSERT(cxListInsert(list, 0, &a) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == 1);
+    CX_TEST_ASSERT(cxListInsert(list, 0, &b) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == 2);
+    CX_TEST_ASSERT(cxListInsert(list, 1, &c) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == 3);
+    CX_TEST_ASSERT(cxListInsert(list, 3, &d) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == 4);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 47);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 13);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 5);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 42);
+})
+
+roll_out_test_combos(insert_array, {
+    int a[5] = array_init(5, 47, 11, 13, 42);
+    int b[5] = array_init(9, 18, 72, 50, 7);
+    int *aptr[5];
+    int *bptr[5];
+    cx_for_n(i, 5) {
+        aptr[i] = &a[i];
+        bptr[i] = &b[i];
+    }
+
+    size_t inserted;
+
+    if (isptrlist) {
+        inserted = cxListInsertArray(list, 0, aptr, 5);
+    } else {
+        inserted = cxListInsertArray(list, 0, a, 5);
+    }
+    CX_TEST_ASSERT(inserted == 5);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 5);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 47);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 11);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 13);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 4) == 42);
+    if (isptrlist) {
+        inserted = cxListInsertArray(list, 3, bptr, 5);
+    } else {
+        inserted = cxListInsertArray(list, 3, b, 5);
+    }
+    CX_TEST_ASSERT(inserted == 5);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 5);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 47);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 11);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 9);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 4) == 18);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 5) == 72);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 6) == 50);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 7) == 7);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 8) == 13);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 9) == 42);
+})
+
+roll_out_test_combos(remove, {
+    const size_t testdata_len = 32;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
+
+    CX_TEST_ASSERT(cxListRemove(list, 2) == 0);
+    CX_TEST_ASSERT(cxListRemove(list, 4) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == testdata_len - 2);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == testdata[0]);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == testdata[1]);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == testdata[3]);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == testdata[4]);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 4) == testdata[6]);
+    CX_TEST_ASSERT(cxListRemove(list, 0) == 0);
+    CX_TEST_ASSERT(cxListSize(list) == testdata_len - 3);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == testdata[1]);
+    CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == testdata[3]);
+    CX_TEST_ASSERT(cxListRemove(list, testdata_len) != 0);
+    free(testdata);
+})
+
+roll_out_test_combos(find_remove, {
+    const size_t testdata_len = 250;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
+
+    int exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
+    int val = testdata[exp];
+    // randomly picked number could occur earlier in list - find first position
+    for (int i = 0 ; i < exp ; i++) {
+        if (testdata[i] == val) {
+            exp = i;
+            break;
+        }
+    }
+    CX_TEST_ASSERT(cxListSize(list) == testdata_len);
+    CX_TEST_ASSERT(cxListFind(list, &val) == exp);
+    CX_TEST_ASSERT(cxListFindRemove(list, &val) == exp);
+    CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
+    CX_TEST_ASSERT(cxListFind(list, &val) != exp);
+
+    int notinlist = -1;
+    CX_TEST_ASSERT(cxListFindRemove(list, &notinlist) < 0);
+    CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
+
+    free(testdata);
+})
+
+roll_out_test_combos(clear, {
+    int *testdata = int_test_data_added_to_list(list, isptrlist, 8);
+    CX_TEST_ASSERT(cxListSize(list) > 0);
+    cxListClear(list);
+    CX_TEST_ASSERT(cxListSize(list) == 0);
+    free(testdata);
+})
+
+roll_out_test_combos(at, {
+    size_t len = 128;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, 128);
+    CX_TEST_ASSERT(cxListSize(list) == len);
+    cx_for_n (i, len) {
+        CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]);
+    }
+    CX_TEST_ASSERT(cxListAt(list, cxListSize(list)) == NULL);
+    free(testdata);
+})
+
+roll_out_test_combos(swap, {
+    int original[16] = array_init(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+    int swapped[16] = array_init(8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13);
+
+    cx_for_n(i, 16) {
+        cxListAdd(list, &original[i]);
+    }
+
+    CX_TEST_ASSERT(0 == cxListSwap(list, 1, 4));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 2, 14));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 9, 6));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 3, 3));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 10, 11));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 8, 0));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 7, 12));
+    CX_TEST_ASSERT(0 == cxListSwap(list, 13, 15));
+
+    CX_TEST_ASSERT(0 != cxListSwap(list, 5, 16));
+    CX_TEST_ASSERT(0 != cxListSwap(list, 16, 6));
+    CX_TEST_ASSERT(0 != cxListSwap(list, 16, 17));
+
+    CxIterator iter = cxListIterator(list);
+    cx_foreach(int*, e, iter) {
+        CX_TEST_ASSERT(*e == swapped[iter.index]);
+    }
+    iter = cxListBackwardsIterator(list);
+    cx_foreach(int*, e, iter) {
+        CX_TEST_ASSERT(*e == swapped[iter.index]);
+    }
+})
+
+roll_out_test_combos(swap_no_sbo, {
+    if (islinkedlist) {
+        CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
+        CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true);
+        CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
+    } else {
+        // TODO: currently, SBO for swap operation cannot be disabled for array lists
+        CX_TEST_ASSERT(true);
+    }
+})
+
+roll_out_test_combos(find, {
+    const size_t testdata_len = 500;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
+
+    cx_for_n (attempt, 25) {
+        int exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
+        int val = testdata[exp];
+        // randomly picked number could occur earlier in list - find first position
+        for (int i = 0 ; i < exp ; i++) {
+            if (testdata[i] == val) {
+                exp = i;
+                break;
+            }
+        }
+        CX_TEST_ASSERT(cxListFind(list, &val) == exp);
+    }
+
+    int notinlist = -1;
+    CX_TEST_ASSERT(cxListFind(list, &notinlist) < 0);
+
+    free(testdata);
+})
+
+roll_out_test_combos(sort, {
+    const size_t testdata_len = 250;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
+    int *expected = malloc(testdata_len*sizeof(int));
+    memcpy(expected, testdata, testdata_len*sizeof(int));
+    qsort(expected, testdata_len, sizeof(int), cx_cmp_int);
+
+    cxListSort(list);
+    cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
+
+    free(expected);
+    free(testdata);
+})
+
+roll_out_test_combos(reverse, {
+    const size_t testdata_len = 50;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
+    cxListReverse(list);
+    cx_for_n(i, testdata_len) {
+        CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[testdata_len - 1 - i]);
+    }
+    free(testdata);
+})
+
+roll_out_test_combos(iterator, {
+    const size_t len = 50;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, len);
+
+    CxIterator iter = cxListIterator(list);
+    size_t i = 0;
+    cx_foreach(int*, x, iter) {
+        CX_TEST_ASSERT(i == iter.index);
+        CX_TEST_ASSERT(*x == testdata[iter.index]);
+        i++;
+    }
+    CX_TEST_ASSERT(i == cxListSize(list));
+    iter = cxListBackwardsIterator(list);
+    cx_foreach(int*, x, iter) {
+        CX_TEST_ASSERT(i - 1 == iter.index);
+        CX_TEST_ASSERT(*x == testdata[iter.index]);
+        i--;
+    }
+    CX_TEST_ASSERT(i == 0);
+    i = len / 2;
+    CxMutIterator mut_iter = cxListMutIteratorAt(list, i);
+    size_t j = 0;
+    cx_foreach(int*, x, mut_iter) {
+        CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2);
+        CX_TEST_ASSERT(*x == testdata[i]);
+        if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter);
+        i++;
+        j++;
+    }
+    CX_TEST_ASSERT(i == len);
+    i = len / 2;
+    j = 0;
+    mut_iter = cxListMutBackwardsIteratorAt(list, i - 1);
+    cx_foreach(int*, x, mut_iter) {
+        CX_TEST_ASSERT(mut_iter.index == len / 2 - 1 - j);
+        CX_TEST_ASSERT(*x == testdata[i - 1]);
+        if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter);
+        i--;
+        j++;
+    }
+    CX_TEST_ASSERT(i == 0);
+    CX_TEST_ASSERT(cxListSize(list) == len / 2);
+    cx_for_n(k, len / 2) CX_TEST_ASSERT(*(int *) cxListAt(list, k) == testdata[k * 2]);
+
+    free(testdata);
+})
+
+roll_out_test_combos(insert_with_iterator, {
+    int fivenums[] = array_init(0, 1, 2, 3, 4);
+    cx_for_n(i, 5) cxListAdd(list, &fivenums[i]);
+    int newdata[] = array_init(10, 20, 30, 40, 50);
+
+    CxMutIterator iter = cxListMutIteratorAt(list, 2);
+    CX_TEST_ASSERT(cxIteratorValid(iter));
+    CX_TEST_ASSERT(iter.index == 2);
+    CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
+    cxListInsertAfter(&iter, &newdata[0]);
+    CX_TEST_ASSERT(cxIteratorValid(iter));
+    CX_TEST_ASSERT(iter.index == 2);
+    CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
+    cxListInsertBefore(&iter, &newdata[1]);
+    CX_TEST_ASSERT(cxIteratorValid(iter));
+    CX_TEST_ASSERT(iter.index == 3);
+    CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
+
+    iter = cxListMutIterator(list);
+    cxListInsertBefore(&iter, &newdata[2]);
+    CX_TEST_ASSERT(cxIteratorValid(iter));
+    CX_TEST_ASSERT(iter.index == 1);
+    CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 0);
+    iter = cxListMutIteratorAt(list, cxListSize(list));
+    cxListInsertBefore(&iter, &newdata[3]);
+    CX_TEST_ASSERT(!cxIteratorValid(iter));
+    CX_TEST_ASSERT(iter.index == 9);
+    iter = cxListMutIteratorAt(list, cxListSize(list));
+    cxListInsertAfter(&iter, &newdata[4]);
+    CX_TEST_ASSERT(!cxIteratorValid(iter));
+    CX_TEST_ASSERT(iter.index == 10);
+
+    int expdata[] = array_init(30, 0, 1, 20, 2, 10, 3, 4, 40, 50);
+    cx_for_n (j, 10) CX_TEST_ASSERT(*(int *) cxListAt(list, j) == expdata[j]);
+})
+
+static CX_TEST_SUBROUTINE(test_list_verify_compare, CxList *left, CxList *right) {
+    CX_TEST_ASSERTM(cxListCompare(left, right) == 0, "lists don't start identical");
+    int x = 42;
+    cxListAdd(left, &x);
+    CX_TEST_ASSERT(cxListSize(left) > cxListSize(right));
+    CX_TEST_ASSERT(cxListCompare(left, right) > 0);
+    CX_TEST_ASSERT(cxListCompare(right, left) < 0);
+    cxListAdd(right, &x);
+    CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
+    CX_TEST_ASSERT(cxListCompare(left, right) == 0);
+    int a = 5, b = 10;
+    cxListInsert(left, 15, &a);
+    cxListInsert(right, 15, &b);
+    CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
+    CX_TEST_ASSERT(cxListCompare(left, right) < 0);
+    CX_TEST_ASSERT(cxListCompare(right, left) > 0);
+    *(int *) cxListAt(left, 15) = 10;
+    CX_TEST_ASSERT(cxListCompare(left, right) == 0);
+}
+
+#define roll_out_compare_tests(suffix, otherctr) \
+roll_out_test_combos(compare_##suffix, { \
+    const size_t len = 47; \
+    int *testdata = int_test_data_added_to_list(list, isptrlist, len); \
+    CxList *other = otherctr; \
+    cx_for_n(i, len) cxListAdd(other, &testdata[i]); \
+    CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); \
+    cxListDestroy(other); \
+    free(testdata); \
+})
+
+roll_out_compare_tests(
+        ll, cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int))
+)
+
+roll_out_compare_tests(
+        pll, cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS)
+)
+
+roll_out_compare_tests(
+        arl, cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 50)
+)
+
+roll_out_compare_tests(
+        parl, cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 50)
+)
+
+static unsigned destr_test_ctr;
+static int destr_last_value;
+
+static void simple_destr_test_fun(void *data) {
+    int *ptr = data;
+    destr_last_value = *ptr;
+    *ptr = destr_last_value + 1;
+    destr_test_ctr++;
+}
+
+static void advanced_destr_test_fun(__attribute__((__unused__)) void *u, void *data) {
+    simple_destr_test_fun(data);
+}
+
+static CX_TEST_SUBROUTINE(test_list_verify_destructor, CxList *list,
+                          int const *testdata, size_t testdata_len) {
+    destr_test_ctr = 0;
+    
+    int off = cxListIsStoringPointers(list) ? 1 : 0;
+
+    cxListRemove(list, 15);
+    CX_TEST_ASSERT(1 == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[15] == destr_last_value + off);
+    CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
+    cxListRemove(list, 47);
+    CX_TEST_ASSERT(2 == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[48] == destr_last_value + off);
+    CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
+
+    CxMutIterator iter = cxListMutIteratorAt(list, 7);
+    cxIteratorNext(iter);
+    CX_TEST_ASSERT(2 == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[48] == destr_last_value + off);
+    CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
+    cxIteratorFlagRemoval(iter);
+    cxIteratorNext(iter);
+    CX_TEST_ASSERT(3 == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[8] == destr_last_value + off);
+    CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
+
+    iter = cxListMutBackwardsIteratorAt(list, 5);
+    cxIteratorNext(iter);
+    CX_TEST_ASSERT(3 == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[8] == destr_last_value + off);
+    CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
+    cxIteratorFlagRemoval(iter);
+    cxIteratorNext(iter);
+    CX_TEST_ASSERT(4 == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[4] == destr_last_value + off);
+    CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
+
+    cxListClear(list);
+    CX_TEST_ASSERT(testdata_len == destr_test_ctr);
+    CX_TEST_ASSERT(testdata[testdata_len - 1] == destr_last_value + off);
+}
+
+roll_out_test_combos(simple_destr, {
+    const size_t len = 60;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, len);
+    list->simple_destructor = simple_destr_test_fun;
+    CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len);
+    free(testdata);
+})
+
+roll_out_test_combos(advanced_destr, {
+    const size_t len = 75;
+    int *testdata = int_test_data_added_to_list(list, isptrlist, len);
+    list->advanced_destructor = advanced_destr_test_fun;
+    CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len);
+    free(testdata);
+})
+
 CxTestSuite *cx_test_suite_array_list(void) {
     CxTestSuite *suite = cx_test_suite_new("array_list");
 
@@ -864,6 +1350,47 @@
     cx_test_register(suite, test_list_parl_destroy_simple_destr);
     cx_test_register(suite, test_list_parl_destroy_adv_destr);
 
+    cx_test_register(suite, test_list_arl_add);
+    cx_test_register(suite, test_list_parl_add);
+    cx_test_register(suite, test_list_arl_insert);
+    cx_test_register(suite, test_list_parl_insert);
+    cx_test_register(suite, test_list_arl_insert_array);
+    cx_test_register(suite, test_list_parl_insert_array);
+    cx_test_register(suite, test_list_arl_remove);
+    cx_test_register(suite, test_list_parl_remove);
+    cx_test_register(suite, test_list_arl_find_remove);
+    cx_test_register(suite, test_list_parl_find_remove);
+    cx_test_register(suite, test_list_arl_clear);
+    cx_test_register(suite, test_list_parl_clear);
+    cx_test_register(suite, test_list_arl_at);
+    cx_test_register(suite, test_list_parl_at);
+    cx_test_register(suite, test_list_arl_swap);
+    cx_test_register(suite, test_list_parl_swap);
+    cx_test_register(suite, test_list_arl_swap_no_sbo);
+    cx_test_register(suite, test_list_parl_swap_no_sbo);
+    cx_test_register(suite, test_list_arl_find);
+    cx_test_register(suite, test_list_parl_find);
+    cx_test_register(suite, test_list_arl_sort);
+    cx_test_register(suite, test_list_parl_sort);
+    cx_test_register(suite, test_list_arl_reverse);
+    cx_test_register(suite, test_list_parl_reverse);
+    cx_test_register(suite, test_list_arl_iterator);
+    cx_test_register(suite, test_list_parl_iterator);
+    cx_test_register(suite, test_list_arl_insert_with_iterator);
+    cx_test_register(suite, test_list_parl_insert_with_iterator);
+    cx_test_register(suite, test_list_arl_compare_ll);
+    cx_test_register(suite, test_list_arl_compare_arl);
+    cx_test_register(suite, test_list_arl_compare_pll);
+    cx_test_register(suite, test_list_arl_compare_parl);
+    cx_test_register(suite, test_list_parl_compare_ll);
+    cx_test_register(suite, test_list_parl_compare_arl);
+    cx_test_register(suite, test_list_parl_compare_pll);
+    cx_test_register(suite, test_list_parl_compare_parl);
+    cx_test_register(suite, test_list_arl_simple_destr);
+    cx_test_register(suite, test_list_parl_simple_destr);
+    cx_test_register(suite, test_list_arl_advanced_destr);
+    cx_test_register(suite, test_list_parl_advanced_destr);
+
     return suite;
 }
 
@@ -895,6 +1422,47 @@
     cx_test_register(suite, test_list_pll_destroy_simple_destr);
     cx_test_register(suite, test_list_pll_destroy_adv_destr);
 
+    cx_test_register(suite, test_list_ll_add);
+    cx_test_register(suite, test_list_pll_add);
+    cx_test_register(suite, test_list_ll_insert);
+    cx_test_register(suite, test_list_pll_insert);
+    cx_test_register(suite, test_list_ll_insert_array);
+    cx_test_register(suite, test_list_pll_insert_array);
+    cx_test_register(suite, test_list_ll_remove);
+    cx_test_register(suite, test_list_pll_remove);
+    cx_test_register(suite, test_list_ll_find_remove);
+    cx_test_register(suite, test_list_pll_find_remove);
+    cx_test_register(suite, test_list_ll_clear);
+    cx_test_register(suite, test_list_pll_clear);
+    cx_test_register(suite, test_list_ll_at);
+    cx_test_register(suite, test_list_pll_at);
+    cx_test_register(suite, test_list_ll_swap);
+    cx_test_register(suite, test_list_pll_swap);
+    cx_test_register(suite, test_list_ll_swap_no_sbo);
+    cx_test_register(suite, test_list_pll_swap_no_sbo);
+    cx_test_register(suite, test_list_ll_find);
+    cx_test_register(suite, test_list_pll_find);
+    cx_test_register(suite, test_list_ll_sort);
+    cx_test_register(suite, test_list_pll_sort);
+    cx_test_register(suite, test_list_ll_reverse);
+    cx_test_register(suite, test_list_pll_reverse);
+    cx_test_register(suite, test_list_ll_iterator);
+    cx_test_register(suite, test_list_pll_iterator);
+    cx_test_register(suite, test_list_ll_insert_with_iterator);
+    cx_test_register(suite, test_list_pll_insert_with_iterator);
+    cx_test_register(suite, test_list_ll_compare_ll);
+    cx_test_register(suite, test_list_ll_compare_arl);
+    cx_test_register(suite, test_list_ll_compare_pll);
+    cx_test_register(suite, test_list_ll_compare_parl);
+    cx_test_register(suite, test_list_pll_compare_ll);
+    cx_test_register(suite, test_list_pll_compare_arl);
+    cx_test_register(suite, test_list_pll_compare_pll);
+    cx_test_register(suite, test_list_pll_compare_parl);
+    cx_test_register(suite, test_list_ll_simple_destr);
+    cx_test_register(suite, test_list_pll_simple_destr);
+    cx_test_register(suite, test_list_ll_advanced_destr);
+    cx_test_register(suite, test_list_pll_advanced_destr);
+
     return suite;
 }
 
--- a/tests/test_list.cpp	Fri Jan 12 20:13:13 2024 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,852 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "cx/linked_list.h"
-#include "cx/array_list.h"
-#include "cx/utils.h"
-#include "cx/compare.h"
-#include "util_allocator.h"
-
-#include <gtest/gtest.h>
-#include <array>
-#include <vector>
-#include <unordered_set>
-#include <algorithm>
-
-
-class HighLevelTest : public ::testing::Test {
-    mutable std::unordered_set<CxList *> lists;
-protected:
-    CxTestingAllocator testingAllocator;
-
-    void TearDown() override {
-        for (auto &&l: lists) cxListDestroy(l);
-        CX_TEST_ASSERT(testingAllocator.verify());
-    }
-
-    static constexpr size_t testdata_len = 250;
-    int_test_data<testdata_len> testdata;
-
-    auto autofree(CxList *list) const -> CxList * {
-        if (list != NULL) lists.insert(list);
-        return list;
-    }
-
-    auto linkedListFromTestData() const -> CxList * {
-        auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
-        cxListAddArray(list, testdata.data.data(), testdata_len);
-        return list;
-    }
-
-    auto pointerLinkedListFromTestData() const -> CxList * {
-        auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
-        // 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);
-        return list;
-    }
-
-    auto pointerArrayListFromTestData() const -> CxList * {
-        auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 256));
-        // 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;
-    }
-
-    void verifyAdd(
-            CxList *list,
-            bool as_pointer
-    ) {
-        auto len = testdata_len;
-        cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0);
-        CX_TEST_ASSERT(cxListSize(list) == len);
-        cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
-        cx_for_n (i, len) ++testdata.data[i];
-        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);
-        }
-    }
-
-    static void verifyInsert(CxList *list) {
-        int a = 5, b = 47, c = 13, d = 42;
-
-        EXPECT_NE(cxListInsert(list, 1, &a), 0);
-        EXPECT_EQ(cxListSize(list), 0);
-        EXPECT_EQ(cxListInsert(list, 0, &a), 0);
-        EXPECT_EQ(cxListSize(list), 1);
-        EXPECT_EQ(cxListInsert(list, 0, &b), 0);
-        EXPECT_EQ(cxListSize(list), 2);
-        EXPECT_EQ(cxListInsert(list, 1, &c), 0);
-        EXPECT_EQ(cxListSize(list), 3);
-        EXPECT_EQ(cxListInsert(list, 3, &d), 0);
-
-        CX_TEST_ASSERT(cxListSize(list) == 4);
-
-        EXPECT_EQ(*(int *) cxListAt(list, 0), 47);
-        EXPECT_EQ(*(int *) cxListAt(list, 1), 13);
-        EXPECT_EQ(*(int *) cxListAt(list, 2), 5);
-        EXPECT_EQ(*(int *) cxListAt(list, 3), 42);
-    }
-
-    static void verifyInsertArray(
-            CxList *list,
-            bool pointers = false
-    ) {
-        int a[5] = {5, 47, 11, 13, 42};
-        int b[5] = {9, 18, 72, 50, 7};
-        int *aptr[5];
-        int *bptr[5];
-        cx_for_n(i, 5) {
-            aptr[i] = &a[i];
-            bptr[i] = &b[i];
-        }
-
-        size_t inserted;
-
-        if (pointers) {
-            inserted = cxListInsertArray(list, 0, aptr, 5);
-        } else {
-            inserted = cxListInsertArray(list, 0, a, 5);
-        }
-        CX_TEST_ASSERT(inserted == 5);
-        EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
-        EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
-        EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
-        EXPECT_EQ(*(int *) cxListAt(list, 3), 13);
-        EXPECT_EQ(*(int *) cxListAt(list, 4), 42);
-        if (pointers) {
-            inserted = cxListInsertArray(list, 3, bptr, 5);
-        } else {
-            inserted = cxListInsertArray(list, 3, b, 5);
-        }
-        CX_TEST_ASSERT(inserted == 5);
-        EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
-        EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
-        EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
-        EXPECT_EQ(*(int *) cxListAt(list, 3), 9);
-        EXPECT_EQ(*(int *) cxListAt(list, 4), 18);
-        EXPECT_EQ(*(int *) cxListAt(list, 5), 72);
-        EXPECT_EQ(*(int *) cxListAt(list, 6), 50);
-        EXPECT_EQ(*(int *) cxListAt(list, 7), 7);
-        EXPECT_EQ(*(int *) cxListAt(list, 8), 13);
-        EXPECT_EQ(*(int *) cxListAt(list, 9), 42);
-    }
-
-    void verifyRemove(CxList *list) const {
-        EXPECT_EQ(cxListRemove(list, 2), 0);
-        EXPECT_EQ(cxListRemove(list, 4), 0);
-        EXPECT_EQ(cxListSize(list), testdata_len - 2);
-        EXPECT_EQ(*(int *) cxListAt(list, 0), testdata.data[0]);
-        EXPECT_EQ(*(int *) cxListAt(list, 1), testdata.data[1]);
-        EXPECT_EQ(*(int *) cxListAt(list, 2), testdata.data[3]);
-        EXPECT_EQ(*(int *) cxListAt(list, 3), testdata.data[4]);
-        EXPECT_EQ(*(int *) cxListAt(list, 4), testdata.data[6]);
-
-        EXPECT_EQ(cxListRemove(list, 0), 0);
-        EXPECT_EQ(cxListSize(list), testdata_len - 3);
-        EXPECT_EQ(*(int *) cxListAt(list, 0), testdata.data[1]);
-        EXPECT_EQ(*(int *) cxListAt(list, 1), testdata.data[3]);
-
-        EXPECT_NE(cxListRemove(list, testdata_len), 0);
-    }
-
-    void verifyFindRemove(CxList *list) const {
-        size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
-        int val = testdata.data[exp];
-        // randomly picked number could occur earlier in list - find first position
-        cx_for_n (i, exp) {
-            if (testdata.data[i] == val) {
-                exp = i;
-                break;
-            }
-        }
-        EXPECT_EQ(cxListSize(list), testdata_len);
-        EXPECT_EQ(cxListFind(list, &val), exp);
-        EXPECT_EQ(cxListFindRemove(list, &val), exp);
-        EXPECT_EQ(cxListSize(list), testdata_len - 1);
-        EXPECT_NE(cxListFind(list, &val), exp);
-
-        int notinlist = -1;
-        EXPECT_LT(cxListFindRemove(list, &notinlist), 0);
-        EXPECT_EQ(cxListSize(list), testdata_len - 1);
-    }
-
-    static void verifyClear(CxList *list) {
-        cxListClear(list);
-        EXPECT_EQ(0, cxListSize(list));
-    }
-
-    static unsigned destr_test_ctr;
-    static int destr_last_value;
-
-    static void simple_destr_test_fun(void *data) {
-        auto ptr = (int *) data;
-        destr_last_value = *ptr;
-        *ptr = destr_last_value + 1;
-        destr_test_ctr++;
-    }
-
-    static void advanced_destr_test_fun(
-            [[maybe_unused]] void *u,
-            void *data
-    ) {
-        simple_destr_test_fun(data);
-    }
-
-    void verifyAnyDestructor(CxList *list) {
-        int off = cxListIsStoringPointers(list) ? 1 : 0;
-
-        cxListRemove(list, 15);
-        EXPECT_EQ(1, destr_test_ctr);
-        EXPECT_EQ(testdata.data[15], destr_last_value + off);
-        EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list));
-        cxListRemove(list, 47);
-        EXPECT_EQ(2, destr_test_ctr);
-        EXPECT_EQ(testdata.data[48], destr_last_value + off);
-        EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list));
-
-        auto iter = cxListMutIteratorAt(list, 7);
-        cxIteratorNext(iter);
-        EXPECT_EQ(2, destr_test_ctr);
-        EXPECT_EQ(testdata.data[48], destr_last_value + off);
-        EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list));
-        cxIteratorFlagRemoval(iter);
-        cxIteratorNext(iter);
-        EXPECT_EQ(3, destr_test_ctr);
-        EXPECT_EQ(testdata.data[8], destr_last_value + off);
-        EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list));
-
-        iter = cxListMutBackwardsIteratorAt(list, 5);
-        cxIteratorNext(iter);
-        EXPECT_EQ(3, destr_test_ctr);
-        EXPECT_EQ(testdata.data[8], destr_last_value + off);
-        EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list));
-        cxIteratorFlagRemoval(iter);
-        cxIteratorNext(iter);
-        EXPECT_EQ(4, destr_test_ctr);
-        EXPECT_EQ(testdata.data[4], destr_last_value + off);
-        EXPECT_EQ(testdata_len - destr_test_ctr, cxListSize(list));
-
-        cxListClear(list);
-        EXPECT_EQ(testdata_len, destr_test_ctr);
-        EXPECT_EQ(testdata.data[testdata_len - 1], destr_last_value + off);
-    }
-
-    void verifySimpleDestructor(CxList *list) {
-        destr_test_ctr = 0;
-        list->simple_destructor = simple_destr_test_fun;
-        verifyAnyDestructor(list);
-    }
-
-    void verifyAdvancedDestructor(CxList *list) {
-        destr_test_ctr = 0;
-        list->advanced_destructor = advanced_destr_test_fun;
-        verifyAnyDestructor(list);
-    }
-
-    static void verifySwap(CxList *list) {
-        CX_TEST_ASSERT(cxListSize(list) == 0);
-
-        int original[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
-        int swapped[16] = {8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13};
-
-        // we have to add the items one by one, because it could be a pointer list
-        cx_for_n(i, 16) {
-            cxListAdd(list, &original[i]);
-        }
-
-        int result;
-
-        // execute the test two times with different item sizes
-        result = cxListSwap(list, 1, 4);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 2, 14);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 9, 6);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 3, 3);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 10, 11);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 8, 0);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 7, 12);
-        EXPECT_EQ(0, result);
-        result = cxListSwap(list, 13, 15);
-        EXPECT_EQ(0, result);
-
-        result = cxListSwap(list, 5, 16);
-        CX_TEST_ASSERT(0 != result);
-        result = cxListSwap(list, 16, 6);
-        CX_TEST_ASSERT(0 != result);
-        result = cxListSwap(list, 16, 17);
-        CX_TEST_ASSERT(0 != result);
-
-        auto iter = cxListIterator(list);
-        cx_foreach(int*, e, iter) {
-            EXPECT_EQ(*e, swapped[iter.index]);
-        }
-        iter = cxListBackwardsIterator(list);
-        cx_foreach(int*, e, iter) {
-            EXPECT_EQ(*e, swapped[iter.index]);
-        }
-    }
-
-    void verifyAt(CxList *list) const {
-        auto len = testdata_len;
-        EXPECT_EQ(cxListSize(list), len);
-        cx_for_n (i, len) {
-            EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
-        }
-        EXPECT_EQ(cxListAt(list, cxListSize(list)), NULL);
-    }
-
-    void verifyFind(CxList *list) const {
-        cx_for_n (attempt, 25) {
-            size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
-            int val = testdata.data[exp];
-            // randomly picked number could occur earlier in list - find first position
-            cx_for_n (i, exp) {
-                if (testdata.data[i] == val) {
-                    exp = i;
-                    break;
-                }
-            }
-            EXPECT_EQ(cxListFind(list, &val), exp);
-        }
-
-        int notinlist = -1;
-        EXPECT_LT(cxListFind(list, &notinlist), 0);
-    }
-
-    void verifySort(CxList *list) const {
-        std::array<int, testdata_len> expected{};
-        std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), expected.begin(), expected.end());
-        cxListSort(list);
-        cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
-    }
-
-    void verifyIterator(CxList *list) const {
-        auto iter = cxListIterator(list);
-        size_t i = 0;
-        cx_foreach(int*, x, iter) {
-            CX_TEST_ASSERT(i == iter.index);
-            EXPECT_EQ(*x, testdata.data[iter.index]);
-            i++;
-        }
-        CX_TEST_ASSERT(i == cxListSize(list));
-        iter = cxListBackwardsIterator(list);
-        cx_foreach(int*, x, iter) {
-            CX_TEST_ASSERT(i - 1 == iter.index);
-            EXPECT_EQ(*x, testdata.data[iter.index]);
-            i--;
-        }
-        CX_TEST_ASSERT(i == 0);
-        auto len = testdata_len;
-        i = len / 2;
-        auto mut_iter = cxListMutIteratorAt(list, i);
-        size_t j = 0;
-        cx_foreach(int*, x, mut_iter) {
-            CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2);
-            CX_TEST_ASSERT(*x == testdata.data[i]);
-            if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter);
-            i++;
-            j++;
-        }
-        CX_TEST_ASSERT(i == len);
-        i = len / 2;
-        j = 0;
-        mut_iter = cxListMutBackwardsIteratorAt(list, i - 1);
-        cx_foreach(int*, x, mut_iter) {
-            CX_TEST_ASSERT(mut_iter.index == len / 2 - 1 - j);
-            CX_TEST_ASSERT(*x == testdata.data[i - 1]);
-            if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter);
-            i--;
-            j++;
-        }
-        CX_TEST_ASSERT(i == 0);
-        CX_TEST_ASSERT(cxListSize(list) == len / 2);
-        cx_for_n(j, len / 2) ASSERT_EQ(*(int *) cxListAt(list, j), testdata.data[j * 2]);
-    }
-
-    static void verifyInsertViaIterator(CxList *list) {
-        int newdata[] = {10, 20, 30, 40, 50};
-
-        auto iter = cxListMutIteratorAt(list, 2);
-        CX_TEST_ASSERT(cxIteratorValid(iter));
-        EXPECT_EQ(iter.index, 2);
-        EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
-        cxListInsertAfter(&iter, &newdata[0]);
-        CX_TEST_ASSERT(cxIteratorValid(iter));
-        EXPECT_EQ(iter.index, 2);
-        EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
-        cxListInsertBefore(&iter, &newdata[1]);
-        CX_TEST_ASSERT(cxIteratorValid(iter));
-        EXPECT_EQ(iter.index, 3);
-        EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
-
-        iter = cxListMutIterator(list);
-        cxListInsertBefore(&iter, &newdata[2]);
-        CX_TEST_ASSERT(cxIteratorValid(iter));
-        EXPECT_EQ(iter.index, 1);
-        EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0);
-        iter = cxListMutIteratorAt(list, cxListSize(list));
-        cxListInsertBefore(&iter, &newdata[3]);
-        CX_TEST_ASSERT(!cxIteratorValid(iter));
-        EXPECT_EQ(iter.index, 9);
-        iter = cxListMutIteratorAt(list, cxListSize(list));
-        cxListInsertAfter(&iter, &newdata[4]);
-        CX_TEST_ASSERT(!cxIteratorValid(iter));
-        EXPECT_EQ(iter.index, 10);
-
-        int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
-        cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]);
-    }
-
-    void verifyReverse(CxList *list) const {
-        cxListReverse(list);
-        cx_for_n(i, testdata_len) {
-            ASSERT_EQ(*(int *) cxListAt(list, i), testdata.data[testdata_len - 1 - i]);
-        }
-    }
-
-    static void verifyCompare(
-            CxList *left,
-            CxList *right
-    ) {
-        EXPECT_EQ(cxListCompare(left, right), 0);
-        int x = 42;
-        cxListAdd(left, &x);
-        ASSERT_GT(cxListSize(left), cxListSize(right));
-        EXPECT_GT(cxListCompare(left, right), 0);
-        EXPECT_LT(cxListCompare(right, left), 0);
-        cxListAdd(right, &x);
-        CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
-        EXPECT_EQ(cxListCompare(left, right), 0);
-        int a = 5, b = 10;
-        cxListInsert(left, 15, &a);
-        cxListInsert(right, 15, &b);
-        CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
-        EXPECT_LT(cxListCompare(left, right), 0);
-        EXPECT_GT(cxListCompare(right, left), 0);
-        *(int *) cxListAt(left, 15) = 10;
-        EXPECT_EQ(cxListCompare(left, right), 0);
-    }
-};
-
-unsigned HighLevelTest::destr_test_ctr = 0;
-int HighLevelTest::destr_last_value = 0;
-
-class LinkedList : public HighLevelTest {
-};
-
-class PointerLinkedList : public HighLevelTest {
-};
-
-class ArrayList : public HighLevelTest {
-};
-
-class PointerArrayList : public HighLevelTest {
-};
-
-
-TEST_F(LinkedList, cxListAdd) {
-    auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
-    verifyAdd(list, false);
-}
-
-TEST_F(PointerLinkedList, cxListAdd) {
-    auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
-    verifyAdd(list, true);
-}
-
-TEST_F(ArrayList, cxListAdd) {
-    auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
-    verifyAdd(list, false);
-}
-
-TEST_F(PointerArrayList, cxListAdd) {
-    auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 8));
-    verifyAdd(list, true);
-}
-
-TEST_F(LinkedList, cxListInsert) {
-    verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
-}
-
-TEST_F(PointerLinkedList, cxListInsert) {
-    verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)));
-}
-
-TEST_F(ArrayList, cxListInsert) {
-    verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2)));
-}
-
-TEST_F(PointerArrayList, cxListInsert) {
-    verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 2)));
-}
-
-TEST_F(LinkedList, cxListInsertArray) {
-    verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
-}
-
-TEST_F(PointerLinkedList, cxListInsertArray) {
-    verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)), true);
-}
-
-TEST_F(ArrayList, cxListInsertArray) {
-    verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)));
-}
-
-TEST_F(PointerArrayList, cxListInsertArray) {
-    verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 4)), true);
-}
-
-TEST_F(LinkedList, cxListRemove) {
-    verifyRemove(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListRemove) {
-    verifyRemove(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListRemove) {
-    verifyRemove(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListRemove) {
-    verifyRemove(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, cxListFindRemove) {
-    verifyFindRemove(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListFindRemove) {
-    verifyFindRemove(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListFindRemove) {
-    verifyFindRemove(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListFindRemove) {
-    verifyFindRemove(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, cxListClear) {
-    verifyClear(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListClear) {
-    verifyClear(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListClear) {
-    verifyClear(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListClear) {
-    verifyClear(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, cxListSwap) {
-    verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
-}
-
-TEST_F(PointerLinkedList, cxListSwap) {
-    verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)));
-}
-
-TEST_F(ArrayList, cxListSwap) {
-    verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 16)));
-}
-
-TEST_F(PointerArrayList, cxListSwap) {
-    verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 16)));
-}
-
-TEST_F(LinkedList, cxListSwapNoSBO) {
-    CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
-    verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))));
-    CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
-}
-
-TEST_F(PointerLinkedList, cxListSwapNoSBO) {
-    CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
-    verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS)));
-    CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
-}
-
-TEST_F(LinkedList, cxListAt) {
-    verifyAt(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListAt) {
-    verifyAt(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListAt) {
-    verifyAt(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListAt) {
-    verifyAt(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, cxListFind) {
-    verifyFind(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListFind) {
-    verifyFind(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListFind) {
-    verifyFind(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListFind) {
-    verifyFind(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, cxListSort) {
-    verifySort(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListSort) {
-    verifySort(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListSort) {
-    verifySort(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListSort) {
-    verifySort(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, Iterator) {
-    verifyIterator(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, Iterator) {
-    verifyIterator(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, Iterator) {
-    verifyIterator(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, Iterator) {
-    verifyIterator(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, InsertViaIterator) {
-    int fivenums[] = {0, 1, 2, 3, 4, 5};
-    CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
-    cxListAddArray(list, fivenums, 5);
-    verifyInsertViaIterator(list);
-}
-
-TEST_F(PointerLinkedList, InsertViaIterator) {
-    int fivenums[] = {0, 1, 2, 3, 4, 5};
-    auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS));
-    // note: cannot use cxListAddArray() 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};
-    auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4));
-    cxListAddArray(list, fivenums, 5);
-    verifyInsertViaIterator(list);
-}
-
-TEST_F(PointerArrayList, InsertViaIterator) {
-    int fivenums[] = {0, 1, 2, 3, 4, 5};
-    auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 4));
-    // note: cannot use cxListAddArray() because we don't have a list of pointers
-    cx_for_n(i, 5) cxListAdd(list, &fivenums[i]);
-    verifyInsertViaIterator(list);
-}
-
-TEST_F(LinkedList, cxListReverse) {
-    verifyReverse(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, cxListReverse) {
-    verifyReverse(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, cxListReverse) {
-    verifyReverse(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, cxListReverse) {
-    verifyReverse(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, cxListCompare) {
-    auto left = linkedListFromTestData();
-    auto right = linkedListFromTestData();
-    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(LinkedList, cxListCompareWithPtrArrayList) {
-    auto left = linkedListFromTestData();
-    auto right = pointerArrayListFromTestData();
-    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(PointerLinkedList, cxListCompareWithPtrArrayList) {
-    auto left = pointerLinkedListFromTestData();
-    auto right = pointerArrayListFromTestData();
-    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) {
-    auto left = arrayListFromTestData();
-    auto right = linkedListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(ArrayList, cxListCompareWithPtrArrayList) {
-    auto left = arrayListFromTestData();
-    auto right = pointerArrayListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(PointerArrayList, cxListCompare) {
-    auto left = pointerArrayListFromTestData();
-    auto right = pointerArrayListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(PointerArrayList, cxListCompareWithPtrList) {
-    auto left = pointerArrayListFromTestData();
-    auto right = pointerLinkedListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(PointerArrayList, cxListCompareWithNormalList) {
-    auto left = pointerArrayListFromTestData();
-    auto right = linkedListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(PointerArrayList, cxListCompareWithNormalArrayList) {
-    auto left = pointerArrayListFromTestData();
-    auto right = arrayListFromTestData();
-    verifyCompare(left, right);
-}
-
-TEST_F(LinkedList, SimpleDestructor) {
-    verifySimpleDestructor(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, SimpleDestructor) {
-    verifySimpleDestructor(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, SimpleDestructor) {
-    verifySimpleDestructor(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, SimpleDestructor) {
-    verifySimpleDestructor(pointerArrayListFromTestData());
-}
-
-TEST_F(LinkedList, AdvancedDestructor) {
-    verifyAdvancedDestructor(linkedListFromTestData());
-}
-
-TEST_F(PointerLinkedList, AdvancedDestructor) {
-    verifyAdvancedDestructor(pointerLinkedListFromTestData());
-}
-
-TEST_F(ArrayList, AdvancedDestructor) {
-    verifyAdvancedDestructor(arrayListFromTestData());
-}
-
-TEST_F(PointerArrayList, AdvancedDestructor) {
-    verifyAdvancedDestructor(pointerArrayListFromTestData());
-}
-
-
-

mercurial