diff -r c9d008861178 -r 7340c4255f1f tests/test_list.cpp --- a/tests/test_list.cpp Wed Feb 08 20:26:26 2023 +0100 +++ b/tests/test_list.cpp Wed Feb 15 16:48:11 2023 +0100 @@ -735,13 +735,13 @@ result = cxListSwap(list, 16, 17); EXPECT_NE(0, result); - auto iter = cxListBegin(list); + auto iter = cxListIterator(list); cx_foreach(int*, e, iter) { EXPECT_EQ(*e, swapped[iter.index]); } - // TODO: replace with backward iterator - cx_for_n(i, 16) { - EXPECT_EQ(*((int *) cxListAt(list, i)), swapped[i]); + iter = cxListBackwardsIterator(list); + cx_foreach(int*, e, iter) { + EXPECT_EQ(*e, swapped[iter.index]); } } @@ -777,16 +777,44 @@ } void verifyIterator(CxList *list) const { - int i = 0; - auto iter = cxListBeginMut(list); + auto iter = cxListIterator(list); + size_t i = 0; cx_foreach(int*, x, iter) { - ASSERT_EQ(iter.index, (size_t) (i + 1) / 2); - ASSERT_EQ(*x, testdata.data[i]); - if (i % 2 == 1) cxIteratorFlagRemoval(iter); + ASSERT_EQ(i, iter.index); + EXPECT_EQ(*x, testdata.data[iter.index]); i++; } + ASSERT_EQ(i, list->size); + iter = cxListBackwardsIterator(list); + cx_foreach(int*, x, iter) { + ASSERT_EQ(i - 1, iter.index); + EXPECT_EQ(*x, testdata.data[iter.index]); + i--; + } + ASSERT_EQ(i, 0); auto len = testdata_len; - EXPECT_EQ(i, len); + i = len / 2; + auto mut_iter = cxListMutIteratorAt(list, i); + size_t j = 0; + cx_foreach(int*, x, mut_iter) { + ASSERT_EQ(mut_iter.index, len / 2 + j / 2); + ASSERT_EQ(*x, testdata.data[i]); + if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter); + i++; + j++; + } + ASSERT_EQ(i, len); + i = len / 2; + j = 0; + mut_iter = cxListMutBackwardsIteratorAt(list, i - 1); + cx_foreach(int*, x, mut_iter) { + ASSERT_EQ(mut_iter.index, len / 2 - 1 - j); + ASSERT_EQ(*x, testdata.data[i - 1]); + if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter); + i--; + j++; + } + ASSERT_EQ(i, 0); ASSERT_EQ(list->size, len / 2); cx_for_n(j, len / 2) ASSERT_EQ(*(int *) cxListAt(list, j), testdata.data[j * 2]); } @@ -794,7 +822,7 @@ static void verifyInsertViaIterator(CxList *list) { int newdata[] = {10, 20, 30, 40, 50}; - auto iter = cxListMutIterator(list, 2); + auto iter = cxListMutIteratorAt(list, 2); EXPECT_TRUE(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 2); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); @@ -807,16 +835,16 @@ EXPECT_EQ(iter.index, 3); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); - iter = cxListBeginMut(list); + iter = cxListMutIterator(list); cxListInsertBefore(&iter, &newdata[2]); EXPECT_TRUE(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 1); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0); - iter = cxListMutIterator(list, list->size); + iter = cxListMutIteratorAt(list, list->size); cxListInsertBefore(&iter, &newdata[3]); EXPECT_FALSE(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 9); - iter = cxListMutIterator(list, list->size); + iter = cxListMutIteratorAt(list, list->size); cxListInsertAfter(&iter, &newdata[4]); EXPECT_FALSE(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 10);