diff -r e3bb67b72d33 -r 68ff0839bc6a tests/test_list.c --- a/tests/test_list.c Mon Jan 27 20:27:39 2025 +0100 +++ b/tests/test_list.c Tue Jan 28 18:27:46 2025 +0100 @@ -1567,6 +1567,34 @@ free(testdata); }) +roll_out_test_combos(find_remove_sorted, { + const size_t testdata_len = 250; + int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len); + qsort(testdata, testdata_len, sizeof(int), cx_cmp_int); + cxListSort(list); + + unsigned exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp) + int val = testdata[exp]; + // randomly picked number could occur earlier in list - find first position + for (unsigned 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, ¬inlist) == cxListSize(list)); + 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); @@ -1935,6 +1963,8 @@ cx_test_register(suite, test_list_parl_remove_array); 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_find_remove_sorted); + cx_test_register(suite, test_list_parl_find_remove_sorted); cx_test_register(suite, test_list_arl_clear); cx_test_register(suite, test_list_parl_clear); cx_test_register(suite, test_list_arl_at); @@ -2032,6 +2062,8 @@ cx_test_register(suite, test_list_pll_remove_array); 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_find_remove_sorted); + cx_test_register(suite, test_list_pll_find_remove_sorted); cx_test_register(suite, test_list_ll_clear); cx_test_register(suite, test_list_pll_clear); cx_test_register(suite, test_list_ll_at);