141 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d8, cx_cmp_int)); |
141 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d8, cx_cmp_int)); |
142 CX_TEST_ASSERT(array_size == 18); |
142 CX_TEST_ASSERT(array_size == 18); |
143 CX_TEST_ASSERT(array_capacity >= 18); |
143 CX_TEST_ASSERT(array_capacity >= 18); |
144 |
144 |
145 CX_TEST_ASSERT(0 == memcmp(array, expected, 18 * sizeof(int))); |
145 CX_TEST_ASSERT(0 == memcmp(array, expected, 18 * sizeof(int))); |
|
146 } |
|
147 } |
|
148 |
|
149 CX_TEST(test_array_binary_search) { |
|
150 int array[18] = { |
|
151 40, 50, 51, 52, 54, 56, 57, 58, 60, |
|
152 62, 64, 65, 70, 75, 77, 78, 80, 90 |
|
153 }; |
|
154 |
|
155 CX_TEST_DO { |
|
156 cx_for_n(i, 18) { |
|
157 CX_TEST_ASSERT(i == cx_array_binary_search(array, 18, sizeof(int), &array[i], cx_cmp_int)); |
|
158 } |
|
159 |
|
160 int s = 58; |
|
161 CX_TEST_ASSERT(7 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
162 s = 60; |
|
163 CX_TEST_ASSERT(8 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
164 s = 59; |
|
165 CX_TEST_ASSERT(7 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
166 CX_TEST_ASSERT(18 == cx_array_binary_search(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
167 s = 79; |
|
168 CX_TEST_ASSERT(15 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
169 CX_TEST_ASSERT(18 == cx_array_binary_search(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
170 s = 66; |
|
171 CX_TEST_ASSERT(11 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
172 CX_TEST_ASSERT(18 == cx_array_binary_search(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
173 s = 69; |
|
174 CX_TEST_ASSERT(11 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int)); |
|
175 CX_TEST_ASSERT(18 == cx_array_binary_search(array, 18, sizeof(int), &s, cx_cmp_int)); |
146 } |
176 } |
147 } |
177 } |
148 |
178 |
149 typedef struct node { |
179 typedef struct node { |
150 struct node *next; |
180 struct node *next; |
1580 CxTestSuite *cx_test_suite_array_list(void) { |
1610 CxTestSuite *cx_test_suite_array_list(void) { |
1581 CxTestSuite *suite = cx_test_suite_new("array_list"); |
1611 CxTestSuite *suite = cx_test_suite_new("array_list"); |
1582 |
1612 |
1583 cx_test_register(suite, test_array_add); |
1613 cx_test_register(suite, test_array_add); |
1584 cx_test_register(suite, test_array_insert_sorted); |
1614 cx_test_register(suite, test_array_insert_sorted); |
|
1615 cx_test_register(suite, test_array_binary_search); |
1585 |
1616 |
1586 cx_test_register(suite, test_list_arl_create); |
1617 cx_test_register(suite, test_list_arl_create); |
1587 cx_test_register(suite, test_list_arl_create_simple); |
1618 cx_test_register(suite, test_list_arl_create_simple); |
1588 cx_test_register(suite, test_list_arl_create_simple_for_pointers); |
1619 cx_test_register(suite, test_list_arl_create_simple_for_pointers); |
1589 cx_test_register(suite, test_list_parl_destroy_no_destr); |
1620 cx_test_register(suite, test_list_parl_destroy_no_destr); |