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
     1.1 --- a/test/list_tests.c	Mon Dec 30 09:52:44 2019 +0100
     1.2 +++ b/test/list_tests.c	Tue Oct 05 16:22:48 2021 +0200
     1.3 @@ -404,6 +404,52 @@
     1.4      ucx_list_free(list);
     1.5  }
     1.6  
     1.7 +UCX_TEST(test_ucx_list_sort_int) {
     1.8 +    int expected[] = {
     1.9 +            14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
    1.10 +            894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
    1.11 +            1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
    1.12 +            2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
    1.13 +            3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
    1.14 +            4785, 4791, 4801, 4859, 4903, 4973
    1.15 +    };
    1.16 +    int scrambled[] = {
    1.17 +            759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
    1.18 +            2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
    1.19 +            2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
    1.20 +            894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
    1.21 +            3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
    1.22 +            4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
    1.23 +    };
    1.24 +
    1.25 +    UcxList *list = NULL;
    1.26 +    for (int i = 0 ; i < 100 ; i++) {
    1.27 +        list = ucx_list_append(list, scrambled+i);
    1.28 +    }
    1.29 +
    1.30 +    list = ucx_list_sort(list, ucx_cmp_int, NULL);
    1.31 +
    1.32 +    UCX_TEST_BEGIN
    1.33 +
    1.34 +    UCX_TEST_ASSERT(list->prev == NULL, "prev field of first entry is not null");
    1.35 +    UcxList *check = list;
    1.36 +    UcxList *check_last = NULL;
    1.37 +    for (int i = 0 ; i < 100 ; i++) {
    1.38 +        UCX_TEST_ASSERT(*(int*)check->data == expected[i], "data not correctly sorted");
    1.39 +        UCX_TEST_ASSERT(check->prev == check_last, "prev pointer not correct");
    1.40 +        if (i < 99) {
    1.41 +            UCX_TEST_ASSERT(check->next != NULL, "next pointer not correct");
    1.42 +        }
    1.43 +        check_last = check;
    1.44 +        check = check->next;
    1.45 +    }
    1.46 +    UCX_TEST_ASSERT(check == NULL, "next pointer of last element not null");
    1.47 +
    1.48 +    UCX_TEST_END
    1.49 +
    1.50 +    ucx_list_free(list);
    1.51 +}
    1.52 +
    1.53  UCX_TEST(test_ucx_list_union) {
    1.54      UcxList *left = ucx_list_append(NULL, (void*)"this");
    1.55      left = ucx_list_append(left, (void*)"is");
     2.1 --- a/test/list_tests.h	Mon Dec 30 09:52:44 2019 +0100
     2.2 +++ b/test/list_tests.h	Tue Oct 05 16:22:48 2021 +0200
     2.3 @@ -55,6 +55,7 @@
     2.4  UCX_TEST(test_ucx_list_remove);
     2.5  UCX_TEST(test_ucx_list_clone);
     2.6  UCX_TEST(test_ucx_list_sort);
     2.7 +UCX_TEST(test_ucx_list_sort_int);
     2.8  UCX_TEST(test_ucx_list_union);
     2.9  UCX_TEST(test_ucx_list_intersection);
    2.10  UCX_TEST(test_ucx_list_difference);
     3.1 --- a/test/main.c	Mon Dec 30 09:52:44 2019 +0100
     3.2 +++ b/test/main.c	Tue Oct 05 16:22:48 2021 +0200
     3.3 @@ -181,6 +181,7 @@
     3.4          ucx_test_register(suite, test_ucx_list_remove);
     3.5          ucx_test_register(suite, test_ucx_list_clone);
     3.6          ucx_test_register(suite, test_ucx_list_sort);
     3.7 +        ucx_test_register(suite, test_ucx_list_sort_int);
     3.8          ucx_test_register(suite, test_ucx_list_union);
     3.9          ucx_test_register(suite, test_ucx_list_intersection);
    3.10          ucx_test_register(suite, test_ucx_list_difference);

mercurial