95 CX_TEST_ASSERT(heaparray[5] == 47); |
95 CX_TEST_ASSERT(heaparray[5] == 47); |
96 CX_TEST_ASSERT(heaparray_size == 6); |
96 CX_TEST_ASSERT(heaparray_size == 6); |
97 CX_TEST_ASSERT(heaparray_capacity >= 6); |
97 CX_TEST_ASSERT(heaparray_capacity >= 6); |
98 } |
98 } |
99 free(heaparray); |
99 free(heaparray); |
|
100 } |
|
101 |
|
102 CX_TEST(test_array_insert_sorted) { |
|
103 int d1 = 50; |
|
104 int d2 = 80; |
|
105 int d3 = 60; |
|
106 int d4 = 40; |
|
107 int d5 = 70; |
|
108 int d6a[6] = {52, 54, 56, 62, 64, 75}; |
|
109 int d7a[6] = {51, 57, 58, 65, 77, 78}; |
|
110 int d8 = 90; |
|
111 int expected[18] = { |
|
112 40, 50, 51, 52, 54, 56, 57, 58, 60, |
|
113 62, 64, 65, 70, 75, 77, 78, 80, 90 |
|
114 }; |
|
115 |
|
116 CX_ARRAY_DECLARE(int, array); |
|
117 cx_array_initialize(array, 4); |
|
118 |
|
119 CX_TEST_DO { |
|
120 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d1, cx_cmp_int)); |
|
121 CX_TEST_ASSERT(array_size == 1); |
|
122 CX_TEST_ASSERT(array_capacity == 4); |
|
123 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d2, cx_cmp_int)); |
|
124 CX_TEST_ASSERT(array_size == 2); |
|
125 CX_TEST_ASSERT(array_capacity == 4); |
|
126 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d3, cx_cmp_int)); |
|
127 CX_TEST_ASSERT(array_size == 3); |
|
128 CX_TEST_ASSERT(array_capacity == 4); |
|
129 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d4, cx_cmp_int)); |
|
130 CX_TEST_ASSERT(array_size == 4); |
|
131 CX_TEST_ASSERT(array_capacity == 4); |
|
132 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d5, cx_cmp_int)); |
|
133 CX_TEST_ASSERT(array_size == 5); |
|
134 CX_TEST_ASSERT(array_capacity >= 5); |
|
135 CX_TEST_ASSERT(0 == cx_array_simple_insert_sorted(array, d6a, 6, cx_cmp_int)); |
|
136 CX_TEST_ASSERT(array_size == 11); |
|
137 CX_TEST_ASSERT(array_capacity >= 11); |
|
138 CX_TEST_ASSERT(0 == cx_array_simple_insert_sorted(array, d7a, 6, cx_cmp_int)); |
|
139 CX_TEST_ASSERT(array_size == 17); |
|
140 CX_TEST_ASSERT(array_capacity >= 17); |
|
141 CX_TEST_ASSERT(0 == cx_array_simple_add_sorted(array, d8, cx_cmp_int)); |
|
142 CX_TEST_ASSERT(array_size == 18); |
|
143 CX_TEST_ASSERT(array_capacity >= 18); |
|
144 |
|
145 CX_TEST_ASSERT(0 == memcmp(array, expected, 18 * sizeof(int))); |
|
146 } |
100 } |
147 } |
101 |
148 |
102 typedef struct node { |
149 typedef struct node { |
103 struct node *next; |
150 struct node *next; |
104 struct node *prev; |
151 struct node *prev; |
1532 |
1579 |
1533 CxTestSuite *cx_test_suite_array_list(void) { |
1580 CxTestSuite *cx_test_suite_array_list(void) { |
1534 CxTestSuite *suite = cx_test_suite_new("array_list"); |
1581 CxTestSuite *suite = cx_test_suite_new("array_list"); |
1535 |
1582 |
1536 cx_test_register(suite, test_array_add); |
1583 cx_test_register(suite, test_array_add); |
|
1584 cx_test_register(suite, test_array_insert_sorted); |
1537 |
1585 |
1538 cx_test_register(suite, test_list_arl_create); |
1586 cx_test_register(suite, test_list_arl_create); |
1539 cx_test_register(suite, test_list_arl_create_simple); |
1587 cx_test_register(suite, test_list_arl_create_simple); |
1540 cx_test_register(suite, test_list_arl_create_simple_for_pointers); |
1588 cx_test_register(suite, test_list_arl_create_simple_for_pointers); |
1541 cx_test_register(suite, test_list_parl_destroy_no_destr); |
1589 cx_test_register(suite, test_list_parl_destroy_no_destr); |