test/test_list.c

changeset 498
435c9965b2dd
parent 497
b182a8b8a1af
child 499
3dc9075df822
equal deleted inserted replaced
497:b182a8b8a1af 498:435c9965b2dd
570 570
571 cxLinkedListDestroy(list); 571 cxLinkedListDestroy(list);
572 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 572 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
573 } 573 }
574 574
575 void test_hl_ptr_linked_list_create(void) {
576 cxTestingAllocatorReset();
577
578 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
579
580 CU_ASSERT_EQUAL(list->size, 0)
581 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
582 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
583 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *))
584 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
585
586 cxLinkedListDestroy(list);
587 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
588 }
589
575 void test_hl_linked_list_from_array(void) { 590 void test_hl_linked_list_from_array(void) {
576 cxTestingAllocatorReset(); 591 cxTestingAllocatorReset();
577 592
578 int data[] = {2, 4, 5, 7, 10, 15}; 593 int data[] = {2, 4, 5, 7, 10, 15};
579 594
609 CxList expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp); 624 CxList expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp);
610 CU_ASSERT_TRUE(0 == cxListCompare(list, expected)) 625 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
611 626
612 cxLinkedListDestroy(list); 627 cxLinkedListDestroy(list);
613 cxLinkedListDestroy(expected); 628 cxLinkedListDestroy(expected);
629 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
630 }
631
632 void test_hl_ptr_linked_list_add(void) {
633 cxTestingAllocatorReset();
634
635 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
636
637 int a = 5, b = 47, c = 13;
638
639 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
640 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0)
641 CU_ASSERT_EQUAL(cxListAdd(list, &c), 0)
642
643 CU_ASSERT_EQUAL(list->size, 3)
644 CU_ASSERT_TRUE(list->capacity >= list->size)
645
646 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
647 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
648 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
649
650 a = 9;
651 b = 10;
652 c = 11;
653
654 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9)
655 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10)
656 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11)
657
658 cxLinkedListDestroy(list);
614 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 659 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
615 } 660 }
616 661
617 void test_hl_linked_list_insert(void) { 662 void test_hl_linked_list_insert(void) {
618 cxTestingAllocatorReset(); 663 cxTestingAllocatorReset();
644 cxLinkedListDestroy(list); 689 cxLinkedListDestroy(list);
645 cxLinkedListDestroy(expected); 690 cxLinkedListDestroy(expected);
646 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 691 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
647 } 692 }
648 693
694 void test_hl_ptr_linked_list_insert(void) {
695 cxTestingAllocatorReset();
696
697 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
698
699 int a = 5, b = 47, c = 13, d = 42;
700
701 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0)
702 CU_ASSERT_EQUAL(list->size, 0)
703 CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0)
704 CU_ASSERT_EQUAL(list->size, 1)
705 CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0)
706 CU_ASSERT_EQUAL(list->size, 2)
707 CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0)
708 CU_ASSERT_EQUAL(list->size, 3)
709 CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0)
710
711 CU_ASSERT_EQUAL(list->size, 4)
712 CU_ASSERT_TRUE(list->capacity >= list->size)
713
714 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
715 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
716 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5)
717 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42)
718
719 cxLinkedListDestroy(list);
720 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
721 }
722
649 void test_hl_linked_list_remove(void) { 723 void test_hl_linked_list_remove(void) {
650 cxTestingAllocatorReset(); 724 cxTestingAllocatorReset();
651 725
652 int data[] = {5, 47, 42, 13}; 726 int data[] = {5, 47, 42, 13};
653 CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, 727 CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
684 758
685 cxLinkedListDestroy(list); 759 cxLinkedListDestroy(list);
686 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 760 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
687 } 761 }
688 762
763 void test_hl_ptr_linked_list_remove(void) {
764 cxTestingAllocatorReset();
765
766 int a = 5, b = 47, c = 42, d = 13;
767 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
768
769 cxListAdd(list, &a);
770 cxListAdd(list, &b);
771 cxListAdd(list, &c);
772 cxListAdd(list, &d);
773
774 CU_ASSERT_EQUAL(list->size, 4)
775 CU_ASSERT_TRUE(list->capacity >= list->size)
776
777 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0)
778
779 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
780 CU_ASSERT_EQUAL(list->size, 3)
781 CU_ASSERT_TRUE(list->capacity >= list->size)
782 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
783 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
784 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
785
786 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
787 CU_ASSERT_EQUAL(list->size, 2)
788 CU_ASSERT_TRUE(list->capacity >= list->size)
789 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
790 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
791
792 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
793 CU_ASSERT_EQUAL(list->size, 1)
794 CU_ASSERT_TRUE(list->capacity >= list->size)
795 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
796
797 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
798 CU_ASSERT_EQUAL(list->size, 0)
799 CU_ASSERT_TRUE(list->capacity >= list->size)
800
801 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
802
803 cxLinkedListDestroy(list);
804 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
805 }
806
689 void test_hl_linked_list_at(void) { 807 void test_hl_linked_list_at(void) {
690 cxTestingAllocatorReset(); 808 cxTestingAllocatorReset();
691 809
692 int data[] = {5, 47, 13}; 810 int data[] = {5, 47, 13};
693 CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, 811 CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
694 sizeof(int), 3, data); 812 sizeof(int), 3, data);
813
814 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
815 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
816 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
817 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
818
819 cxLinkedListDestroy(list);
820 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
821 }
822
823 void test_hl_ptr_linked_list_at(void) {
824 cxTestingAllocatorReset();
825
826 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
827
828 int a = 5, b = 47, c = 13;
829 cxListAdd(list, &a);
830 cxListAdd(list, &b);
831 cxListAdd(list, &c);
695 832
696 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) 833 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
697 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) 834 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
698 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) 835 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
699 CU_ASSERT_PTR_NULL(cxListAt(list, 3)) 836 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
721 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) 858 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
722 criteria = 9000; 859 criteria = 9000;
723 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) 860 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
724 criteria = -5; 861 criteria = -5;
725 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) 862 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
863
864 cxLinkedListDestroy(list);
865 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
866 }
867
868 void test_hl_ptr_linked_list_find(void) {
869 cxTestingAllocatorReset();
870
871 int a = 5, b = 47, c = 13, criteria;
872 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
873
874 cxListAdd(list, &a);
875 cxListAdd(list, &b);
876 cxListAdd(list, &c);
877
878 CU_ASSERT_EQUAL(list->size, 3)
879 CU_ASSERT_TRUE(list->capacity >= list->size)
880
881 criteria = 5;
882 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0)
883 criteria = 47;
884 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
885 criteria = 13;
886 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
887 criteria = 9000;
888 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
889 criteria = -5;
890 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
891 b = -5;
892 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
726 893
727 cxLinkedListDestroy(list); 894 cxLinkedListDestroy(list);
728 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 895 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
729 } 896 }
730 897
757 cxLinkedListDestroy(list); 924 cxLinkedListDestroy(list);
758 cxLinkedListDestroy(exp); 925 cxLinkedListDestroy(exp);
759 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 926 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
760 } 927 }
761 928
762 void test_hl_linked_list_iterator_impl(CxList list) {
763 int i = 0;
764 CxIterator iter = cxListBegin(list);
765 cx_foreach(int*, x, iter) {
766 CU_ASSERT_EQUAL(iter.index, (size_t) (i + 1) / 2)
767 CU_ASSERT_EQUAL(*x, i)
768 if (*x % 2 == 1) iter.remove = true;
769 i++;
770 }
771 CU_ASSERT_EQUAL(i, 10)
772 CU_ASSERT_EQUAL_FATAL(list->size, 5)
773 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 0)
774 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 2)
775 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 4)
776 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 6)
777 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 4), 8)
778 cxLinkedListDestroy(list);
779 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
780 }
781
782 void test_hl_linked_list_iterator(void) {
783 cxTestingAllocatorReset();
784 CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
785 for (int i = 0; i < 10; i++) {
786 cxListAdd(list, &i);
787 }
788 test_hl_linked_list_iterator_impl(list);
789 }
790
791 void test_hl_ptr_linked_list_iterator(void) {
792 cxTestingAllocatorReset();
793 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
794 int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
795 for (int i = 0; i < 10; i++) {
796 cxListAdd(list, &data[i]);
797 }
798 test_hl_linked_list_iterator_impl(list);
799 }
800
801 void test_hl_ptr_linked_list_create(void) {
802 cxTestingAllocatorReset();
803
804 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
805
806 CU_ASSERT_EQUAL(list->size, 0)
807 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
808 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
809 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *))
810 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
811
812 cxLinkedListDestroy(list);
813 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
814 }
815
816 void test_hl_ptr_linked_list_add(void) {
817 cxTestingAllocatorReset();
818
819 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
820
821 int a = 5, b = 47, c = 13;
822
823 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
824 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0)
825 CU_ASSERT_EQUAL(cxListAdd(list, &c), 0)
826
827 CU_ASSERT_EQUAL(list->size, 3)
828 CU_ASSERT_TRUE(list->capacity >= list->size)
829
830 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
831 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
832 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
833
834 a = 9;
835 b = 10;
836 c = 11;
837
838 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9)
839 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10)
840 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11)
841
842 cxLinkedListDestroy(list);
843 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
844 }
845
846 void test_hl_ptr_linked_list_insert(void) {
847 cxTestingAllocatorReset();
848
849 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
850
851 int a = 5, b = 47, c = 13, d = 42;
852
853 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0)
854 CU_ASSERT_EQUAL(list->size, 0)
855 CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0)
856 CU_ASSERT_EQUAL(list->size, 1)
857 CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0)
858 CU_ASSERT_EQUAL(list->size, 2)
859 CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0)
860 CU_ASSERT_EQUAL(list->size, 3)
861 CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0)
862
863 CU_ASSERT_EQUAL(list->size, 4)
864 CU_ASSERT_TRUE(list->capacity >= list->size)
865
866 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
867 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
868 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5)
869 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42)
870
871 cxLinkedListDestroy(list);
872 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
873 }
874
875 void test_hl_ptr_linked_list_remove(void) {
876 cxTestingAllocatorReset();
877
878 int a = 5, b = 47, c = 42, d = 13;
879 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
880
881 cxListAdd(list, &a);
882 cxListAdd(list, &b);
883 cxListAdd(list, &c);
884 cxListAdd(list, &d);
885
886 CU_ASSERT_EQUAL(list->size, 4)
887 CU_ASSERT_TRUE(list->capacity >= list->size)
888
889 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0)
890
891 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
892 CU_ASSERT_EQUAL(list->size, 3)
893 CU_ASSERT_TRUE(list->capacity >= list->size)
894 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
895 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
896 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
897
898 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
899 CU_ASSERT_EQUAL(list->size, 2)
900 CU_ASSERT_TRUE(list->capacity >= list->size)
901 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
902 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
903
904 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
905 CU_ASSERT_EQUAL(list->size, 1)
906 CU_ASSERT_TRUE(list->capacity >= list->size)
907 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
908
909 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
910 CU_ASSERT_EQUAL(list->size, 0)
911 CU_ASSERT_TRUE(list->capacity >= list->size)
912
913 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
914
915 cxLinkedListDestroy(list);
916 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
917 }
918
919 void test_hl_ptr_linked_list_at(void) {
920 cxTestingAllocatorReset();
921
922 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
923
924 int a = 5, b = 47, c = 13;
925 cxListAdd(list, &a);
926 cxListAdd(list, &b);
927 cxListAdd(list, &c);
928
929 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
930 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
931 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
932 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
933
934 cxLinkedListDestroy(list);
935 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
936 }
937
938 void test_hl_ptr_linked_list_find(void) {
939 cxTestingAllocatorReset();
940
941 int a = 5, b = 47, c = 13, criteria;
942 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
943
944 cxListAdd(list, &a);
945 cxListAdd(list, &b);
946 cxListAdd(list, &c);
947
948 CU_ASSERT_EQUAL(list->size, 3)
949 CU_ASSERT_TRUE(list->capacity >= list->size)
950
951 criteria = 5;
952 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0)
953 criteria = 47;
954 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
955 criteria = 13;
956 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
957 criteria = 9000;
958 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
959 criteria = -5;
960 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
961 b = -5;
962 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
963
964 cxLinkedListDestroy(list);
965 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
966 }
967
968 void test_hl_ptr_linked_list_sort(void) { 929 void test_hl_ptr_linked_list_sort(void) {
969 int expected[] = { 930 int expected[] = {
970 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, 931 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
971 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, 932 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
972 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, 933 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
999 960
1000 cxLinkedListDestroy(list); 961 cxLinkedListDestroy(list);
1001 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 962 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
1002 } 963 }
1003 964
965 void test_hl_linked_list_iterator_impl(CxList list) {
966 int i = 0;
967 CxIterator iter = cxListBegin(list);
968 cx_foreach(int*, x, iter) {
969 CU_ASSERT_EQUAL(iter.index, (size_t) (i + 1) / 2)
970 CU_ASSERT_EQUAL(*x, i)
971 if (*x % 2 == 1) iter.remove = true;
972 i++;
973 }
974 CU_ASSERT_EQUAL(i, 10)
975 CU_ASSERT_EQUAL_FATAL(list->size, 5)
976 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 0)
977 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 2)
978 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 4)
979 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 6)
980 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 4), 8)
981 cxLinkedListDestroy(list);
982 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
983 }
984
985 void test_hl_linked_list_iterator(void) {
986 cxTestingAllocatorReset();
987 CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
988 for (int i = 0; i < 10; i++) {
989 cxListAdd(list, &i);
990 }
991 test_hl_linked_list_iterator_impl(list);
992 }
993
994 void test_hl_ptr_linked_list_iterator(void) {
995 cxTestingAllocatorReset();
996 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
997 int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
998 for (int i = 0; i < 10; i++) {
999 cxListAdd(list, &data[i]);
1000 }
1001 test_hl_linked_list_iterator_impl(list);
1002 }
1003
1004 int main() { 1004 int main() {
1005 CU_pSuite suite = NULL; 1005 CU_pSuite suite = NULL;
1006 1006
1007 if (CUE_SUCCESS != CU_initialize_registry()) { 1007 if (CUE_SUCCESS != CU_initialize_registry()) {
1008 return CU_get_error(); 1008 return CU_get_error();

mercurial