2452 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 11); |
2453 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 11); |
2453 CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 47); |
2454 CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 47); |
2454 CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 1337); |
2455 CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 1337); |
2455 } |
2456 } |
2456 cxListFree(list); |
2457 cxListFree(list); |
|
2458 } |
|
2459 |
|
2460 CX_TEST(test_list_use_insert_unique_to_remove_duplicates) { |
|
2461 CxList *linked_list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
|
2462 CxList *array_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
|
2463 CxList *defaulted_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
|
2464 do_set_default_class_funcs(defaulted_list); |
|
2465 int test_array[23] = { |
|
2466 120, -13, 100, -90, 13, -56, 74, 20, 28, 80, 18, -56, 130, 12, 15, 0, 39, 100, 0, 29, 28, 85, 20 |
|
2467 }; |
|
2468 int test_array_unique[18] = { |
|
2469 -90, -56, -13, 0, 12, 13, 15, 18, 20, 28, 29, 39, 74, 80, 85, 100, 120, 130 |
|
2470 }; |
|
2471 CX_TEST_DO { |
|
2472 qsort(test_array, 23, sizeof(int), cx_cmp_int); |
|
2473 cxListInsertUniqueArray(linked_list, test_array, 23); |
|
2474 cxListInsertUniqueArray(array_list, test_array, 23); |
|
2475 cxListInsertUniqueArray(defaulted_list, test_array, 23); |
|
2476 CX_TEST_ASSERT(cxListSize(linked_list) == 18); |
|
2477 CX_TEST_ASSERT(cxListSize(array_list) == 18); |
|
2478 CX_TEST_ASSERT(cxListSize(defaulted_list) == 18); |
|
2479 for (unsigned i = 0; i < 18; i++) { |
|
2480 CX_TEST_ASSERT(*(int *) cxListAt(linked_list, i) == test_array_unique[i]); |
|
2481 CX_TEST_ASSERT(*(int *) cxListAt(array_list, i) == test_array_unique[i]); |
|
2482 CX_TEST_ASSERT(*(int *) cxListAt(defaulted_list, i) == test_array_unique[i]); |
|
2483 } |
|
2484 } |
|
2485 cxListFree(defaulted_list); |
|
2486 cxListFree(linked_list); |
|
2487 cxListFree(array_list); |
|
2488 } |
|
2489 |
|
2490 CX_TEST(test_list_use_insert_unique_with_duplicates_in_source) { |
|
2491 CxList *linked_list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); |
|
2492 CxList *array_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
|
2493 CxList *defaulted_list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 8); |
|
2494 do_set_default_class_funcs(defaulted_list); |
|
2495 int pre_filled[10] = {-13, 5, 18, 30, 40, 45, 50, 80, 85, 110}; |
|
2496 cxListInsertSortedArray(linked_list, pre_filled, 10); |
|
2497 cxListInsertSortedArray(array_list, pre_filled, 10); |
|
2498 cxListInsertSortedArray(defaulted_list, pre_filled, 10); |
|
2499 int test_array[23] = { |
|
2500 120, -13, 100, -90, 13, -56, 74, 20, 28, 80, 18, -56, 130, 12, 15, 0, 39, 100, 0, 29, 28, 85, 20 |
|
2501 }; |
|
2502 int test_array_unique[24] = { |
|
2503 -90, -56, -13, 0, 5, 12, 13, 15, 18, 20, 28, 29, 30, 39, 40, 45, 50, 74, 80, 85, 100, 110, 120, 130 |
|
2504 }; |
|
2505 CX_TEST_DO { |
|
2506 qsort(test_array, 23, sizeof(int), cx_cmp_int); |
|
2507 cxListInsertUniqueArray(linked_list, test_array, 23); |
|
2508 cxListInsertUniqueArray(array_list, test_array, 23); |
|
2509 cxListInsertUniqueArray(defaulted_list, test_array, 23); |
|
2510 CX_TEST_ASSERT(cxListSize(linked_list) == 24); |
|
2511 CX_TEST_ASSERT(cxListSize(array_list) == 24); |
|
2512 CX_TEST_ASSERT(cxListSize(defaulted_list) == 24); |
|
2513 for (unsigned i = 0; i < 24; i++) { |
|
2514 CX_TEST_ASSERT(*(int *) cxListAt(linked_list, i) == test_array_unique[i]); |
|
2515 CX_TEST_ASSERT(*(int *) cxListAt(array_list, i) == test_array_unique[i]); |
|
2516 CX_TEST_ASSERT(*(int *) cxListAt(defaulted_list, i) == test_array_unique[i]); |
|
2517 } |
|
2518 CX_TEST_ASSERT(*(int*)cxListLast(linked_list) == 130); |
|
2519 CX_TEST_ASSERT(*(int*)cxListLast(array_list) == 130); |
|
2520 CX_TEST_ASSERT(*(int*)cxListLast(defaulted_list) == 130); |
|
2521 } |
|
2522 cxListFree(defaulted_list); |
|
2523 cxListFree(linked_list); |
|
2524 cxListFree(array_list); |
2457 } |
2525 } |
2458 |
2526 |
2459 CxTestSuite *cx_test_suite_array_list(void) { |
2527 CxTestSuite *cx_test_suite_array_list(void) { |
2460 CxTestSuite *suite = cx_test_suite_new("array_list"); |
2528 CxTestSuite *suite = cx_test_suite_new("array_list"); |
2461 |
2529 |