test/list_tests.c

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 371
365b24f20f98
permissions
-rw-r--r--

add new ucx_list_sort test

     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions are met:
     8  *
     9  *   1. Redistributions of source code must retain the above copyright
    10  *      notice, this list of conditions and the following disclaimer.
    11  *
    12  *   2. Redistributions in binary form must reproduce the above copyright
    13  *      notice, this list of conditions and the following disclaimer in the
    14  *      documentation and/or other materials provided with the distribution.
    15  *
    16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    26  * POSSIBILITY OF SUCH DAMAGE.
    27  */
    29 #include "list_tests.h"
    30 #include <ucx/utils.h>
    32 UCX_TEST(test_ucx_list_append) {
    33     UcxList *list, *first;
    34     list = first = ucx_list_append(NULL, (void*)"Hello");
    35     UCX_TEST_BEGIN
    37     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    38             "failed");
    40     list = ucx_list_append(list, (void*)" World!");
    42     UCX_TEST_ASSERT(list == first, "does not return first element");
    43     UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    44             "failed");
    45     UCX_TEST_ASSERT(list->next->prev == list, "failed");
    46     UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    47     UCX_TEST_END
    49     ucx_list_free(list);
    50 }
    52 UCX_TEST(test_ucx_list_prepend) {
    53     UcxList *list, *last;
    54     list = last = ucx_list_prepend(NULL, (void*)" World!");
    55     UCX_TEST_BEGIN
    57     list = ucx_list_prepend(list, (void*)"Hello");
    59     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    60             "failed");
    61     UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    62             "failed");
    63     UCX_TEST_ASSERT(list == last->prev, "does not return first element");
    64     UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    65     UCX_TEST_ASSERT(list->prev == NULL, "failed");
    67     UCX_TEST_END
    68     ucx_list_free(list);
    69 }
    71 UCX_TEST(test_ucx_list_equals) {
    72     const char *hello = "Hello";
    73     const char *world = " World!";
    74     UcxList *list = ucx_list_append(NULL, (void*)hello);
    75     list = ucx_list_append(list, (void*)world);
    76     UcxList *list2 = ucx_list_prepend(NULL, (void*)world);
    77     list2 = ucx_list_prepend(list2, (void*)hello);
    78     UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!");
    79     list3 = ucx_list_prepend(list3, (void*)"Hallo");
    80     UcxList *list4 = ucx_list_prepend(NULL, (void*)" World!");
    81     list4 = ucx_list_prepend(list4, (void*)"Hello");
    82     UCX_TEST_BEGIN
    84     UCX_TEST_ASSERT(ucx_list_equals(list, list4, ucx_cmp_str, NULL), "failed");
    85     UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_cmp_str, NULL), "failed");
    86     UCX_TEST_ASSERT(ucx_list_equals(list, list2, NULL, NULL), "failed");
    88     UCX_TEST_END
    89     ucx_list_free(list4);
    90     ucx_list_free(list3);
    91     ucx_list_free(list2);
    92     ucx_list_free(list);
    93 }
    95 UCX_TEST(test_ucx_list_concat) {
    96     UcxList *list = ucx_list_append(NULL, (void*)"Hello");
    97     list = ucx_list_append(list, (void*)" my ");
    98     UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
    99     list2 = ucx_list_prepend(list2, (void*)" sweet ");
   100     UCX_TEST_BEGIN
   102     list = ucx_list_concat(list, list2);
   103     list = ucx_list_concat(list, NULL);
   104     list = ucx_list_concat(NULL, list);
   106     UCX_TEST_ASSERT(!strncmp((const char*)list->data, "Hello", 5),
   107             "failed");
   108     UCX_TEST_ASSERT(!strncmp((const char*)list->next->data, " my ", 4),
   109             "failed");
   110     UCX_TEST_ASSERT(!strncmp((const char*)list->next->next->data, " sweet ", 7),
   111             "failed");
   112     UCX_TEST_ASSERT(!strncmp((const char*)ucx_list_last(list)->data,
   113             " World!", 7), "failed");
   115     UCX_TEST_ASSERT(list->prev == NULL, "failed");
   117     UCX_TEST_END
   118     // don't free list2, as it is freed by freeing list;
   119     ucx_list_free(list);
   120 }
   122 UCX_TEST(test_ucx_list_size) {
   123     UcxList *list = ucx_list_append(NULL, (void*)"This ");
   124     list = ucx_list_append(list, (void*)"list ");
   125     list = ucx_list_append(list, (void*)"has ");
   126     list = ucx_list_append(list, (void*)"size ");
   127     list = ucx_list_append(list, (void*)"5!");
   129     UCX_TEST_BEGIN
   131     UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed");
   132     list = ucx_list_remove(list, ucx_list_get(list, 2));
   133     UCX_TEST_ASSERT(ucx_list_size(list) == 4, "failed after removal");
   135     UCX_TEST_END
   136     ucx_list_free(list);
   137 }
   139 UCX_TEST(test_ucx_list_first) {
   140     UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   141     list = ucx_list_append(list, (void*)"the ");
   142     list = ucx_list_append(list, (void*)"first!");
   144     UCX_TEST_BEGIN
   146     const char* first = (const char*) (ucx_list_first(list)->data);
   148     UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
   149     UCX_TEST_ASSERT(ucx_list_first(list->next->next) == list, "failed");
   150     UCX_TEST_ASSERT(!ucx_list_first(NULL),
   151         "does not return NULL on an empty list");
   153     UCX_TEST_END
   154     ucx_list_free(list);
   155 }
   157 UCX_TEST(test_ucx_list_last) {
   158     UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   159     list = ucx_list_append(list, (void*)"the ");
   160     list = ucx_list_append(list, (void*)"last!");
   162     UCX_TEST_BEGIN
   164     const char* last = (const char*) (ucx_list_last(list->next->next)->data);
   166     UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
   167     UCX_TEST_ASSERT(ucx_list_last(list) == list->next->next, "failed");
   168     UCX_TEST_ASSERT(!ucx_list_last(NULL),
   169         "does not return NULL on an empty list");
   171     UCX_TEST_END
   172     ucx_list_free(list);
   173 }
   175 UCX_TEST(test_ucx_list_get) {
   176     UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   177     list = ucx_list_append(list, (void*)"the ");
   178     list = ucx_list_append(list, (void*)"mid!");
   180     UCX_TEST_BEGIN
   182     const char* first = (const char*) (ucx_list_get(list, 0)->data);
   183     const char* mid = (const char*) (ucx_list_get(list, 1)->data);
   184     const char* last = (const char*) (ucx_list_get(list, 2)->data);
   186     UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
   187     UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
   188     UCX_TEST_ASSERT(strncmp(last, "mid!", 4) == 0, "failed");
   189     UCX_TEST_ASSERT(!ucx_list_get(list, -1), "out of bounds (neg)");
   190     UCX_TEST_ASSERT(!ucx_list_get(list, 3), "out of bounds");
   191     UCX_TEST_ASSERT(!ucx_list_get(NULL, 0), "empty list");
   193     UCX_TEST_END
   194     ucx_list_free(list);
   195 }
   197 UCX_TEST(test_ucx_list_indexof) {
   198     UcxList *list = ucx_list_append(NULL, (void*)"Find ");
   199     list = ucx_list_append(list, (void*)"the ");
   200     list = ucx_list_append(list, (void*)"mid!");
   202     UCX_TEST_BEGIN
   204     UCX_TEST_ASSERT(ucx_list_indexof(list, list) == 0, "failed");
   205     UCX_TEST_ASSERT(ucx_list_indexof(list, list->next) == 1, "failed");
   206     UCX_TEST_ASSERT(ucx_list_indexof(list, ucx_list_get(list, 2)) == 2,
   207         "failed");
   209     UcxList *otherlist = ucx_list_append(NULL, (void*) "the ");
   210     UCX_TEST_ASSERT(ucx_list_indexof(list, otherlist) == -1, "failed");
   211     UCX_TEST_ASSERT(ucx_list_indexof(NULL, otherlist) == -1, "empty list");
   213     ucx_list_free(otherlist);
   215     UCX_TEST_END
   216     ucx_list_free(list);
   217 }
   219 UCX_TEST(test_ucx_list_find) {
   220     const char* teststr = "string!";
   221     UcxList *l = ucx_list_append(NULL, (void*)"find ");
   222     l = ucx_list_append(l, (void*)"some ");
   223     l = ucx_list_append(l, (void*)teststr);
   225     UCX_TEST_BEGIN
   227     UCX_TEST_ASSERT(ucx_list_find(l,(void*)"some ",ucx_cmp_str,NULL) == 1,
   228         "doesn't find string");
   229     UCX_TEST_ASSERT(ucx_list_find(l,(void*)"a",ucx_cmp_str,NULL) == -1,
   230         "finds non-existing string");
   232     UCX_TEST_ASSERT(ucx_list_find(l,(void*)teststr,NULL,NULL) == 2,
   233         "doesn't find integer without cmp_func");
   235     UCX_TEST_ASSERT(ucx_list_find(NULL, (void*)"some ",ucx_cmp_str,NULL) == -1,
   236         "empty list");
   238     UCX_TEST_END
   239     ucx_list_free(l);
   240 }
   242 UCX_TEST(test_ucx_list_contains) {
   243     UcxList *l = ucx_list_append(NULL, (void*)"Contains ");
   244     l = ucx_list_append(l, (void*)"a ");
   245     l = ucx_list_append(l, (void*)"string!");
   247     UCX_TEST_BEGIN
   249     UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_cmp_str,NULL),
   250         "false negative");
   251     UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_cmp_str,NULL),
   252         "false positive");
   254     UCX_TEST_END
   255     ucx_list_free(l);
   256 }
   258 UCX_TEST(test_ucx_list_remove) {
   259     UcxList *list = ucx_list_append(NULL, (void*)"Hello");
   260     list = ucx_list_append(list, (void*)"fucking");
   261     list = ucx_list_append(list, (void*)"World!");
   263     UcxList *list2 = ucx_list_append(NULL, (void*)"A");
   264     list2 = ucx_list_append(list2, (void*)"B");
   265     list2 = ucx_list_append(list2, (void*)"C");
   266     list2 = ucx_list_append(list2, (void*)"D");
   267     list2 = ucx_list_append(list2, (void*)"E");
   268     list2 = ucx_list_append(list2, (void*)"F");
   269     list2 = ucx_list_append(list2, (void*)"G");
   271     UCX_TEST_BEGIN
   273     list = ucx_list_remove(list, ucx_list_get(list, 1));
   275     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
   276             "failed");
   277     UCX_TEST_ASSERT(strncmp((const char*)list->next->data, "World!", 7) == 0,
   278             "failed");
   279     UCX_TEST_ASSERT(list->next->next == NULL, "failed");
   281     // remove first element: B, C, D, E, F, G
   282     list2 = ucx_list_remove(list2, list2);
   284     UCX_TEST_ASSERT(ucx_list_size(list2) == 6, "list2 has wrong size");
   285     UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0,
   286             "wrong first element");
   287     UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 5)->data, "G", 1)
   288             == 0, "wrong last element");
   290     // remove second element: B, D, E, F, G
   291     list2 = ucx_list_remove(list2, list2->next);
   293     UCX_TEST_ASSERT(ucx_list_size(list2) == 5, "list2 has wrong size");
   294     UCX_TEST_ASSERT(strncmp((const char*)list2->next->data, "D", 1) == 0,
   295             "wrong second element");
   297     UcxList *last = ucx_list_get(list2, 4);
   298     list2 = ucx_list_remove(list2, last->prev);
   300     UCX_TEST_ASSERT(ucx_list_size(list2) == 4, "list2 has wrong size");
   301     UCX_TEST_ASSERT(strncmp((const char*)last->prev->data, "E", 1) == 0,
   302             "wrong element");
   304     // remove last element: B, D, E, F
   305     list2 = ucx_list_remove(list2, last);
   306     UCX_TEST_ASSERT(ucx_list_size(list2) == 3, "list2 has wrong size");
   307     UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 2)->data, "E", 1)
   308             == 0, "wrong last element");
   310     UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0,
   311             "wrong element");
   313     list2 = ucx_list_remove(list2, list2);
   314     UCX_TEST_ASSERT(ucx_list_size(list2) == 2, "list2 has wrong size");
   315     list2 = ucx_list_remove(list2, list2);
   316     UCX_TEST_ASSERT(ucx_list_size(list2) == 1, "list2 has wrong size");
   317     list2 = ucx_list_remove(list2, list2);
   318     UCX_TEST_ASSERT(list2 == NULL, "list2 is not null");
   320     UCX_TEST_END
   321     ucx_list_free(list);
   322 }
   324 UCX_TEST(test_ucx_list_clone) {
   326     char *hello = (char*)malloc(6);
   327     char *world = (char*)malloc(8);
   329     memcpy(hello, "Hello", 6);
   330     memcpy(world, " World!", 8);
   332     UcxList *list = ucx_list_append(NULL, hello);
   333     list = ucx_list_append(list, world);
   335     UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL);
   336     UCX_TEST_BEGIN
   338     UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_cmp_str, NULL), "failed");
   339     UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
   340     UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
   342     UCX_TEST_END
   344     ucx_list_free_content(copy, free);
   346     free(world);
   347     free(hello);
   348     ucx_list_free(list);
   349     ucx_list_free(copy);
   350 }
   352 UCX_TEST(test_ucx_list_sort) {
   353     UcxList *list = ucx_list_append(NULL, (void*)"this");
   354     list = ucx_list_append(list, (void*)"is");
   355     list = ucx_list_append(list, (void*)"a");
   356     list = ucx_list_append(list, (void*)"test");
   357     list = ucx_list_append(list, (void*)"for");
   358     list = ucx_list_append(list, (void*)"partial");
   359     list = ucx_list_append(list, (void*)"correctness");
   360     list = ucx_list_append(list, (void*)"of");
   361     list = ucx_list_append(list, (void*)"the");
   362     list = ucx_list_append(list, (void*)"sort");
   363     list = ucx_list_append(list, (void*)"function");
   364     list = ucx_list_append(list, (void*)"that");
   365     list = ucx_list_append(list, (void*)"shall");
   366     list = ucx_list_append(list, (void*)"pass");
   367     list = ucx_list_append(list, (void*)"this");
   368     list = ucx_list_append(list, (void*)"test");
   370     UcxList *expected = ucx_list_append(NULL, (void*)"a");
   371     expected = ucx_list_append(expected, (void*)"correctness");
   372     expected = ucx_list_append(expected, (void*)"for");
   373     expected = ucx_list_append(expected, (void*)"function");
   374     expected = ucx_list_append(expected, (void*)"is");
   375     expected = ucx_list_append(expected, (void*)"of");
   376     expected = ucx_list_append(expected, (void*)"partial");
   377     expected = ucx_list_append(expected, (void*)"pass");
   378     expected = ucx_list_append(expected, (void*)"shall");
   379     expected = ucx_list_append(expected, (void*)"sort");
   380     expected = ucx_list_append(expected, (void*)"test");
   381     expected = ucx_list_append(expected, (void*)"test");
   382     expected = ucx_list_append(expected, (void*)"that");
   383     expected = ucx_list_append(expected, (void*)"the");
   384     expected = ucx_list_append(expected, (void*)"this");
   385     expected = ucx_list_append(expected, (void*)"this");
   387     list = ucx_list_sort(list, ucx_cmp_str, NULL);
   389     UCX_TEST_BEGIN
   390     UCX_TEST_ASSERT(
   391             ucx_list_equals(list, expected, ucx_cmp_str, NULL), "failed");
   392     UCX_TEST_ASSERT(ucx_list_size(list) == 16, "list has now a wrong size");
   393     UcxList *l = list;
   394     UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
   395     while (l->next != NULL) {
   396         UCX_TEST_ASSERT(l->next->prev == l, "next or prev pointer corrupted");
   397         l = l->next;
   398     }
   399     UCX_TEST_ASSERT(!ucx_list_sort(NULL, ucx_cmp_str, NULL),
   400         "failed to sort empty list");
   401     UCX_TEST_END
   403     ucx_list_free(expected);
   404     ucx_list_free(list);
   405 }
   407 UCX_TEST(test_ucx_list_sort_int) {
   408     int expected[] = {
   409             14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
   410             894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
   411             1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
   412             2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
   413             3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
   414             4785, 4791, 4801, 4859, 4903, 4973
   415     };
   416     int scrambled[] = {
   417             759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
   418             2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
   419             2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
   420             894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
   421             3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
   422             4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
   423     };
   425     UcxList *list = NULL;
   426     for (int i = 0 ; i < 100 ; i++) {
   427         list = ucx_list_append(list, scrambled+i);
   428     }
   430     list = ucx_list_sort(list, ucx_cmp_int, NULL);
   432     UCX_TEST_BEGIN
   434     UCX_TEST_ASSERT(list->prev == NULL, "prev field of first entry is not null");
   435     UcxList *check = list;
   436     UcxList *check_last = NULL;
   437     for (int i = 0 ; i < 100 ; i++) {
   438         UCX_TEST_ASSERT(*(int*)check->data == expected[i], "data not correctly sorted");
   439         UCX_TEST_ASSERT(check->prev == check_last, "prev pointer not correct");
   440         if (i < 99) {
   441             UCX_TEST_ASSERT(check->next != NULL, "next pointer not correct");
   442         }
   443         check_last = check;
   444         check = check->next;
   445     }
   446     UCX_TEST_ASSERT(check == NULL, "next pointer of last element not null");
   448     UCX_TEST_END
   450     ucx_list_free(list);
   451 }
   453 UCX_TEST(test_ucx_list_union) {
   454     UcxList *left = ucx_list_append(NULL, (void*)"this");
   455     left = ucx_list_append(left, (void*)"is");
   456     left = ucx_list_append(left, (void*)"a");
   457     left = ucx_list_append(left, (void*)"test");
   459     UcxList *right = ucx_list_append(NULL, (void*)"to");
   460     right = ucx_list_append(right, (void*)"test");
   461     right = ucx_list_append(right, (void*)"set");
   462     right = ucx_list_append(right, (void*)"operations");
   464     UcxList *expected = ucx_list_append(NULL, (void*)"this");
   465     expected = ucx_list_append(expected, (void*)"is");
   466     expected = ucx_list_append(expected, (void*)"a");
   467     expected = ucx_list_append(expected, (void*)"test");
   468     expected = ucx_list_append(expected, (void*)"to");
   469     expected = ucx_list_append(expected, (void*)"set");
   470     expected = ucx_list_append(expected, (void*)"operations");
   472     UcxList* result = ucx_list_union(left, right, ucx_cmp_str,
   473             NULL, NULL, NULL);
   475     UCX_TEST_BEGIN
   476     UCX_TEST_ASSERT(ucx_list_equals(result, expected,
   477             ucx_cmp_str, NULL), "failed");
   478     UCX_TEST_END
   480     ucx_list_free(result);
   481     ucx_list_free(expected);
   482     ucx_list_free(right);
   483     ucx_list_free(left);
   484 }
   486 UCX_TEST(test_ucx_list_intersection) {
   487     UcxList *left = ucx_list_append(NULL, (void*)"this");
   488     left = ucx_list_append(left, (void*)"is");
   489     left = ucx_list_append(left, (void*)"a");
   490     left = ucx_list_append(left, (void*)"test");
   492     UcxList *right = ucx_list_append(NULL, (void*)"to");
   493     right = ucx_list_append(right, (void*)"test");
   494     right = ucx_list_append(right, (void*)"a");
   495     right = ucx_list_append(right, (void*)"set");
   496     right = ucx_list_append(right, (void*)"operation");
   498     UcxList *expected = ucx_list_append(NULL, (void*)"a");
   499     expected = ucx_list_append(expected, (void*)"test");
   501     UcxList* result = ucx_list_intersection(left, right, ucx_cmp_str,
   502             NULL, NULL, NULL);
   504     UCX_TEST_BEGIN
   505     UCX_TEST_ASSERT(ucx_list_equals(result, expected,
   506             ucx_cmp_str, NULL), "failed");
   507     UCX_TEST_END
   509     ucx_list_free(result);
   510     ucx_list_free(expected);
   511     ucx_list_free(right);
   512     ucx_list_free(left);
   513 }
   515 UCX_TEST(test_ucx_list_difference) {
   516     UcxList *left = ucx_list_append(NULL, (void*)"this");
   517     left = ucx_list_append(left, (void*)"is");
   518     left = ucx_list_append(left, (void*)"a");
   519     left = ucx_list_append(left, (void*)"test");
   521     UcxList *right = ucx_list_append(NULL, (void*)"to");
   522     right = ucx_list_append(right, (void*)"test");
   523     right = ucx_list_append(right, (void*)"this");
   524     right = ucx_list_append(right, (void*)"set");
   525     right = ucx_list_append(right, (void*)"operations");
   527     UcxList *expected = ucx_list_append(NULL, (void*)"is");
   528     expected = ucx_list_append(expected, (void*)"a");
   530     UcxList* result = ucx_list_difference(left, right, ucx_cmp_str,
   531             NULL, NULL, NULL);
   533     UCX_TEST_BEGIN
   534     UCX_TEST_ASSERT(ucx_list_equals(result, expected,
   535             ucx_cmp_str, NULL), "failed");
   536     UCX_TEST_END
   538     ucx_list_free(result);
   539     ucx_list_free(expected);
   540     ucx_list_free(right);
   541     ucx_list_free(left);
   542 }

mercurial