tests/test_list.cpp

changeset 764
ccbdbd088455
parent 763
741a2040fa33
child 790
42877968260c
equal deleted inserted replaced
763:741a2040fa33 764:ccbdbd088455
697 EXPECT_EQ(*(int *) cxListAt(list, 1), testdata.data[3]); 697 EXPECT_EQ(*(int *) cxListAt(list, 1), testdata.data[3]);
698 698
699 EXPECT_NE(cxListRemove(list, testdata_len), 0); 699 EXPECT_NE(cxListRemove(list, testdata_len), 0);
700 } 700 }
701 701
702 void verifyFindRemove(CxList *list) const {
703 size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
704 int val = testdata.data[exp];
705 // randomly picked number could occur earlier in list - find first position
706 cx_for_n (i, exp) {
707 if (testdata.data[i] == val) {
708 exp = i;
709 break;
710 }
711 }
712 EXPECT_EQ(cxListSize(list), testdata_len);
713 EXPECT_EQ(cxListFind(list, &val), exp);
714 EXPECT_EQ(cxListFindRemove(list, &val), exp);
715 EXPECT_EQ(cxListSize(list), testdata_len - 1);
716 EXPECT_NE(cxListFind(list, &val), exp);
717
718 int notinlist = -1;
719 EXPECT_LT(cxListFindRemove(list, &notinlist), 0);
720 EXPECT_EQ(cxListSize(list), testdata_len - 1);
721 }
722
702 static void verifyClear(CxList *list) { 723 static void verifyClear(CxList *list) {
703 cxListClear(list); 724 cxListClear(list);
704 EXPECT_EQ(0, cxListSize(list)); 725 EXPECT_EQ(0, cxListSize(list));
705 } 726 }
706 727
1131 1152
1132 TEST_F(PointerArrayList, cxListRemove) { 1153 TEST_F(PointerArrayList, cxListRemove) {
1133 verifyRemove(pointerArrayListFromTestData()); 1154 verifyRemove(pointerArrayListFromTestData());
1134 } 1155 }
1135 1156
1157 TEST_F(LinkedList, cxListFindRemove) {
1158 verifyFindRemove(linkedListFromTestData());
1159 }
1160
1161 TEST_F(PointerLinkedList, cxListFindRemove) {
1162 verifyFindRemove(pointerLinkedListFromTestData());
1163 }
1164
1165 TEST_F(ArrayList, cxListFindRemove) {
1166 verifyFindRemove(arrayListFromTestData());
1167 }
1168
1169 TEST_F(PointerArrayList, cxListFindRemove) {
1170 verifyFindRemove(pointerArrayListFromTestData());
1171 }
1172
1136 TEST_F(LinkedList, cxListClear) { 1173 TEST_F(LinkedList, cxListClear) {
1137 verifyClear(linkedListFromTestData()); 1174 verifyClear(linkedListFromTestData());
1138 } 1175 }
1139 1176
1140 TEST_F(PointerLinkedList, cxListClear) { 1177 TEST_F(PointerLinkedList, cxListClear) {

mercurial