391 |
391 |
392 cxLinkedListDestroy(list); |
392 cxLinkedListDestroy(list); |
393 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
393 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
394 } |
394 } |
395 |
395 |
|
396 void test_hl_linked_list_sort(void) { |
|
397 int expected[] = { |
|
398 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
|
399 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
|
400 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
|
401 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
|
402 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
|
403 4785, 4791, 4801, 4859, 4903, 4973 |
|
404 }; |
|
405 int scrambled[] = { |
|
406 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
|
407 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
|
408 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
|
409 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
|
410 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
|
411 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
|
412 }; |
|
413 |
|
414 cxTestingAllocatorReset(); |
|
415 |
|
416 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
417 |
|
418 for (int i = 0 ; i < 100 ; i++) { |
|
419 cxListAdd(list, &scrambled[i]); |
|
420 } |
|
421 |
|
422 cxListSort(list); |
|
423 |
|
424 for (int i = 0 ; i < 100 ; i++) { |
|
425 CU_ASSERT_EQUAL(*(int*)cxListAt(list, i), expected[i]) |
|
426 } |
|
427 |
|
428 cxLinkedListDestroy(list); |
|
429 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
430 } |
|
431 |
396 void test_hl_ptr_linked_list_create(void) { |
432 void test_hl_ptr_linked_list_create(void) { |
397 cxTestingAllocatorReset(); |
433 cxTestingAllocatorReset(); |
398 |
434 |
399 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
435 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
400 |
436 |
556 |
592 |
557 cxLinkedListDestroy(list); |
593 cxLinkedListDestroy(list); |
558 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
594 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
559 } |
595 } |
560 |
596 |
|
597 void test_hl_ptr_linked_list_sort(void) { |
|
598 int expected[] = { |
|
599 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
|
600 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
|
601 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
|
602 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
|
603 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
|
604 4785, 4791, 4801, 4859, 4903, 4973 |
|
605 }; |
|
606 int scrambled[] = { |
|
607 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
|
608 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
|
609 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
|
610 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
|
611 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
|
612 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
|
613 }; |
|
614 |
|
615 cxTestingAllocatorReset(); |
|
616 |
|
617 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
618 |
|
619 for (int i = 0 ; i < 100 ; i++) { |
|
620 cxListAdd(list, &scrambled[i]); |
|
621 } |
|
622 |
|
623 cxListSort(list); |
|
624 |
|
625 for (int i = 0 ; i < 100 ; i++) { |
|
626 CU_ASSERT_EQUAL(*(int*)cxListAt(list, i), expected[i]) |
|
627 } |
|
628 |
|
629 cxLinkedListDestroy(list); |
|
630 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
631 } |
|
632 |
561 int main() { |
633 int main() { |
562 CU_pSuite suite = NULL; |
634 CU_pSuite suite = NULL; |
563 |
635 |
564 if (CUE_SUCCESS != CU_initialize_registry()) { |
636 if (CUE_SUCCESS != CU_initialize_registry()) { |
565 return CU_get_error(); |
637 return CU_get_error(); |
579 cu_add_test(suite, test_hl_linked_list_add); |
651 cu_add_test(suite, test_hl_linked_list_add); |
580 cu_add_test(suite, test_hl_linked_list_last); |
652 cu_add_test(suite, test_hl_linked_list_last); |
581 cu_add_test(suite, test_hl_linked_list_insert); |
653 cu_add_test(suite, test_hl_linked_list_insert); |
582 cu_add_test(suite, test_hl_linked_list_remove); |
654 cu_add_test(suite, test_hl_linked_list_remove); |
583 cu_add_test(suite, test_hl_linked_list_find); |
655 cu_add_test(suite, test_hl_linked_list_find); |
|
656 cu_add_test(suite, test_hl_linked_list_sort); |
584 |
657 |
585 suite = CU_add_suite("high level pointer linked list", NULL, NULL); |
658 suite = CU_add_suite("high level pointer linked list", NULL, NULL); |
586 |
659 |
587 cu_add_test(suite, test_hl_ptr_linked_list_create); |
660 cu_add_test(suite, test_hl_ptr_linked_list_create); |
588 cu_add_test(suite, test_hl_ptr_linked_list_add); |
661 cu_add_test(suite, test_hl_ptr_linked_list_add); |
589 cu_add_test(suite, test_hl_ptr_linked_list_last); |
662 cu_add_test(suite, test_hl_ptr_linked_list_last); |
590 cu_add_test(suite, test_hl_ptr_linked_list_insert); |
663 cu_add_test(suite, test_hl_ptr_linked_list_insert); |
591 cu_add_test(suite, test_hl_ptr_linked_list_remove); |
664 cu_add_test(suite, test_hl_ptr_linked_list_remove); |
592 cu_add_test(suite, test_hl_ptr_linked_list_find); |
665 cu_add_test(suite, test_hl_ptr_linked_list_find); |
|
666 cu_add_test(suite, test_hl_ptr_linked_list_sort); |
593 |
667 |
594 CU_basic_set_mode(UCX_CU_BRM); |
668 CU_basic_set_mode(UCX_CU_BRM); |
595 |
669 |
596 int exitcode; |
670 int exitcode; |
597 if (CU_basic_run_tests()) { |
671 if (CU_basic_run_tests()) { |