test/list_tests.c

changeset 371
365b24f20f98
parent 323
b8c49e7a1dba
child 471
e9ef2637e101
     1.1 --- a/test/list_tests.c	Thu Nov 07 10:43:31 2019 +0100
     1.2 +++ b/test/list_tests.c	Sun Nov 24 17:57:25 2019 +0100
     1.3 @@ -403,3 +403,94 @@
     1.4      ucx_list_free(expected);
     1.5      ucx_list_free(list);
     1.6  }
     1.7 +
     1.8 +UCX_TEST(test_ucx_list_union) {
     1.9 +    UcxList *left = ucx_list_append(NULL, (void*)"this");
    1.10 +    left = ucx_list_append(left, (void*)"is");
    1.11 +    left = ucx_list_append(left, (void*)"a");
    1.12 +    left = ucx_list_append(left, (void*)"test");
    1.13 +
    1.14 +    UcxList *right = ucx_list_append(NULL, (void*)"to");
    1.15 +    right = ucx_list_append(right, (void*)"test");
    1.16 +    right = ucx_list_append(right, (void*)"set");
    1.17 +    right = ucx_list_append(right, (void*)"operations");
    1.18 +    
    1.19 +    UcxList *expected = ucx_list_append(NULL, (void*)"this");
    1.20 +    expected = ucx_list_append(expected, (void*)"is");
    1.21 +    expected = ucx_list_append(expected, (void*)"a");
    1.22 +    expected = ucx_list_append(expected, (void*)"test");
    1.23 +    expected = ucx_list_append(expected, (void*)"to");
    1.24 +    expected = ucx_list_append(expected, (void*)"set");
    1.25 +    expected = ucx_list_append(expected, (void*)"operations");
    1.26 +
    1.27 +    UcxList* result = ucx_list_union(left, right, ucx_cmp_str,
    1.28 +            NULL, NULL, NULL);
    1.29 +
    1.30 +    UCX_TEST_BEGIN
    1.31 +    UCX_TEST_ASSERT(ucx_list_equals(result, expected,
    1.32 +            ucx_cmp_str, NULL), "failed");
    1.33 +    UCX_TEST_END
    1.34 +
    1.35 +    ucx_list_free(result);
    1.36 +    ucx_list_free(expected);
    1.37 +    ucx_list_free(right);
    1.38 +    ucx_list_free(left);
    1.39 +}
    1.40 +
    1.41 +UCX_TEST(test_ucx_list_intersection) {
    1.42 +    UcxList *left = ucx_list_append(NULL, (void*)"this");
    1.43 +    left = ucx_list_append(left, (void*)"is");
    1.44 +    left = ucx_list_append(left, (void*)"a");
    1.45 +    left = ucx_list_append(left, (void*)"test");
    1.46 +
    1.47 +    UcxList *right = ucx_list_append(NULL, (void*)"to");
    1.48 +    right = ucx_list_append(right, (void*)"test");
    1.49 +    right = ucx_list_append(right, (void*)"a");
    1.50 +    right = ucx_list_append(right, (void*)"set");
    1.51 +    right = ucx_list_append(right, (void*)"operation");
    1.52 +    
    1.53 +    UcxList *expected = ucx_list_append(NULL, (void*)"a");
    1.54 +    expected = ucx_list_append(expected, (void*)"test");
    1.55 +
    1.56 +    UcxList* result = ucx_list_intersection(left, right, ucx_cmp_str,
    1.57 +            NULL, NULL, NULL);
    1.58 +
    1.59 +    UCX_TEST_BEGIN
    1.60 +    UCX_TEST_ASSERT(ucx_list_equals(result, expected,
    1.61 +            ucx_cmp_str, NULL), "failed");
    1.62 +    UCX_TEST_END
    1.63 +
    1.64 +    ucx_list_free(result);
    1.65 +    ucx_list_free(expected);
    1.66 +    ucx_list_free(right);
    1.67 +    ucx_list_free(left);
    1.68 +}
    1.69 +
    1.70 +UCX_TEST(test_ucx_list_difference) {
    1.71 +    UcxList *left = ucx_list_append(NULL, (void*)"this");
    1.72 +    left = ucx_list_append(left, (void*)"is");
    1.73 +    left = ucx_list_append(left, (void*)"a");
    1.74 +    left = ucx_list_append(left, (void*)"test");
    1.75 +
    1.76 +    UcxList *right = ucx_list_append(NULL, (void*)"to");
    1.77 +    right = ucx_list_append(right, (void*)"test");
    1.78 +    right = ucx_list_append(right, (void*)"this");
    1.79 +    right = ucx_list_append(right, (void*)"set");
    1.80 +    right = ucx_list_append(right, (void*)"operations");
    1.81 +    
    1.82 +    UcxList *expected = ucx_list_append(NULL, (void*)"is");
    1.83 +    expected = ucx_list_append(expected, (void*)"a");
    1.84 +    
    1.85 +    UcxList* result = ucx_list_difference(left, right, ucx_cmp_str,
    1.86 +            NULL, NULL, NULL);
    1.87 +
    1.88 +    UCX_TEST_BEGIN
    1.89 +    UCX_TEST_ASSERT(ucx_list_equals(result, expected,
    1.90 +            ucx_cmp_str, NULL), "failed");
    1.91 +    UCX_TEST_END
    1.92 +
    1.93 +    ucx_list_free(result);
    1.94 +    ucx_list_free(expected);
    1.95 +    ucx_list_free(right);
    1.96 +    ucx_list_free(left);
    1.97 +}

mercurial