| 159 | } |
| 160 | |
| 161 | static void test_heapPopulateDup(void) { |
| 162 | // create a new heap |
| 163 | heap_t *heap = Heap_new(cmp, NULL); |
| 164 | |
| 165 | int e = 7; // duplicated value |
| 166 | int n = 1000; // number of duplicates |
| 167 | |
| 168 | //-------------------------------------------------------------------------- |
| 169 | // populate heap |
| 170 | //-------------------------------------------------------------------------- |
| 171 | |
| 172 | // insert duplicated elements |
| 173 | for(int i = 0; i < n; i++) { |
| 174 | TEST_ASSERT(Heap_offer(&heap, &e) == 0); |
| 175 | } |
| 176 | |
| 177 | // validate number of elements in heap |
| 178 | TEST_ASSERT(Heap_count(heap) == n); |
| 179 | |
| 180 | // validate expected elements are indeed in heap |
| 181 | for(int i = 0; i < n; i++) { |
| 182 | TEST_ASSERT(Heap_contains_item(heap, &e) == 1); |
| 183 | } |
| 184 | |
| 185 | //-------------------------------------------------------------------------- |
| 186 | // empty heap |
| 187 | //-------------------------------------------------------------------------- |
| 188 | |
| 189 | // empty heap by polling until empty |
| 190 | int *elem; |
| 191 | for(int i = 0; i < n; i++) { |
| 192 | elem = (int*)Heap_peek(heap); |
| 193 | TEST_ASSERT(*elem == e); |
| 194 | |
| 195 | elem = Heap_poll(heap); |
| 196 | TEST_ASSERT(*elem == e); |
| 197 | } |
| 198 | |
| 199 | //-------------------------------------------------------------------------- |
| 200 | // validate heap is empty |
| 201 | //-------------------------------------------------------------------------- |
| 202 | |
| 203 | TEST_ASSERT(Heap_count(heap) == 0); |
| 204 | |
| 205 | // free heap |
| 206 | Heap_free(heap); |
| 207 | } |
| 208 | |
| 209 | static void test_heapPopulateRand(void) { |
| 210 | // seed random |
nothing calls this directly
no test coverage detected