1.1 --- a/tests/test_list.c Tue Jan 09 00:09:11 2024 +0100 1.2 +++ b/tests/test_list.c Tue Jan 09 21:25:08 2024 +0100 1.3 @@ -555,6 +555,86 @@ 1.4 destroy_nodes_test_data(expected); 1.5 } 1.6 1.7 + 1.8 +CX_TEST(test_empty_list_size) { 1.9 + CX_TEST_DO { 1.10 + CX_TEST_ASSERT(cxEmptyList->size == 0); 1.11 + CX_TEST_ASSERT(cxListSize(cxEmptyList) == 0); 1.12 + } 1.13 +} 1.14 + 1.15 +CX_TEST(test_empty_list_iterator) { 1.16 + CxList *list = cxEmptyList; 1.17 + 1.18 + CxIterator it1 = cxListIterator(list); 1.19 + CxIterator it2 = cxListBackwardsIterator(list); 1.20 + CxMutIterator it3 = cxListMutIterator(list); 1.21 + CxMutIterator it4 = cxListMutBackwardsIterator(list); 1.22 + 1.23 + CX_TEST_DO { 1.24 + CX_TEST_ASSERT(!cxIteratorValid(it1)); 1.25 + CX_TEST_ASSERT(!cxIteratorValid(it2)); 1.26 + CX_TEST_ASSERT(!cxIteratorValid(it3)); 1.27 + CX_TEST_ASSERT(!cxIteratorValid(it4)); 1.28 + 1.29 + int c = 0; 1.30 + cx_foreach(void*, data, it1) c++; 1.31 + cx_foreach(void*, data, it2) c++; 1.32 + cx_foreach(void*, data, it3) c++; 1.33 + cx_foreach(void*, data, it4) c++; 1.34 + CX_TEST_ASSERT(c == 0); 1.35 + } 1.36 +} 1.37 + 1.38 +CX_TEST(test_empty_list_noops) { 1.39 + CX_TEST_DO { 1.40 + CxList copy = *cxEmptyList; 1.41 + cxListSort(cxEmptyList); 1.42 + cxListClear(cxEmptyList); 1.43 + cxListDestroy(cxEmptyList); 1.44 + CX_TEST_ASSERT(0 == memcmp(©, cxEmptyList, sizeof(CxList))); // NOLINT(*-suspicious-memory-comparison) 1.45 + } 1.46 +} 1.47 + 1.48 +CX_TEST(test_empty_list_at) { 1.49 + CX_TEST_DO { 1.50 + CX_TEST_ASSERT(cxListAt(cxEmptyList, 0) == NULL); 1.51 + CX_TEST_ASSERT(cxListAt(cxEmptyList, 1) == NULL); 1.52 + } 1.53 +} 1.54 + 1.55 +CX_TEST(test_empty_list_find) { 1.56 + int x = 42, y = 1337; 1.57 + CX_TEST_DO { 1.58 + CX_TEST_ASSERT(cxListFind(cxEmptyList, &x) < 0); 1.59 + CX_TEST_ASSERT(cxListFind(cxEmptyList, &y) < 0); 1.60 + } 1.61 +} 1.62 + 1.63 +CX_TEST(test_empty_list_compare) { 1.64 + CxList *empty = cxEmptyList; 1.65 + CxList *ll = cxLinkedListCreateSimple(sizeof(int)); 1.66 + CxList *al = cxArrayListCreateSimple(sizeof(int), 8); 1.67 + int x = 5; 1.68 + CX_TEST_DO { 1.69 + CX_TEST_ASSERT(0 == cxListCompare(empty, cxEmptyList)); 1.70 + CX_TEST_ASSERT(0 == cxListCompare(ll, cxEmptyList)); 1.71 + CX_TEST_ASSERT(0 == cxListCompare(al, cxEmptyList)); 1.72 + CX_TEST_ASSERT(0 == cxListCompare(cxEmptyList, ll)); 1.73 + CX_TEST_ASSERT(0 == cxListCompare(cxEmptyList, al)); 1.74 + 1.75 + cxListAdd(ll, &x); 1.76 + cxListAdd(al, &x); 1.77 + 1.78 + CX_TEST_ASSERT(0 < cxListCompare(ll, cxEmptyList)); 1.79 + CX_TEST_ASSERT(0 < cxListCompare(al, cxEmptyList)); 1.80 + CX_TEST_ASSERT(0 > cxListCompare(cxEmptyList, ll)); 1.81 + CX_TEST_ASSERT(0 > cxListCompare(cxEmptyList, al)); 1.82 + } 1.83 + cxListDestroy(ll); 1.84 + cxListDestroy(al); 1.85 +} 1.86 + 1.87 CxTestSuite *cx_test_suite_array_list(void) { 1.88 CxTestSuite *suite = cx_test_suite_new("array_list"); 1.89 1.90 @@ -584,3 +664,15 @@ 1.91 return suite; 1.92 } 1.93 1.94 +CxTestSuite *cx_test_suite_empty_list(void) { 1.95 + CxTestSuite *suite = cx_test_suite_new("empty list dummy"); 1.96 + 1.97 + cx_test_register(suite, test_empty_list_size); 1.98 + cx_test_register(suite, test_empty_list_iterator); 1.99 + cx_test_register(suite, test_empty_list_noops); 1.100 + cx_test_register(suite, test_empty_list_at); 1.101 + cx_test_register(suite, test_empty_list_find); 1.102 + cx_test_register(suite, test_empty_list_compare); 1.103 + 1.104 + return suite; 1.105 +}