test/test_list.c

changeset 487
4bd19279778c
parent 486
d7ca126eab7f
child 488
9138acaa494b
equal deleted inserted replaced
486:d7ca126eab7f 487:4bd19279778c
123 123
124 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a) 124 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a)
125 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b) 125 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b)
126 } 126 }
127 127
128 void test_linked_list_find(void) {
129 int data[] = {2, 4, 6, 8};
130 void *list = create_test_data(4, data);
131 int s;
132
133 s = 2;
134 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
135 false, (CxListComparator) cmp_int, &s), 0)
136 s = 4;
137 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
138 false, (CxListComparator) cmp_int, &s), 1)
139 s = 6;
140 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
141 false, (CxListComparator) cmp_int, &s), 2)
142 s = 8;
143 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
144 false, (CxListComparator) cmp_int, &s), 3)
145 s = 10;
146 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
147 false, (CxListComparator) cmp_int, &s), 4)
148 s = -2;
149 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
150 false, (CxListComparator) cmp_int, &s), 4)
151 }
152
128 void test_linked_list_compare(void) { 153 void test_linked_list_compare(void) {
129 int a[] = {2, 4, 6, 8}; 154 int a[] = {2, 4, 6, 8};
130 int b[] = {2, 4, 6}; 155 int b[] = {2, 4, 6};
131 int c[] = {2, 4, 6, 9}; 156 int c[] = {2, 4, 6, 9};
132 157
133 void *la = create_test_data(4, a); 158 void *la = create_test_data(4, a);
134 void *lb = create_test_data(3, b); 159 void *lb = create_test_data(3, b);
135 void *lc = create_test_data(4, c); 160 void *lc = create_test_data(4, c);
136 161
137 CU_ASSERT_TRUE(0 < cx_linked_list_compare(la, lb, loc_next, loc_data, 162 CU_ASSERT_TRUE(0 < cx_linked_list_compare(la, lb, loc_next, loc_data,
138 0, (CxListComparator) cmp_int) 163 false, (CxListComparator) cmp_int)
139 ) 164 )
140 CU_ASSERT_TRUE(0 > cx_linked_list_compare(lb, la, loc_next, loc_data, 165 CU_ASSERT_TRUE(0 > cx_linked_list_compare(lb, la, loc_next, loc_data,
141 0, (CxListComparator) cmp_int) 166 false, (CxListComparator) cmp_int)
142 ) 167 )
143 CU_ASSERT_TRUE(0 < cx_linked_list_compare(lc, la, loc_next, loc_data, 168 CU_ASSERT_TRUE(0 < cx_linked_list_compare(lc, la, loc_next, loc_data,
144 0, (CxListComparator) cmp_int) 169 false, (CxListComparator) cmp_int)
145 ) 170 )
146 CU_ASSERT_TRUE(0 > cx_linked_list_compare(la, lc, loc_next, loc_data, 171 CU_ASSERT_TRUE(0 > cx_linked_list_compare(la, lc, loc_next, loc_data,
147 0, (CxListComparator) cmp_int) 172 false, (CxListComparator) cmp_int)
148 ) 173 )
149 CU_ASSERT_TRUE(0 == cx_linked_list_compare(la, la, loc_next, loc_data, 174 CU_ASSERT_TRUE(0 == cx_linked_list_compare(la, la, loc_next, loc_data,
150 0, (CxListComparator) cmp_int) 175 false, (CxListComparator) cmp_int)
151 ) 176 )
152 177
153 destroy_test_data(la); 178 destroy_test_data(la);
154 destroy_test_data(lb); 179 destroy_test_data(lb);
155 destroy_test_data(lc); 180 destroy_test_data(lc);
485 510
486 void *begin = create_test_data(100, scrambled); 511 void *begin = create_test_data(100, scrambled);
487 void *end = cx_linked_list_last(begin, loc_next); 512 void *end = cx_linked_list_last(begin, loc_next);
488 513
489 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, 514 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data,
490 0, (CxListComparator) cmp_int); 515 false, (CxListComparator) cmp_int);
491 516
492 struct node *check = begin; 517 struct node *check = begin;
493 struct node *check_last = NULL; 518 struct node *check_last = NULL;
494 CU_ASSERT_PTR_NULL(check->prev) 519 CU_ASSERT_PTR_NULL(check->prev)
495 CU_ASSERT_EQUAL(check->data, expected[0]) 520 CU_ASSERT_EQUAL(check->data, expected[0])
950 975
951 suite = CU_add_suite("low level linked list", NULL, NULL); 976 suite = CU_add_suite("low level linked list", NULL, NULL);
952 977
953 cu_add_test(suite, test_linked_list_link_unlink); 978 cu_add_test(suite, test_linked_list_link_unlink);
954 cu_add_test(suite, test_linked_list_at); 979 cu_add_test(suite, test_linked_list_at);
980 cu_add_test(suite, test_linked_list_find);
955 cu_add_test(suite, test_linked_list_compare); 981 cu_add_test(suite, test_linked_list_compare);
956 cu_add_test(suite, test_linked_list_prepend); 982 cu_add_test(suite, test_linked_list_prepend);
957 cu_add_test(suite, test_linked_list_add); 983 cu_add_test(suite, test_linked_list_add);
958 cu_add_test(suite, test_linked_list_insert); 984 cu_add_test(suite, test_linked_list_insert);
959 cu_add_test(suite, test_linked_list_insert_chain); 985 cu_add_test(suite, test_linked_list_insert_chain);

mercurial