tests/test_list.c

changeset 1026
ca20f9ffcb62
parent 1022
2911c1f4a570
--- a/tests/test_list.c	Wed Dec 18 15:36:45 2024 +0100
+++ b/tests/test_list.c	Wed Dec 18 15:40:13 2024 +0100
@@ -250,6 +250,30 @@
         CX_TEST_ASSERT(18 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int));
         CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 18, sizeof(int), &s, cx_cmp_int));
         CX_TEST_ASSERT(18 == cx_array_binary_search(array, 18, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 0
+        s = 40;
+        CX_TEST_ASSERT(0 == cx_array_binary_search_inf(array, 0, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 0, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search(array, 0, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 1, searched element is smaller
+        s = 30;
+        CX_TEST_ASSERT(1 == cx_array_binary_search_inf(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(1 == cx_array_binary_search(array, 1, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 1, searched element is larger
+        s = 50;
+        CX_TEST_ASSERT(0 == cx_array_binary_search_inf(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(1 == cx_array_binary_search_sup(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(1 == cx_array_binary_search(array, 1, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 1, element matches
+        s = 40;
+        CX_TEST_ASSERT(0 == cx_array_binary_search_inf(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search(array, 1, sizeof(int), &s, cx_cmp_int));
     }
 }
 

mercurial