added more tests for ucx_list_remove

Thu, 10 Apr 2014 11:32:59 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 10 Apr 2014 11:32:59 +0200
changeset 162
52dfe5f4ecd7
parent 161
1031dd910f8e
child 163
5ec9a2ca6328

added more tests for ucx_list_remove

test/list_tests.c file | annotate | diff | comparison | revisions
     1.1 --- a/test/list_tests.c	Thu Apr 10 11:18:12 2014 +0200
     1.2 +++ b/test/list_tests.c	Thu Apr 10 11:32:59 2014 +0200
     1.3 @@ -211,8 +211,16 @@
     1.4  
     1.5  UCX_TEST(test_ucx_list_remove) {
     1.6      UcxList *list = ucx_list_append(NULL, (void*)"Hello");
     1.7 -    list = ucx_list_append(list, (void*)" fucking");
     1.8 -    list = ucx_list_append(list, (void*)" World!");
     1.9 +    list = ucx_list_append(list, (void*)"fucking");
    1.10 +    list = ucx_list_append(list, (void*)"World!");
    1.11 +    
    1.12 +    UcxList *list2 = ucx_list_append(NULL, (void*)"A");
    1.13 +    list2 = ucx_list_append(list2, (void*)"B");
    1.14 +    list2 = ucx_list_append(list2, (void*)"C");
    1.15 +    list2 = ucx_list_append(list2, (void*)"D");
    1.16 +    list2 = ucx_list_append(list2, (void*)"E");
    1.17 +    list2 = ucx_list_append(list2, (void*)"F");
    1.18 +    list2 = ucx_list_append(list2, (void*)"G");
    1.19      
    1.20      UCX_TEST_BEGIN
    1.21      
    1.22 @@ -220,10 +228,49 @@
    1.23      
    1.24      UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    1.25              "failed");
    1.26 -    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    1.27 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, "World!", 7) == 0,
    1.28              "failed");
    1.29      UCX_TEST_ASSERT(list->next->next == NULL, "failed");
    1.30      
    1.31 +    // remove first element: B, C, D, E, F, G
    1.32 +    list2 = ucx_list_remove(list2, list2);
    1.33 +    
    1.34 +    UCX_TEST_ASSERT(ucx_list_size(list2) == 6, "list2 has wrong size");
    1.35 +    UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0,
    1.36 +            "wrong first element");
    1.37 +    UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 5)->data, "G", 1)
    1.38 +            == 0, "wrong last element");
    1.39 +    
    1.40 +    // remove second element: B, D, E, F, G
    1.41 +    list2 = ucx_list_remove(list2, list2->next);
    1.42 +    
    1.43 +    UCX_TEST_ASSERT(ucx_list_size(list2) == 5, "list2 has wrong size");
    1.44 +    UCX_TEST_ASSERT(strncmp((const char*)list2->next->data, "D", 1) == 0,
    1.45 +            "wrong second element");
    1.46 +    
    1.47 +    UcxList *last = ucx_list_get(list2, 4);
    1.48 +    list2 = ucx_list_remove(list2, last->prev);
    1.49 +    
    1.50 +    UCX_TEST_ASSERT(ucx_list_size(list2) == 4, "list2 has wrong size");
    1.51 +    UCX_TEST_ASSERT(strncmp((const char*)last->prev->data, "E", 1) == 0,
    1.52 +            "wrong element");
    1.53 +    
    1.54 +    // remove last element: B, D, E, F
    1.55 +    list2 = ucx_list_remove(list2, last);
    1.56 +    UCX_TEST_ASSERT(ucx_list_size(list2) == 3, "list2 has wrong size");
    1.57 +    UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 2)->data, "E", 1)
    1.58 +            == 0, "wrong last element");
    1.59 +    
    1.60 +    UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0,
    1.61 +            "wrong element");
    1.62 +    
    1.63 +    list2 = ucx_list_remove(list2, list2);
    1.64 +    UCX_TEST_ASSERT(ucx_list_size(list2) == 2, "list2 has wrong size");
    1.65 +    list2 = ucx_list_remove(list2, list2);
    1.66 +    UCX_TEST_ASSERT(ucx_list_size(list2) == 1, "list2 has wrong size");
    1.67 +    list2 = ucx_list_remove(list2, list2);
    1.68 +    UCX_TEST_ASSERT(list2 == NULL, "list2 is not null");
    1.69 +    
    1.70      UCX_TEST_END
    1.71      ucx_list_free(list);
    1.72  }

mercurial