Sat, 16 Apr 2022 22:12:47 +0200
add test for cxListCompare
Also increases size for low level sort test in order to
exceed the SBO limit.
src/linked_list.c | file | annotate | diff | comparison | revisions | |
test/test_list.cpp | file | annotate | diff | comparison | revisions |
--- a/src/linked_list.c Sat Apr 16 21:12:02 2022 +0200 +++ b/src/linked_list.c Sat Apr 16 22:12:47 2022 +0200 @@ -625,7 +625,7 @@ static void cx_ll_reverse(struct cx_list_s *list) { cx_linked_list *ll = (cx_linked_list *) list; - cx_linked_list_reverse((void **) &ll->begin, (void **) ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT); + cx_linked_list_reverse((void **) &ll->begin, (void **) &ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT); } static int cx_ll_compare(
--- a/test/test_list.cpp Sat Apr 16 21:12:02 2022 +0200 +++ b/test/test_list.cpp Sat Apr 16 22:12:47 2022 +0200 @@ -515,8 +515,8 @@ } TEST(LinkedList_LowLevel, cx_linked_list_sort) { - int_test_data<1000> testdata; - std::array<int, 1000> sorted{}; + int_test_data<1500> testdata; + std::array<int, 1500> sorted{}; std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), sorted.begin(), sorted.end()); auto scrambled = create_nodes_test_data(testdata.data.begin(), testdata.data.end()); @@ -657,7 +657,9 @@ void verifyAt(CxList *list) const { auto len = testdata_len; EXPECT_EQ(list->size, len); - cx_for_n (i, list->size) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); + cx_for_n (i, len) { + EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); + } EXPECT_EQ(cxListAt(list, list->size), nullptr); } @@ -731,6 +733,33 @@ int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50}; cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]); } + + void verifyReverse(CxList *list) const { + cxListReverse(list); + cx_for_n(i, testdata_len) { + ASSERT_EQ(*(int *) cxListAt(list, i), testdata.data[testdata_len - 1 - i]); + } + } + + static void verifyCompare(CxList *left, CxList *right) { + EXPECT_EQ(cxListCompare(left, right), 0); + int x = 42; + cxListAdd(left, &x); + ASSERT_GT(left->size, right->size); + EXPECT_GT(cxListCompare(left, right), 0); + EXPECT_LT(cxListCompare(right, left), 0); + cxListAdd(right, &x); + ASSERT_EQ(left->size, right->size); + EXPECT_EQ(cxListCompare(left, right), 0); + int a = 5, b = 10; + cxListInsert(left, 15, &a); + cxListInsert(right, 15, &b); + ASSERT_EQ(left->size, right->size); + EXPECT_LT(cxListCompare(left, right), 0); + EXPECT_GT(cxListCompare(right, left), 0); + *(int*)cxListAt(left, 15) = 10; + EXPECT_EQ(cxListCompare(left, right), 0); + } }; class LinkedList : public HighLevelTest { @@ -829,3 +858,24 @@ cx_for_n (i, 5) cxListAdd(list, &fivenums[i]); verifyInsertViaIterator(list); } + +TEST_F(LinkedList, cxListReverse) { + verifyReverse(linkedListFromTestData()); +} + +TEST_F(PointerLinkedList, cxListReverse) { + verifyReverse(pointerLinkedListFromTestData()); +} + +TEST_F(LinkedList, cxListCompare) { + auto left = linkedListFromTestData(); + auto right = linkedListFromTestData(); + verifyCompare(left, right); +} + +TEST_F(PointerLinkedList, cxListCompare) { + auto left = pointerLinkedListFromTestData(); + auto right = pointerLinkedListFromTestData(); + verifyCompare(left, right); +} +