fix(heap): finally fixed that pop bug
All checks were successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/test-mem Pipeline was successful

This commit is contained in:
Jef Roosens 2023-01-26 10:21:30 +01:00
parent 3ec2e76af9
commit 05b96d1fd6
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
2 changed files with 23 additions and 16 deletions

View file

@ -88,15 +88,17 @@ void test_insert_random() {
}
void test_pop() {
const uint64_t n = 500;
vieter_heap *heap = vieter_heap_init();
TEST_SIZE(heap, 0);
void *data;
for (uint64_t i = 50; i > 0; i--) {
for (uint64_t i = n; i > 0; i--) {
vieter_heap_insert(heap, i, (void *)i);
TEST_SIZE(heap, (uint64_t)51 - i);
TEST_CHECK(count_nodes_heap(heap) == (uint64_t)51 - i);
TEST_SIZE(heap, (uint64_t)n + 1 - i);
TEST_CHECK(count_nodes_heap(heap) == (uint64_t)n + 1 - i);
TEST_CHECK(vieter_heap_peek(&data, heap) == vieter_heap_ok);
TEST_CHECK(data == (void*)i);
@ -104,10 +106,10 @@ void test_pop() {
data = NULL;
for (uint64_t i = 1; i <= 50; i++) {
for (uint64_t i = 1; i <= n; i++) {
TEST_CHECK(vieter_heap_pop(&data, heap) == vieter_heap_ok);
TEST_CHECK(data == (void*)i);
TEST_SIZE(heap, (uint64_t)50 - i);
TEST_SIZE(heap, (uint64_t)n - i);
}
vieter_heap_free(heap);
@ -124,7 +126,7 @@ int uint64_t_compare(const void *a, const void *b) {
}
void test_pop_random() {
const uint64_t n = 29;
const uint64_t n = 500;
srand(0);