| 1659 } \ |
1667 } \ |
| 1660 cx_testing_allocator_destroy(&talloc); |
1668 cx_testing_allocator_destroy(&talloc); |
| 1661 #define roll_out_test_invokers(name) \ |
1669 #define roll_out_test_invokers(name) \ |
| 1662 CX_TEST(test_list_ll_##name) { \ |
1670 CX_TEST(test_list_ll_##name) { \ |
| 1663 set_up_combo \ |
1671 set_up_combo \ |
| 1664 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \ |
1672 CxList *list = cxLinkedListCreate(alloc, sizeof(int)); \ |
| |
1673 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1665 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
1674 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
| 1666 tear_down_combo \ |
1675 tear_down_combo \ |
| 1667 } \ |
1676 } \ |
| 1668 CX_TEST(test_list_arl_##name) { \ |
1677 CX_TEST(test_list_arl_##name) { \ |
| 1669 set_up_combo \ |
1678 set_up_combo \ |
| 1670 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \ |
1679 CxList *list = cxArrayListCreate(alloc, sizeof(int), 8); \ |
| |
1680 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1671 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
1681 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
| 1672 tear_down_combo \ |
1682 tear_down_combo \ |
| 1673 } \ |
1683 } \ |
| 1674 CX_TEST(test_list_kvl_##name) { \ |
1684 CX_TEST(test_list_kvl_##name) { \ |
| 1675 set_up_combo \ |
1685 set_up_combo \ |
| 1676 CxList *list = cxKvListCreate(alloc, cx_cmp_int, sizeof(int)); \ |
1686 CxList *list = cxKvListCreate(alloc, sizeof(int)); \ |
| |
1687 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1677 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
1688 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
| 1678 tear_down_combo \ |
1689 tear_down_combo \ |
| 1679 } \ |
1690 } \ |
| 1680 CX_TEST(test_list_pll_##name) { \ |
1691 CX_TEST(test_list_pll_##name) { \ |
| 1681 set_up_combo \ |
1692 set_up_combo \ |
| 1682 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \ |
1693 CxList *list = cxLinkedListCreate(alloc, CX_STORE_POINTERS); \ |
| |
1694 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1683 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
1695 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
| 1684 tear_down_combo \ |
1696 tear_down_combo \ |
| 1685 } \ |
1697 } \ |
| 1686 CX_TEST(test_list_parl_##name) { \ |
1698 CX_TEST(test_list_parl_##name) { \ |
| 1687 set_up_combo \ |
1699 set_up_combo \ |
| 1688 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \ |
1700 CxList *list = cxArrayListCreate(alloc, CX_STORE_POINTERS, 8); \ |
| |
1701 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1689 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
1702 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
| 1690 tear_down_combo \ |
1703 tear_down_combo \ |
| 1691 } \ |
1704 } \ |
| 1692 CX_TEST(test_list_pkvl_##name) { \ |
1705 CX_TEST(test_list_pkvl_##name) { \ |
| 1693 set_up_combo \ |
1706 set_up_combo \ |
| 1694 CxList *list = cxKvListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \ |
1707 CxList *list = cxKvListCreate(alloc, CX_STORE_POINTERS); \ |
| |
1708 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1695 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
1709 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
| 1696 tear_down_combo \ |
1710 tear_down_combo \ |
| 1697 } |
1711 } |
| 1698 #define roll_out_test_combos(name, body) \ |
1712 #define roll_out_test_combos(name, body) \ |
| 1699 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ |
1713 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ |
| 1723 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ |
1737 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ |
| 1724 cx_attr_unused bool isptrlist) body \ |
1738 cx_attr_unused bool isptrlist) body \ |
| 1725 roll_out_test_invokers(name) \ |
1739 roll_out_test_invokers(name) \ |
| 1726 CX_TEST(test_list_llm_##name) { \ |
1740 CX_TEST(test_list_llm_##name) { \ |
| 1727 set_up_combo \ |
1741 set_up_combo \ |
| 1728 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \ |
1742 CxList *list = cxLinkedListCreate(alloc, sizeof(int)); \ |
| |
1743 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1729 do_set_default_class_funcs(list); \ |
1744 do_set_default_class_funcs(list); \ |
| 1730 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
1745 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
| 1731 tear_down_combo \ |
1746 tear_down_combo \ |
| 1732 } \ |
1747 } \ |
| 1733 CX_TEST(test_list_arlm_##name) { \ |
1748 CX_TEST(test_list_arlm_##name) { \ |
| 1734 set_up_combo \ |
1749 set_up_combo \ |
| 1735 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \ |
1750 CxList *list = cxArrayListCreate(alloc, sizeof(int), 8); \ |
| |
1751 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1736 do_set_default_class_funcs(list); \ |
1752 do_set_default_class_funcs(list); \ |
| 1737 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
1753 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ |
| 1738 tear_down_combo \ |
1754 tear_down_combo \ |
| 1739 } \ |
1755 } \ |
| 1740 CX_TEST(test_list_pllm_##name) { \ |
1756 CX_TEST(test_list_pllm_##name) { \ |
| 1741 set_up_combo \ |
1757 set_up_combo \ |
| 1742 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \ |
1758 CxList *list = cxLinkedListCreate(alloc, CX_STORE_POINTERS); \ |
| |
1759 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1743 do_set_default_class_funcs(list); \ |
1760 do_set_default_class_funcs(list); \ |
| 1744 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
1761 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
| 1745 tear_down_combo \ |
1762 tear_down_combo \ |
| 1746 } \ |
1763 } \ |
| 1747 CX_TEST(test_list_parlm_##name) { \ |
1764 CX_TEST(test_list_parlm_##name) { \ |
| 1748 set_up_combo \ |
1765 set_up_combo \ |
| 1749 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \ |
1766 CxList *list = cxArrayListCreate(alloc, CX_STORE_POINTERS, 8); \ |
| |
1767 cxSetCompareFunc(list, cx_cmp_int); \ |
| 1750 do_set_default_class_funcs(list); \ |
1768 do_set_default_class_funcs(list); \ |
| 1751 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
1769 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ |
| 1752 tear_down_combo \ |
1770 tear_down_combo \ |
| 1753 } |
1771 } |
| 1754 |
1772 |
| 2641 #define roll_out_compare_tests(suffix, otherctr) \ |
2660 #define roll_out_compare_tests(suffix, otherctr) \ |
| 2642 roll_out_test_combos(compare_##suffix, { \ |
2661 roll_out_test_combos(compare_##suffix, { \ |
| 2643 const size_t len = 47; \ |
2662 const size_t len = 47; \ |
| 2644 int *testdata = int_test_data_added_to_list(list, isptrlist, len); \ |
2663 int *testdata = int_test_data_added_to_list(list, isptrlist, len); \ |
| 2645 CxList *other = otherctr; \ |
2664 CxList *other = otherctr; \ |
| |
2665 cxSetCompareFunc(other, cx_cmp_int); \ |
| 2646 for (size_t i = 0; i < len; i++) cxListAdd(other, &testdata[i]); \ |
2666 for (size_t i = 0; i < len; i++) cxListAdd(other, &testdata[i]); \ |
| 2647 CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); \ |
2667 CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); \ |
| 2648 cxListFree(other); \ |
2668 cxListFree(other); \ |
| 2649 free(testdata); \ |
2669 free(testdata); \ |
| 2650 }) |
2670 }) |
| 2651 |
2671 |
| 2652 roll_out_compare_tests( |
2672 roll_out_compare_tests( |
| 2653 ll, cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)) |
2673 ll, cxLinkedListCreate(cxDefaultAllocator, sizeof(int)) |
| 2654 ) |
2674 ) |
| 2655 |
2675 |
| 2656 roll_out_compare_tests( |
2676 roll_out_compare_tests( |
| 2657 pll, cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS) |
2677 pll, cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS) |
| 2658 ) |
2678 ) |
| 2659 |
2679 |
| 2660 roll_out_compare_tests( |
2680 roll_out_compare_tests( |
| 2661 arl, cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 50) |
2681 arl, cxArrayListCreate(cxDefaultAllocator, sizeof(int), 50) |
| 2662 ) |
2682 ) |
| 2663 |
2683 |
| 2664 roll_out_compare_tests( |
2684 roll_out_compare_tests( |
| 2665 parl, cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 50) |
2685 parl, cxArrayListCreate(cxDefaultAllocator, CX_STORE_POINTERS, 50) |
| 2666 ) |
2686 ) |
| 2667 |
2687 |
| 2668 roll_out_test_combos_with_defaulted_funcs(compare_unoptimized, { |
2688 roll_out_test_combos_with_defaulted_funcs(compare_unoptimized, { |
| 2669 const size_t len = 33; |
2689 const size_t len = 33; |
| 2670 int *testdata = int_test_data_added_to_list(list, isptrlist, len); |
2690 int *testdata = int_test_data_added_to_list(list, isptrlist, len); |
| 2671 CxList *other = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 50); |
2691 CxList *other = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 50); |
| |
2692 cxSetCompareFunc(other, cx_cmp_int); |
| 2672 do_set_default_class_funcs(other); |
2693 do_set_default_class_funcs(other); |
| 2673 for (size_t i = 0; i < len; i++) cxListAdd(other, &testdata[i]); |
2694 for (size_t i = 0; i < len; i++) cxListAdd(other, &testdata[i]); |
| 2674 CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); |
2695 CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); |
| 2675 cxListFree(other); |
2696 cxListFree(other); |
| 2676 free(testdata); |
2697 free(testdata); |
| 2894 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2915 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| 2895 cx_testing_allocator_destroy(&talloc); |
2916 cx_testing_allocator_destroy(&talloc); |
| 2896 } |
2917 } |
| 2897 |
2918 |
| 2898 roll_out_test_combos(clone_into_arl, { |
2919 roll_out_test_combos(clone_into_arl, { |
| 2899 CxList *target = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
2920 CxList *target = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 8); |
| |
2921 cxSetCompareFunc(target, cx_cmp_int); |
| 2900 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, false); |
2922 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, false); |
| 2901 }) |
2923 }) |
| 2902 |
2924 |
| 2903 roll_out_test_combos(clone_into_ll, { |
2925 roll_out_test_combos(clone_into_ll, { |
| 2904 CxList *target = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
2926 CxList *target = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| |
2927 cxSetCompareFunc(target, cx_cmp_int); |
| 2905 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, false); |
2928 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, false); |
| 2906 }) |
2929 }) |
| 2907 |
2930 |
| 2908 roll_out_test_combos(clone_into_parl, { |
2931 roll_out_test_combos(clone_into_parl, { |
| 2909 CxList *target = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 8); |
2932 CxList *target = cxArrayListCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); |
| |
2933 cxSetCompareFunc(target, cx_cmp_int); |
| 2910 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, true); |
2934 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, true); |
| 2911 }) |
2935 }) |
| 2912 |
2936 |
| 2913 roll_out_test_combos(clone_into_pll, { |
2937 roll_out_test_combos(clone_into_pll, { |
| 2914 CxList *target = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
2938 CxList *target = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| |
2939 cxSetCompareFunc(target, cx_cmp_int); |
| 2915 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, true); |
2940 CX_TEST_CALL_SUBROUTINE(verify_clone, target, list, true); |
| 2916 }) |
2941 }) |
| 2917 |
2942 |
| 2918 roll_out_test_combos(clone_alloc_fail_into_arl, { |
2943 roll_out_test_combos(clone_alloc_fail_into_arl, { |
| 2919 CxList *target = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
2944 CxList *target = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 8); |
| |
2945 cxSetCompareFunc(target, cx_cmp_int); |
| 2920 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, false); |
2946 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, false); |
| 2921 }) |
2947 }) |
| 2922 |
2948 |
| 2923 roll_out_test_combos(clone_alloc_fail_into_ll, { |
2949 roll_out_test_combos(clone_alloc_fail_into_ll, { |
| 2924 CxList *target = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
2950 CxList *target = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| |
2951 cxSetCompareFunc(target, cx_cmp_int); |
| 2925 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, false); |
2952 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, false); |
| 2926 }) |
2953 }) |
| 2927 |
2954 |
| 2928 roll_out_test_combos(clone_alloc_fail_into_parl, { |
2955 roll_out_test_combos(clone_alloc_fail_into_parl, { |
| 2929 CxList *target = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 8); |
2956 CxList *target = cxArrayListCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); |
| |
2957 cxSetCompareFunc(target, cx_cmp_int); |
| 2930 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, true); |
2958 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, true); |
| 2931 }) |
2959 }) |
| 2932 |
2960 |
| 2933 roll_out_test_combos(clone_alloc_fail_into_pll, { |
2961 roll_out_test_combos(clone_alloc_fail_into_pll, { |
| 2934 CxList *target = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
2962 CxList *target = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| |
2963 cxSetCompareFunc(target, cx_cmp_int); |
| 2935 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, true); |
2964 CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, true); |
| 2936 }) |
2965 }) |
| 2937 |
2966 |
| 2938 static CX_TEST_SUBROUTINE(verify_difference, bool sorted, bool alloc_fail) { |
2967 static CX_TEST_SUBROUTINE(verify_difference, bool sorted, bool alloc_fail) { |
| 2939 CxTestingAllocator talloc; |
2968 CxTestingAllocator talloc; |
| 2940 cx_testing_allocator_init(&talloc); |
2969 cx_testing_allocator_init(&talloc); |
| 2941 |
2970 |
| 2942 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
2971 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| 2943 cxDefineAdvancedDestructor(dst, cxFree, &talloc); |
2972 cxSetAdvancedDestructor(dst, cxFree, &talloc); |
| 2944 CxList *minuend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
2973 CxList *minuend = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| 2945 CxList *subtrahend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
2974 CxList *subtrahend = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| |
2975 cxSetCompareFunc(dst, cx_cmp_int); |
| |
2976 cxSetCompareFunc(minuend, cx_cmp_int); |
| |
2977 cxSetCompareFunc(subtrahend, cx_cmp_int); |
| 2946 |
2978 |
| 2947 int dst_data[] = {47, 178, 176, 83}; |
2979 int dst_data[] = {47, 178, 176, 83}; |
| 2948 int minuend_data[] = { |
2980 int minuend_data[] = { |
| 2949 153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, |
2981 153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, |
| 2950 151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 |
2982 151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 |
| 3032 |
3065 |
| 3033 static CX_TEST_SUBROUTINE(verify_intersection, bool sorted, bool alloc_fail) { |
3066 static CX_TEST_SUBROUTINE(verify_intersection, bool sorted, bool alloc_fail) { |
| 3034 CxTestingAllocator talloc; |
3067 CxTestingAllocator talloc; |
| 3035 cx_testing_allocator_init(&talloc); |
3068 cx_testing_allocator_init(&talloc); |
| 3036 |
3069 |
| 3037 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
3070 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| 3038 cxDefineAdvancedDestructor(dst, cxFree, &talloc); |
3071 cxSetAdvancedDestructor(dst, cxFree, &talloc); |
| 3039 CxList *src = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
3072 CxList *src = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| 3040 CxList *other = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
3073 CxList *other = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| |
3074 cxSetCompareFunc(dst, cx_cmp_int); |
| |
3075 cxSetCompareFunc(src, cx_cmp_int); |
| |
3076 cxSetCompareFunc(other, cx_cmp_int); |
| 3041 |
3077 |
| 3042 int dst_data[] = {47, 178, 176, 83}; |
3078 int dst_data[] = {47, 178, 176, 83}; |
| 3043 int src_data[] = { |
3079 int src_data[] = { |
| 3044 153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, |
3080 153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, |
| 3045 151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 |
3081 151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 |
| 3125 |
3162 |
| 3126 static CX_TEST_SUBROUTINE(verify_union, bool sorted, bool alloc_fail) { |
3163 static CX_TEST_SUBROUTINE(verify_union, bool sorted, bool alloc_fail) { |
| 3127 CxTestingAllocator talloc; |
3164 CxTestingAllocator talloc; |
| 3128 cx_testing_allocator_init(&talloc); |
3165 cx_testing_allocator_init(&talloc); |
| 3129 |
3166 |
| 3130 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
3167 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| 3131 cxDefineAdvancedDestructor(dst, cxFree, &talloc); |
3168 cxSetCompareFunc(dst, cx_cmp_int); |
| 3132 CxList *src = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
3169 cxSetAdvancedDestructor(dst, cxFree, &talloc); |
| 3133 CxList *other = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
3170 CxList *src = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| |
3171 CxList *other = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| |
3172 cxSetCompareFunc(src, cx_cmp_int); |
| |
3173 cxSetCompareFunc(other, cx_cmp_int); |
| 3134 |
3174 |
| 3135 int dst_data[] = {47, 178, 176, 83}; |
3175 int dst_data[] = {47, 178, 176, 83}; |
| 3136 int src_data[] = { |
3176 int src_data[] = { |
| 3137 153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, |
3177 153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, |
| 3138 151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 |
3178 151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 |
| 3233 int a[] = {1, 2, 5, 8, 10}; |
3274 int a[] = {1, 2, 5, 8, 10}; |
| 3234 int b[] = {1, 3, 5, 7, 9, 11}; |
3275 int b[] = {1, 3, 5, 7, 9, 11}; |
| 3235 int c[] = {2, 4, 6, 8, 10, 12}; |
3276 int c[] = {2, 4, 6, 8, 10, 12}; |
| 3236 int d[] = {4, 8, 12}; |
3277 int d[] = {4, 8, 12}; |
| 3237 |
3278 |
| 3238 CxList *la = cxArrayListCreateSimple(sizeof(int), 8); |
3279 CxList *la = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3239 cxCollectionCompareFunc(la, cx_cmp_int); |
3280 cxSetCompareFunc(la, cx_cmp_int); |
| 3240 cxListInsertSortedArray(la, a, cx_nmemb(a)); |
3281 cxListInsertSortedArray(la, a, cx_nmemb(a)); |
| 3241 CxList *lb = cxArrayListCreateSimple(sizeof(int), 8); |
3282 CxList *lb = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3242 cxCollectionCompareFunc(lb, cx_cmp_int); |
3283 cxSetCompareFunc(lb, cx_cmp_int); |
| 3243 cxListInsertSortedArray(lb, b, cx_nmemb(b)); |
3284 cxListInsertSortedArray(lb, b, cx_nmemb(b)); |
| 3244 CxList *lc = cxArrayListCreateSimple(sizeof(int), 8); |
3285 CxList *lc = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3245 cxCollectionCompareFunc(lc, cx_cmp_int); |
3286 cxSetCompareFunc(lc, cx_cmp_int); |
| 3246 cxListInsertSortedArray(lc, c, cx_nmemb(c)); |
3287 cxListInsertSortedArray(lc, c, cx_nmemb(c)); |
| 3247 CxList *ld = cxArrayListCreateSimple(sizeof(int), 8); |
3288 CxList *ld = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3248 cxCollectionCompareFunc(ld, cx_cmp_int); |
3289 cxSetCompareFunc(ld, cx_cmp_int); |
| 3249 cxListInsertSortedArray(ld, d, cx_nmemb(d)); |
3290 cxListInsertSortedArray(ld, d, cx_nmemb(d)); |
| 3250 |
3291 |
| 3251 CxList *d1 = cxArrayListCreateSimple(sizeof(int), 8); |
3292 CxList *d1 = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3252 cxCollectionCompareFunc(d1, cx_cmp_int); |
3293 cxSetCompareFunc(d1, cx_cmp_int); |
| 3253 CxList *d2 = cxArrayListCreateSimple(sizeof(int), 8); |
3294 CxList *d2 = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3254 cxCollectionCompareFunc(d2, cx_cmp_int); |
3295 cxSetCompareFunc(d2, cx_cmp_int); |
| 3255 |
3296 |
| 3256 CX_TEST_DO { |
3297 CX_TEST_DO { |
| 3257 // clone a into d1 |
3298 // clone a into d1 |
| 3258 CX_TEST_ASSERT(0 == cxListCloneShallow(d1, la)); |
3299 CX_TEST_ASSERT(0 == cxListCloneShallow(d1, la)); |
| 3259 CX_TEST_ASSERT(0 == cxListCompare(d1, la)); |
3300 CX_TEST_ASSERT(0 == cxListCompare(d1, la)); |
| 3260 CX_TEST_ASSERT(cxCollectionSorted(d1)); |
3301 CX_TEST_ASSERT(cxCollectionSorted(d1)); |
| 3261 |
3302 |
| 3262 // union of a (in d1) and b |
3303 // union of a (in d1) and b |
| 3263 CX_TEST_ASSERT(0 == cxListUnionShallow(d2, d1, lb)); |
3304 CX_TEST_ASSERT(0 == cxListUnionShallow(d2, d1, lb)); |
| 3264 CX_TEST_ASSERT(cxCollectionSorted(d2)); |
3305 CX_TEST_ASSERT(cxCollectionSorted(d2)); |
| 3265 CxList *expected_union = cxArrayListCreateSimple(sizeof(int), 8); |
3306 CxList *expected_union = cxArrayListCreate(NULL, sizeof(int), 8); |
| 3266 { |
3307 { |
| 3267 int expected[] = {1, 2, 3, 5, 7, 8, 9, 10, 11}; |
3308 int expected[] = {1, 2, 3, 5, 7, 8, 9, 10, 11}; |
| 3268 cxListAddArray(expected_union, expected, cx_nmemb(expected)); |
3309 cxListAddArray(expected_union, expected, cx_nmemb(expected)); |
| 3269 } |
3310 } |
| 3270 CX_TEST_ASSERT(0 == cxListCompare(d2, expected_union)); |
3311 CX_TEST_ASSERT(0 == cxListCompare(d2, expected_union)); |
| 3330 } |
3372 } |
| 3331 cxListFree(list); |
3373 cxListFree(list); |
| 3332 } |
3374 } |
| 3333 |
3375 |
| 3334 CX_TEST(test_list_use_insert_unique_to_remove_duplicates) { |
3376 CX_TEST(test_list_use_insert_unique_to_remove_duplicates) { |
| 3335 CxList *linked_list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
3377 CxList *linked_list = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| 3336 CxList *array_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
3378 CxList *array_list = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 8); |
| 3337 CxList *defaulted_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
3379 CxList *defaulted_list = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 8); |
| |
3380 cxSetCompareFunc(linked_list, cx_cmp_int); |
| |
3381 cxSetCompareFunc(array_list, cx_cmp_int); |
| |
3382 cxSetCompareFunc(defaulted_list, cx_cmp_int); |
| 3338 do_set_default_class_funcs(defaulted_list); |
3383 do_set_default_class_funcs(defaulted_list); |
| 3339 int test_array[23] = { |
3384 int test_array[23] = { |
| 3340 120, -13, 100, -90, 13, -56, 74, 20, 28, 80, 18, -56, 130, 12, 15, 0, 39, 100, 0, 29, 28, 85, 20 |
3385 120, -13, 100, -90, 13, -56, 74, 20, 28, 80, 18, -56, 130, 12, 15, 0, 39, 100, 0, 29, 28, 85, 20 |
| 3341 }; |
3386 }; |
| 3342 int test_array_unique[18] = { |
3387 int test_array_unique[18] = { |
| 3360 cxListFree(linked_list); |
3405 cxListFree(linked_list); |
| 3361 cxListFree(array_list); |
3406 cxListFree(array_list); |
| 3362 } |
3407 } |
| 3363 |
3408 |
| 3364 CX_TEST(test_list_use_insert_unique_with_duplicates_in_source) { |
3409 CX_TEST(test_list_use_insert_unique_with_duplicates_in_source) { |
| 3365 CxList *linked_list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
3410 CxList *linked_list = cxLinkedListCreate(cxDefaultAllocator, sizeof(int)); |
| 3366 CxList *array_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
3411 CxList *array_list = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 8); |
| 3367 CxList *defaulted_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
3412 CxList *defaulted_list = cxArrayListCreate(cxDefaultAllocator, sizeof(int), 8); |
| |
3413 cxSetCompareFunc(linked_list, cx_cmp_int); |
| |
3414 cxSetCompareFunc(array_list, cx_cmp_int); |
| |
3415 cxSetCompareFunc(defaulted_list, cx_cmp_int); |
| 3368 do_set_default_class_funcs(defaulted_list); |
3416 do_set_default_class_funcs(defaulted_list); |
| 3369 int pre_filled[10] = {-13, 5, 18, 30, 40, 45, 50, 80, 85, 110}; |
3417 int pre_filled[10] = {-13, 5, 18, 30, 40, 45, 50, 80, 85, 110}; |
| 3370 cxListInsertSortedArray(linked_list, pre_filled, 10); |
3418 cxListInsertSortedArray(linked_list, pre_filled, 10); |
| 3371 cxListInsertSortedArray(array_list, pre_filled, 10); |
3419 cxListInsertSortedArray(array_list, pre_filled, 10); |
| 3372 cxListInsertSortedArray(defaulted_list, pre_filled, 10); |
3420 cxListInsertSortedArray(defaulted_list, pre_filled, 10); |