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

Function test_heapPopulateDup

tests/unit/test_heap.c:161–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161static 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
209static void test_heapPopulateRand(void) {
210 // seed random

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected