add new ucx_list_sort test support/2.x

Tue, 05 Oct 2021 16:22:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 05 Oct 2021 16:22:48 +0200
branch
support/2.x
changeset 471
e9ef2637e101
parent 388
871a8ffe6c9d

add new ucx_list_sort test

test/list_tests.c file | annotate | diff | comparison | revisions
test/list_tests.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
--- a/test/list_tests.c	Mon Dec 30 09:52:44 2019 +0100
+++ b/test/list_tests.c	Tue Oct 05 16:22:48 2021 +0200
@@ -404,6 +404,52 @@
     ucx_list_free(list);
 }
 
+UCX_TEST(test_ucx_list_sort_int) {
+    int expected[] = {
+            14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
+            894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
+            1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
+            2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
+            3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
+            4785, 4791, 4801, 4859, 4903, 4973
+    };
+    int scrambled[] = {
+            759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
+            2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
+            2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
+            894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
+            3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
+            4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
+    };
+
+    UcxList *list = NULL;
+    for (int i = 0 ; i < 100 ; i++) {
+        list = ucx_list_append(list, scrambled+i);
+    }
+
+    list = ucx_list_sort(list, ucx_cmp_int, NULL);
+
+    UCX_TEST_BEGIN
+
+    UCX_TEST_ASSERT(list->prev == NULL, "prev field of first entry is not null");
+    UcxList *check = list;
+    UcxList *check_last = NULL;
+    for (int i = 0 ; i < 100 ; i++) {
+        UCX_TEST_ASSERT(*(int*)check->data == expected[i], "data not correctly sorted");
+        UCX_TEST_ASSERT(check->prev == check_last, "prev pointer not correct");
+        if (i < 99) {
+            UCX_TEST_ASSERT(check->next != NULL, "next pointer not correct");
+        }
+        check_last = check;
+        check = check->next;
+    }
+    UCX_TEST_ASSERT(check == NULL, "next pointer of last element not null");
+
+    UCX_TEST_END
+
+    ucx_list_free(list);
+}
+
 UCX_TEST(test_ucx_list_union) {
     UcxList *left = ucx_list_append(NULL, (void*)"this");
     left = ucx_list_append(left, (void*)"is");
--- a/test/list_tests.h	Mon Dec 30 09:52:44 2019 +0100
+++ b/test/list_tests.h	Tue Oct 05 16:22:48 2021 +0200
@@ -55,6 +55,7 @@
 UCX_TEST(test_ucx_list_remove);
 UCX_TEST(test_ucx_list_clone);
 UCX_TEST(test_ucx_list_sort);
+UCX_TEST(test_ucx_list_sort_int);
 UCX_TEST(test_ucx_list_union);
 UCX_TEST(test_ucx_list_intersection);
 UCX_TEST(test_ucx_list_difference);
--- a/test/main.c	Mon Dec 30 09:52:44 2019 +0100
+++ b/test/main.c	Tue Oct 05 16:22:48 2021 +0200
@@ -181,6 +181,7 @@
         ucx_test_register(suite, test_ucx_list_remove);
         ucx_test_register(suite, test_ucx_list_clone);
         ucx_test_register(suite, test_ucx_list_sort);
+        ucx_test_register(suite, test_ucx_list_sort_int);
         ucx_test_register(suite, test_ucx_list_union);
         ucx_test_register(suite, test_ucx_list_intersection);
         ucx_test_register(suite, test_ucx_list_difference);

mercurial