tests/test_list.c

changeset 876
f4ce7df9cff0
parent 875
ee84ac776cbc
child 883
3012e9b4214e
equal deleted inserted replaced
875:ee84ac776cbc 876:f4ce7df9cff0
960 960
961 static void set_default_class_funcs(CxList *list, cx_list_class *defaulted_cl) { 961 static void set_default_class_funcs(CxList *list, cx_list_class *defaulted_cl) {
962 cx_list_class const *cl = list->climpl == NULL ? list->cl : list->climpl; 962 cx_list_class const *cl = list->climpl == NULL ? list->cl : list->climpl;
963 memcpy(defaulted_cl, cl, sizeof(cx_list_class)); 963 memcpy(defaulted_cl, cl, sizeof(cx_list_class));
964 defaulted_cl->insert_array = cx_list_default_insert_array; 964 defaulted_cl->insert_array = cx_list_default_insert_array;
965 defaulted_cl->insert_sorted = cx_list_default_insert_sorted;
965 defaulted_cl->sort = cx_list_default_sort; 966 defaulted_cl->sort = cx_list_default_sort;
966 defaulted_cl->swap = cx_list_default_swap; 967 defaulted_cl->swap = cx_list_default_swap;
967 defaulted_cl->compare = NULL; 968 defaulted_cl->compare = NULL;
968 if (list->climpl == NULL) { 969 if (list->climpl == NULL) {
969 list->cl = defaulted_cl; 970 list->cl = defaulted_cl;
1097 CX_TEST_ASSERT(*(int *) cxListAt(list, 7) == 7); 1098 CX_TEST_ASSERT(*(int *) cxListAt(list, 7) == 7);
1098 CX_TEST_ASSERT(*(int *) cxListAt(list, 8) == 13); 1099 CX_TEST_ASSERT(*(int *) cxListAt(list, 8) == 13);
1099 CX_TEST_ASSERT(*(int *) cxListAt(list, 9) == 42); 1100 CX_TEST_ASSERT(*(int *) cxListAt(list, 9) == 42);
1100 }) 1101 })
1101 1102
1103 roll_out_test_combos_with_defaulted_funcs(insert_sorted, {
1104 int d1 = 50;
1105 int d2 = 80;
1106 int d3 = 60;
1107 int d4 = 40;
1108 int d5 = 70;
1109 int d6a[6] = array_init(52, 54, 56, 62, 64, 75);
1110 int d7a[6] = array_init(51, 57, 58, 65, 77, 78);
1111 int d8 = 90;
1112 int *d6ptr[6];
1113 int *d7ptr[6];
1114 cx_for_n(i, 6)
1115 {
1116 d6ptr[i] = &d6a[i];
1117 d7ptr[i] = &d7a[i];
1118 }
1119 size_t inserted;
1120 int expected[18] = array_init(
1121 40, 50, 51, 52, 54, 56, 57, 58, 60,
1122 62, 64, 65, 70, 75, 77, 78, 80, 90
1123 );
1124
1125 CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d1));
1126 CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d2));
1127 CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d3));
1128 CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d4));
1129 CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d5));
1130 if (isptrlist) {
1131 inserted = cxListInsertSortedArray(list, d6ptr, 6);
1132 } else {
1133 inserted = cxListInsertSortedArray(list, d6a, 6);
1134 }
1135 CX_TEST_ASSERT(inserted == 6);
1136 if (isptrlist) {
1137 inserted = cxListInsertSortedArray(list, d7ptr, 6);
1138 } else {
1139 inserted = cxListInsertSortedArray(list, d7a, 6);
1140 }
1141 CX_TEST_ASSERT(inserted == 6);
1142 CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d8));
1143
1144 CX_TEST_ASSERT(cxListSize(list) == 18);
1145 cx_for_n(i, 18)
1146 {
1147 CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
1148 }
1149 })
1150
1102 roll_out_test_combos(remove, { 1151 roll_out_test_combos(remove, {
1103 const size_t testdata_len = 32; 1152 const size_t testdata_len = 32;
1104 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len); 1153 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1105 1154
1106 CX_TEST_ASSERT(cxListRemove(list, 2) == 0); 1155 CX_TEST_ASSERT(cxListRemove(list, 2) == 0);
1497 cx_test_register(suite, test_list_parl_add); 1546 cx_test_register(suite, test_list_parl_add);
1498 cx_test_register(suite, test_list_arl_insert); 1547 cx_test_register(suite, test_list_arl_insert);
1499 cx_test_register(suite, test_list_parl_insert); 1548 cx_test_register(suite, test_list_parl_insert);
1500 cx_test_register(suite, test_list_arl_insert_array); 1549 cx_test_register(suite, test_list_arl_insert_array);
1501 cx_test_register(suite, test_list_parl_insert_array); 1550 cx_test_register(suite, test_list_parl_insert_array);
1551 cx_test_register(suite, test_list_arl_insert_sorted);
1552 cx_test_register(suite, test_list_parl_insert_sorted);
1502 cx_test_register(suite, test_list_arl_remove); 1553 cx_test_register(suite, test_list_arl_remove);
1503 cx_test_register(suite, test_list_parl_remove); 1554 cx_test_register(suite, test_list_parl_remove);
1504 cx_test_register(suite, test_list_arl_find_remove); 1555 cx_test_register(suite, test_list_arl_find_remove);
1505 cx_test_register(suite, test_list_parl_find_remove); 1556 cx_test_register(suite, test_list_parl_find_remove);
1506 cx_test_register(suite, test_list_arl_clear); 1557 cx_test_register(suite, test_list_arl_clear);
1540 CxTestSuite *suite = cx_test_suite_new( 1591 CxTestSuite *suite = cx_test_suite_new(
1541 "array_list with defaulted functions"); 1592 "array_list with defaulted functions");
1542 1593
1543 cx_test_register(suite, test_list_arlm_insert_array); 1594 cx_test_register(suite, test_list_arlm_insert_array);
1544 cx_test_register(suite, test_list_parlm_insert_array); 1595 cx_test_register(suite, test_list_parlm_insert_array);
1596 cx_test_register(suite, test_list_arlm_insert_sorted);
1597 cx_test_register(suite, test_list_parlm_insert_sorted);
1545 cx_test_register(suite, test_list_arlm_swap); 1598 cx_test_register(suite, test_list_arlm_swap);
1546 cx_test_register(suite, test_list_parlm_swap); 1599 cx_test_register(suite, test_list_parlm_swap);
1547 cx_test_register(suite, test_list_arlm_sort); 1600 cx_test_register(suite, test_list_arlm_sort);
1548 cx_test_register(suite, test_list_parlm_sort); 1601 cx_test_register(suite, test_list_parlm_sort);
1549 1602
1587 cx_test_register(suite, test_list_pll_add); 1640 cx_test_register(suite, test_list_pll_add);
1588 cx_test_register(suite, test_list_ll_insert); 1641 cx_test_register(suite, test_list_ll_insert);
1589 cx_test_register(suite, test_list_pll_insert); 1642 cx_test_register(suite, test_list_pll_insert);
1590 cx_test_register(suite, test_list_ll_insert_array); 1643 cx_test_register(suite, test_list_ll_insert_array);
1591 cx_test_register(suite, test_list_pll_insert_array); 1644 cx_test_register(suite, test_list_pll_insert_array);
1645 cx_test_register(suite, test_list_ll_insert_sorted);
1646 cx_test_register(suite, test_list_pll_insert_sorted);
1592 cx_test_register(suite, test_list_ll_remove); 1647 cx_test_register(suite, test_list_ll_remove);
1593 cx_test_register(suite, test_list_pll_remove); 1648 cx_test_register(suite, test_list_pll_remove);
1594 cx_test_register(suite, test_list_ll_find_remove); 1649 cx_test_register(suite, test_list_ll_find_remove);
1595 cx_test_register(suite, test_list_pll_find_remove); 1650 cx_test_register(suite, test_list_pll_find_remove);
1596 cx_test_register(suite, test_list_ll_clear); 1651 cx_test_register(suite, test_list_ll_clear);
1630 CxTestSuite *suite = cx_test_suite_new( 1685 CxTestSuite *suite = cx_test_suite_new(
1631 "linked_list with defaulted functions"); 1686 "linked_list with defaulted functions");
1632 1687
1633 cx_test_register(suite, test_list_llm_insert_array); 1688 cx_test_register(suite, test_list_llm_insert_array);
1634 cx_test_register(suite, test_list_pllm_insert_array); 1689 cx_test_register(suite, test_list_pllm_insert_array);
1690 cx_test_register(suite, test_list_llm_insert_sorted);
1691 cx_test_register(suite, test_list_pllm_insert_sorted);
1635 cx_test_register(suite, test_list_llm_swap); 1692 cx_test_register(suite, test_list_llm_swap);
1636 cx_test_register(suite, test_list_pllm_swap); 1693 cx_test_register(suite, test_list_pllm_swap);
1637 cx_test_register(suite, test_list_llm_sort); 1694 cx_test_register(suite, test_list_llm_sort);
1638 cx_test_register(suite, test_list_pllm_sort); 1695 cx_test_register(suite, test_list_pllm_sort);
1639 1696

mercurial