test/test_list.c

changeset 469
0458bff0b1cd
parent 468
75ae1dccd101
child 473
1bd4b8c28722
     1.1 --- a/test/test_list.c	Tue Oct 05 16:33:11 2021 +0200
     1.2 +++ b/test/test_list.c	Wed Oct 06 14:10:19 2021 +0200
     1.3 @@ -393,6 +393,42 @@
     1.4      CU_ASSERT_TRUE(cxTestingAllocatorVerify())
     1.5  }
     1.6  
     1.7 +void test_hl_linked_list_sort(void) {
     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 +    cxTestingAllocatorReset();
    1.26 +
    1.27 +    CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
    1.28 +
    1.29 +    for (int i = 0 ; i < 100 ; i++) {
    1.30 +        cxListAdd(list, &scrambled[i]);
    1.31 +    }
    1.32 +
    1.33 +    cxListSort(list);
    1.34 +
    1.35 +    for (int i = 0 ; i < 100 ; i++) {
    1.36 +        CU_ASSERT_EQUAL(*(int*)cxListAt(list, i), expected[i])
    1.37 +    }
    1.38 +
    1.39 +    cxLinkedListDestroy(list);
    1.40 +    CU_ASSERT_TRUE(cxTestingAllocatorVerify())
    1.41 +}
    1.42 +
    1.43  void test_hl_ptr_linked_list_create(void) {
    1.44      cxTestingAllocatorReset();
    1.45  
    1.46 @@ -558,6 +594,42 @@
    1.47      CU_ASSERT_TRUE(cxTestingAllocatorVerify())
    1.48  }
    1.49  
    1.50 +void test_hl_ptr_linked_list_sort(void) {
    1.51 +    int expected[] = {
    1.52 +            14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
    1.53 +            894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
    1.54 +            1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
    1.55 +            2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
    1.56 +            3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
    1.57 +            4785, 4791, 4801, 4859, 4903, 4973
    1.58 +    };
    1.59 +    int scrambled[] = {
    1.60 +            759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
    1.61 +            2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
    1.62 +            2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
    1.63 +            894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
    1.64 +            3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
    1.65 +            4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
    1.66 +    };
    1.67 +
    1.68 +    cxTestingAllocatorReset();
    1.69 +
    1.70 +    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
    1.71 +
    1.72 +    for (int i = 0 ; i < 100 ; i++) {
    1.73 +        cxListAdd(list, &scrambled[i]);
    1.74 +    }
    1.75 +
    1.76 +    cxListSort(list);
    1.77 +
    1.78 +    for (int i = 0 ; i < 100 ; i++) {
    1.79 +        CU_ASSERT_EQUAL(*(int*)cxListAt(list, i), expected[i])
    1.80 +    }
    1.81 +
    1.82 +    cxLinkedListDestroy(list);
    1.83 +    CU_ASSERT_TRUE(cxTestingAllocatorVerify())
    1.84 +}
    1.85 +
    1.86  int main() {
    1.87      CU_pSuite suite = NULL;
    1.88  
    1.89 @@ -581,6 +653,7 @@
    1.90      cu_add_test(suite, test_hl_linked_list_insert);
    1.91      cu_add_test(suite, test_hl_linked_list_remove);
    1.92      cu_add_test(suite, test_hl_linked_list_find);
    1.93 +    cu_add_test(suite, test_hl_linked_list_sort);
    1.94  
    1.95      suite = CU_add_suite("high level pointer linked list", NULL, NULL);
    1.96  
    1.97 @@ -590,6 +663,7 @@
    1.98      cu_add_test(suite, test_hl_ptr_linked_list_insert);
    1.99      cu_add_test(suite, test_hl_ptr_linked_list_remove);
   1.100      cu_add_test(suite, test_hl_ptr_linked_list_find);
   1.101 +    cu_add_test(suite, test_hl_ptr_linked_list_sort);
   1.102  
   1.103      CU_basic_set_mode(UCX_CU_BRM);
   1.104  

mercurial