tests/test_list.c

changeset 1163
68ff0839bc6a
parent 1162
e3bb67b72d33
equal deleted inserted replaced
1162:e3bb67b72d33 1163:68ff0839bc6a
1565 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1); 1565 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
1566 1566
1567 free(testdata); 1567 free(testdata);
1568 }) 1568 })
1569 1569
1570 roll_out_test_combos(find_remove_sorted, {
1571 const size_t testdata_len = 250;
1572 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1573 qsort(testdata, testdata_len, sizeof(int), cx_cmp_int);
1574 cxListSort(list);
1575
1576 unsigned exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
1577 int val = testdata[exp];
1578 // randomly picked number could occur earlier in list - find first position
1579 for (unsigned i = 0 ; i < exp ; i++) {
1580 if (testdata[i] == val) {
1581 exp = i;
1582 break;
1583 }
1584 }
1585 CX_TEST_ASSERT(cxListSize(list) == testdata_len);
1586 CX_TEST_ASSERT(cxListFind(list, &val) == exp);
1587 CX_TEST_ASSERT(cxListFindRemove(list, &val) == exp);
1588 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
1589 CX_TEST_ASSERT(cxListFind(list, &val) != exp);
1590
1591 int notinlist = -1;
1592 CX_TEST_ASSERT(cxListFindRemove(list, &notinlist) == cxListSize(list));
1593 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
1594
1595 free(testdata);
1596 })
1597
1570 roll_out_test_combos(clear, { 1598 roll_out_test_combos(clear, {
1571 int *testdata = int_test_data_added_to_list(list, isptrlist, 8); 1599 int *testdata = int_test_data_added_to_list(list, isptrlist, 8);
1572 CX_TEST_ASSERT(cxListSize(list) > 0); 1600 CX_TEST_ASSERT(cxListSize(list) > 0);
1573 cxListClear(list); 1601 cxListClear(list);
1574 CX_TEST_ASSERT(cxListSize(list) == 0); 1602 CX_TEST_ASSERT(cxListSize(list) == 0);
1933 cx_test_register(suite, test_list_parl_remove); 1961 cx_test_register(suite, test_list_parl_remove);
1934 cx_test_register(suite, test_list_arl_remove_array); 1962 cx_test_register(suite, test_list_arl_remove_array);
1935 cx_test_register(suite, test_list_parl_remove_array); 1963 cx_test_register(suite, test_list_parl_remove_array);
1936 cx_test_register(suite, test_list_arl_find_remove); 1964 cx_test_register(suite, test_list_arl_find_remove);
1937 cx_test_register(suite, test_list_parl_find_remove); 1965 cx_test_register(suite, test_list_parl_find_remove);
1966 cx_test_register(suite, test_list_arl_find_remove_sorted);
1967 cx_test_register(suite, test_list_parl_find_remove_sorted);
1938 cx_test_register(suite, test_list_arl_clear); 1968 cx_test_register(suite, test_list_arl_clear);
1939 cx_test_register(suite, test_list_parl_clear); 1969 cx_test_register(suite, test_list_parl_clear);
1940 cx_test_register(suite, test_list_arl_at); 1970 cx_test_register(suite, test_list_arl_at);
1941 cx_test_register(suite, test_list_parl_at); 1971 cx_test_register(suite, test_list_parl_at);
1942 cx_test_register(suite, test_list_arl_swap); 1972 cx_test_register(suite, test_list_arl_swap);
2030 cx_test_register(suite, test_list_pll_remove); 2060 cx_test_register(suite, test_list_pll_remove);
2031 cx_test_register(suite, test_list_ll_remove_array); 2061 cx_test_register(suite, test_list_ll_remove_array);
2032 cx_test_register(suite, test_list_pll_remove_array); 2062 cx_test_register(suite, test_list_pll_remove_array);
2033 cx_test_register(suite, test_list_ll_find_remove); 2063 cx_test_register(suite, test_list_ll_find_remove);
2034 cx_test_register(suite, test_list_pll_find_remove); 2064 cx_test_register(suite, test_list_pll_find_remove);
2065 cx_test_register(suite, test_list_ll_find_remove_sorted);
2066 cx_test_register(suite, test_list_pll_find_remove_sorted);
2035 cx_test_register(suite, test_list_ll_clear); 2067 cx_test_register(suite, test_list_ll_clear);
2036 cx_test_register(suite, test_list_pll_clear); 2068 cx_test_register(suite, test_list_pll_clear);
2037 cx_test_register(suite, test_list_ll_at); 2069 cx_test_register(suite, test_list_ll_at);
2038 cx_test_register(suite, test_list_pll_at); 2070 cx_test_register(suite, test_list_pll_at);
2039 cx_test_register(suite, test_list_ll_swap); 2071 cx_test_register(suite, test_list_ll_swap);

mercurial