| 2693 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
2693 CxList *dst = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
| 2694 cxDefineAdvancedDestructor(dst, cxFree, &talloc); |
2694 cxDefineAdvancedDestructor(dst, cxFree, &talloc); |
| 2695 CxList *minuend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
2695 CxList *minuend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
| 2696 CxList *subtrahend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
2696 CxList *subtrahend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
| 2697 |
2697 |
| 2698 int dst_data[] = { |
2698 int dst_data[] = {47, 178, 176, 83}; |
| 2699 47, 178, 176, 83, 109, 149, 192, 38, 101, 116, 121, 73, 94, 197, 91, 79, 158, 86, 190, 138, 100, 39, 30, 144, |
|
| 2700 35, 182, 155, 84, 139, 186, 67, 123, 62, 37, 3, 64, 172, 56, 160, 1, 156, 132, 131, 49, 10, 126, 171, 145, 77, |
|
| 2701 107 |
|
| 2702 }; |
|
| 2703 int minuend_data[] = { |
2699 int minuend_data[] = { |
| 2704 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, |
2700 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, |
| 2705 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 |
2701 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 |
| 2706 }; |
2702 }; |
| 2707 int subtrahend_data[] = { |
2703 int subtrahend_data[] = { |
| 2708 75, 137, 176, 111, 85, 27, 197, 141, 46, 103, 69, 146, 49, 79, 63, 130, 154, 45, 38, 139, 193, 90, 64, 142, 115, |
2704 75, 137, 176, 111, 85, 27, 197, 141, 46, 103, 69, 146, 49, 79, 63, 130, 154, 45, 38, 139, 193, 90, 64, 142, 115, |
| 2709 120, 78, 100, 101, 42, 21, 1, 161, 10, 114, 198, 181, 178, 136, 188, 59, 41, 73, 99, 151, 144, 118, 53, 199, 71 |
2705 120, 78, 100, 101, 42, 21, 1, 161, 10, 114, 198, 181, 178, 136, 188, 59, 41, 73, 99, 151, 144, 118, 53, 199, 71 |
| 2710 }; |
2706 }; |
| 2711 |
2707 |
| 2712 { |
2708 for (unsigned i = 0 ; i < cx_nmemb(dst_data) ; i++) { |
| 2713 CxList *tmp = cxArrayListCreateSimple(sizeof(int), 50); |
2709 int *x = cxMalloc(&talloc.base, sizeof(int)); |
| 2714 cxListAddArray(tmp, dst_data, 50); |
2710 *x = dst_data[i]; |
| 2715 cxListClone(dst, tmp, test_clone_func, &talloc.base, NULL); |
2711 cxListAdd(dst, x); |
| 2716 cxListFree(tmp); |
|
| 2717 } |
2712 } |
| 2718 cxListAddArray(minuend, minuend_data, 50); |
2713 cxListAddArray(minuend, minuend_data, 50); |
| 2719 cxListAddArray(subtrahend, subtrahend_data, 50); |
2714 cxListAddArray(subtrahend, subtrahend_data, 50); |
| 2720 if (sorted) { |
2715 if (sorted) { |
| 2721 cxListSort(dst); |
2716 cxListSort(dst); |
| 2722 cxListSort(minuend); |
2717 cxListSort(minuend); |
| 2723 cxListSort(subtrahend); |
2718 cxListSort(subtrahend); |
| 2724 } |
2719 } |
| 2725 |
2720 |
| 2726 // expected 36 elements stay in dst, and 36 will be added from the difference |
2721 // expected 36 elements in the difference |
| 2727 size_t expected_len = 72; |
2722 size_t expected_len = 40; |
| 2728 int expected_unsorted[] = { |
2723 int expected_unsorted[] = { |
| 2729 47, 83, 109, 149, 192, 116, 121, 94, 91, 158, 86, 190, 138, 39, 30, 35, 182, 155, 84, 186, 67, 123, 62, 37, |
2724 47, 178, 176, 83, |
| 2730 3, 172, 56, 160, 156, 132, 131, 126, 171, 145, 77, 107, |
|
| 2731 153, 106, 171, 74, 173, 150, 94, 92, 70, 175, 200, 20, 29, 88, 116, 124, 32, 9, 76, 33, 51, 37, 65, 12, 162, |
2725 153, 106, 171, 74, 173, 150, 94, 92, 70, 175, 200, 20, 29, 88, 116, 124, 32, 9, 76, 33, 51, 37, 65, 12, 162, |
| 2732 28, 4, 177, 54, 109, 44, 77, 194, 129, 97, 83 |
2726 28, 4, 177, 54, 109, 44, 77, 194, 129, 97, 83 |
| 2733 }; |
2727 }; |
| 2734 int expected_sorted[] = { |
2728 int expected_sorted[] = { |
| 2735 3, 30, 35, 37, 39, 47, 56, 62, 67, 77, 83, 84, 86, 91, 94, 107, 109, 116, 121, 123, 126, 131, 132, 138, 145, |
2729 47, 83, 176, 178, |
| 2736 149, 155, 156, 158, 160, 171, 172, 182, 186, 190, 192, |
|
| 2737 4, 9, 12, 20, 28, 29, 32, 33, 37, 44, 51, 54, 65, 70, 74, 76, 77, 83, 88, 92, 94, 97, 106, 109, 116, 124, 129, |
2730 4, 9, 12, 20, 28, 29, 32, 33, 37, 44, 51, 54, 65, 70, 74, 76, 77, 83, 88, 92, 94, 97, 106, 109, 116, 124, 129, |
| 2738 150, 153, 162, 171, 173, 175, 177, 194, 200 |
2731 150, 153, 162, 171, 173, 175, 177, 194, 200 |
| 2739 }; |
2732 }; |
| 2740 |
2733 |
| 2741 if (alloc_fail) { |
2734 if (alloc_fail) { |
| 2742 test_clone_func_max_enabled = true; |
2735 test_clone_func_max_enabled = true; |
| 2743 test_clone_func_max_clones = 30; |
2736 test_clone_func_max_clones = 30; |
| 2744 expected_len = 66; |
2737 expected_len = 34; |
| 2745 } |
2738 } |
| 2746 CxList *expected = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), expected_len); |
2739 CxList *expected = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), expected_len); |
| 2747 cxListAddArray(expected, sorted ? expected_sorted : expected_unsorted, expected_len); |
2740 cxListAddArray(expected, sorted ? expected_sorted : expected_unsorted, expected_len); |
| 2748 |
2741 |
| 2749 int result = cxListDifference(dst, minuend, subtrahend, test_clone_func, &talloc.base, NULL); |
2742 int result = cxListDifference(dst, minuend, subtrahend, test_clone_func, &talloc.base, NULL); |