--- a/tests/test_list.cpp Mon Dec 18 16:14:07 2023 +0100 +++ b/tests/test_list.cpp Mon Dec 18 18:22:53 2023 +0100 @@ -699,6 +699,27 @@ EXPECT_NE(cxListRemove(list, testdata_len), 0); } + void verifyFindRemove(CxList *list) const { + size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp) + int val = testdata.data[exp]; + // randomly picked number could occur earlier in list - find first position + cx_for_n (i, exp) { + if (testdata.data[i] == val) { + exp = i; + break; + } + } + EXPECT_EQ(cxListSize(list), testdata_len); + EXPECT_EQ(cxListFind(list, &val), exp); + EXPECT_EQ(cxListFindRemove(list, &val), exp); + EXPECT_EQ(cxListSize(list), testdata_len - 1); + EXPECT_NE(cxListFind(list, &val), exp); + + int notinlist = -1; + EXPECT_LT(cxListFindRemove(list, ¬inlist), 0); + EXPECT_EQ(cxListSize(list), testdata_len - 1); + } + static void verifyClear(CxList *list) { cxListClear(list); EXPECT_EQ(0, cxListSize(list)); @@ -1133,6 +1154,22 @@ verifyRemove(pointerArrayListFromTestData()); } +TEST_F(LinkedList, cxListFindRemove) { + verifyFindRemove(linkedListFromTestData()); +} + +TEST_F(PointerLinkedList, cxListFindRemove) { + verifyFindRemove(pointerLinkedListFromTestData()); +} + +TEST_F(ArrayList, cxListFindRemove) { + verifyFindRemove(arrayListFromTestData()); +} + +TEST_F(PointerArrayList, cxListFindRemove) { + verifyFindRemove(pointerArrayListFromTestData()); +} + TEST_F(LinkedList, cxListClear) { verifyClear(linkedListFromTestData()); }