MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_heapRemoveElement

Function test_heapRemoveElement

tests/unit/test_heap.c:268–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268static void test_heapRemoveElement(void) {
269 // create a new heap
270 heap_t *heap = Heap_new(cmp, NULL);
271
272 //--------------------------------------------------------------------------
273 // populate heap
274 //--------------------------------------------------------------------------
275
276 int n = 10;
277 int elements[n];
278
279 // insert elements 0..9
280 for(int i = 0; i < n; i++) {
281 elements[i] = i;
282 TEST_ASSERT(Heap_offer(&heap, elements + i) == 0);
283 }
284
285 // validate number of elements in heap
286 TEST_ASSERT(Heap_count(heap) == n);
287
288 //--------------------------------------------------------------------------
289 // remove heap head
290 //--------------------------------------------------------------------------
291
292 int elem;
293 elem = *(int*)Heap_remove_item(heap, elements + 0);
294
295 TEST_ASSERT(elem == elements[0]);
296
297 // validate new head
298 elem = *(int*)Heap_peek(heap);
299 TEST_ASSERT(elem == 1);
300
301 //--------------------------------------------------------------------------
302 // remove 2 from heap
303 //--------------------------------------------------------------------------
304
305 elem = *(int*)Heap_remove_item(heap, elements + 2);
306 TEST_ASSERT(elem == elements[2]);
307
308 // remove heap head
309 elem = *(int*)Heap_poll(heap);
310 TEST_ASSERT(elem == 1);
311
312 // validate new head
313 elem = *(int*)Heap_peek(heap);
314 TEST_ASSERT(elem == 3);
315
316 //--------------------------------------------------------------------------
317 // remove last element
318 //--------------------------------------------------------------------------
319
320 elem = *(int*)Heap_remove_item(heap, elements + 9);
321 TEST_ASSERT(elem == elements[9]);
322
323 // validate new head
324 elem = *(int*)Heap_peek(heap);
325 TEST_ASSERT(elem == 3);

Callers

nothing calls this directly

Calls 7

Heap_newFunction · 0.85
Heap_offerFunction · 0.85
Heap_countFunction · 0.85
Heap_remove_itemFunction · 0.85
Heap_peekFunction · 0.85
Heap_pollFunction · 0.85
Heap_freeFunction · 0.85

Tested by

no test coverage detected