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

Function test_heapPopulate

tests/unit/test_heap.c:112–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static void test_heapPopulate(void) {
113 // create a new heap
114 heap_t *heap = Heap_new(cmp, NULL);
115
116 int n = 10;
117 int elements[n];
118
119 //--------------------------------------------------------------------------
120 // populate heap
121 //--------------------------------------------------------------------------
122
123 // insert elements 0..9
124 for(int i = 0; i < n; i++) {
125 elements[i] = i;
126 TEST_ASSERT(Heap_offer(&heap, elements + i) == 0);
127 }
128
129 // validate number of elements in heap
130 TEST_ASSERT(Heap_count(heap) == n);
131
132 // validate expected elements are indeed in heap
133 for(int i = 0; i < n; i++) {
134 TEST_ASSERT(Heap_contains_item(heap, elements + i) == 1);
135 }
136
137 //--------------------------------------------------------------------------
138 // empty heap
139 //--------------------------------------------------------------------------
140
141 // empty heap by polling until empty
142 int *elem;
143 for(int i = 0; i < n; i++) {
144 elem = (int*)Heap_peek(heap);
145 TEST_ASSERT(*elem == i);
146
147 elem = Heap_poll(heap);
148 TEST_ASSERT(*elem == i);
149 }
150
151 //--------------------------------------------------------------------------
152 // validate heap is empty
153 //--------------------------------------------------------------------------
154
155 TEST_ASSERT(Heap_count(heap) == 0);
156
157 // free heap
158 Heap_free(heap);
159}
160
161static void test_heapPopulateDup(void) {
162 // create a new heap

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