tests/test_list.cpp

changeset 704
35f06c5eeb0e
parent 702
3390b58ad15a
child 763
741a2040fa33
--- a/tests/test_list.cpp	Sun May 21 11:52:58 2023 +0200
+++ b/tests/test_list.cpp	Sun May 21 14:03:21 2023 +0200
@@ -1477,3 +1477,80 @@
     EXPECT_TRUE(testingAllocator.verify());
 }
 
+TEST(EmptyList, Size) {
+    auto list = cxEmptyList;
+
+    EXPECT_EQ(list->size, 0);
+    EXPECT_EQ(cxListSize(list), 0);
+}
+
+TEST(EmptyList, Iterator) {
+    auto list = cxEmptyList;
+
+    auto it1 = cxListIterator(list);
+    auto it2 = cxListBackwardsIterator(list);
+    auto it3 = cxListMutIterator(list);
+    auto it4 = cxListMutBackwardsIterator(list);
+
+    EXPECT_FALSE(cxIteratorValid(it1));
+    EXPECT_FALSE(cxIteratorValid(it2));
+    EXPECT_FALSE(cxIteratorValid(it3));
+    EXPECT_FALSE(cxIteratorValid(it4));
+
+    int c = 0;
+    cx_foreach(void*, data, it1) c++;
+    cx_foreach(void*, data, it2) c++;
+    cx_foreach(void*, data, it3) c++;
+    cx_foreach(void*, data, it4) c++;
+    EXPECT_EQ(c, 0);
+}
+
+TEST(EmptyList, NoOps) {
+    auto list = cxEmptyList;
+
+    ASSERT_NO_FATAL_FAILURE(cxListSort(list));
+    ASSERT_NO_FATAL_FAILURE(cxListClear(list));
+    ASSERT_NO_FATAL_FAILURE(cxListDestroy(list));
+}
+
+TEST(EmptyList, At) {
+    auto list = cxEmptyList;
+
+    EXPECT_EQ(cxListAt(list, 0), nullptr);
+    EXPECT_EQ(cxListAt(list, 1), nullptr);
+}
+
+TEST(EmptyList, Find) {
+    auto list = cxEmptyList;
+
+    int x = 42, y = 1337;
+
+    EXPECT_LT(cxListFind(list, &x), 0);
+    EXPECT_LT(cxListFind(list, &y), 0);
+}
+
+TEST(EmptyList, Compare) {
+    auto empty = cxEmptyList;
+
+    auto ll = cxLinkedListCreateSimple(sizeof(int));
+    auto al = cxArrayListCreateSimple(sizeof(int), 8);
+
+    int x = 5;
+
+    EXPECT_EQ(cxListCompare(empty, cxEmptyList), 0);
+    EXPECT_EQ(cxListCompare(ll, cxEmptyList), 0);
+    EXPECT_EQ(cxListCompare(al, cxEmptyList), 0);
+    EXPECT_EQ(cxListCompare(cxEmptyList, ll), 0);
+    EXPECT_EQ(cxListCompare(cxEmptyList, al), 0);
+
+    cxListAdd(ll, &x);
+    cxListAdd(al, &x);
+
+    EXPECT_GT(cxListCompare(ll, cxEmptyList), 0);
+    EXPECT_GT(cxListCompare(al, cxEmptyList), 0);
+    EXPECT_LT(cxListCompare(cxEmptyList, ll), 0);
+    EXPECT_LT(cxListCompare(cxEmptyList, al), 0);
+
+    cxListDestroy(ll);
+    cxListDestroy(al);
+}

mercurial