tests/test_list.c

changeset 876
f4ce7df9cff0
parent 875
ee84ac776cbc
child 883
3012e9b4214e
--- a/tests/test_list.c	Thu Aug 29 21:30:52 2024 +0200
+++ b/tests/test_list.c	Sun Sep 01 14:48:43 2024 +0200
@@ -962,6 +962,7 @@
     cx_list_class const *cl = list->climpl == NULL ? list->cl : list->climpl;
     memcpy(defaulted_cl, cl, sizeof(cx_list_class));
     defaulted_cl->insert_array = cx_list_default_insert_array;
+    defaulted_cl->insert_sorted = cx_list_default_insert_sorted;
     defaulted_cl->sort = cx_list_default_sort;
     defaulted_cl->swap = cx_list_default_swap;
     defaulted_cl->compare = NULL;
@@ -1099,6 +1100,54 @@
     CX_TEST_ASSERT(*(int *) cxListAt(list, 9) == 42);
 })
 
+roll_out_test_combos_with_defaulted_funcs(insert_sorted, {
+    int d1 = 50;
+    int d2 = 80;
+    int d3 = 60;
+    int d4 = 40;
+    int d5 = 70;
+    int d6a[6] = array_init(52, 54, 56, 62, 64, 75);
+    int d7a[6] = array_init(51, 57, 58, 65, 77, 78);
+    int d8 = 90;
+    int *d6ptr[6];
+    int *d7ptr[6];
+    cx_for_n(i, 6)
+    {
+        d6ptr[i] = &d6a[i];
+        d7ptr[i] = &d7a[i];
+    }
+    size_t inserted;
+    int expected[18] = array_init(
+            40, 50, 51, 52, 54, 56, 57, 58, 60,
+            62, 64, 65, 70, 75, 77, 78, 80, 90
+    );
+
+    CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d1));
+    CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d2));
+    CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d3));
+    CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d4));
+    CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d5));
+    if (isptrlist) {
+        inserted = cxListInsertSortedArray(list, d6ptr, 6);
+    } else {
+        inserted = cxListInsertSortedArray(list, d6a, 6);
+    }
+    CX_TEST_ASSERT(inserted == 6);
+    if (isptrlist) {
+        inserted = cxListInsertSortedArray(list, d7ptr, 6);
+    } else {
+        inserted = cxListInsertSortedArray(list, d7a, 6);
+    }
+    CX_TEST_ASSERT(inserted == 6);
+    CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d8));
+
+    CX_TEST_ASSERT(cxListSize(list) == 18);
+    cx_for_n(i, 18)
+    {
+        CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
+    }
+})
+
 roll_out_test_combos(remove, {
     const size_t testdata_len = 32;
     int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
@@ -1499,6 +1548,8 @@
     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_insert_sorted);
+    cx_test_register(suite, test_list_parl_insert_sorted);
     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);
@@ -1542,6 +1593,8 @@
 
     cx_test_register(suite, test_list_arlm_insert_array);
     cx_test_register(suite, test_list_parlm_insert_array);
+    cx_test_register(suite, test_list_arlm_insert_sorted);
+    cx_test_register(suite, test_list_parlm_insert_sorted);
     cx_test_register(suite, test_list_arlm_swap);
     cx_test_register(suite, test_list_parlm_swap);
     cx_test_register(suite, test_list_arlm_sort);
@@ -1589,6 +1642,8 @@
     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_insert_sorted);
+    cx_test_register(suite, test_list_pll_insert_sorted);
     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);
@@ -1632,6 +1687,8 @@
 
     cx_test_register(suite, test_list_llm_insert_array);
     cx_test_register(suite, test_list_pllm_insert_array);
+    cx_test_register(suite, test_list_llm_insert_sorted);
+    cx_test_register(suite, test_list_pllm_insert_sorted);
     cx_test_register(suite, test_list_llm_swap);
     cx_test_register(suite, test_list_pllm_swap);
     cx_test_register(suite, test_list_llm_sort);

mercurial