forked from vieter-v/libvieter
fix(heap): finally fixed that pop bug
This commit is contained in:
parent
3ec2e76af9
commit
05b96d1fd6
2 changed files with 23 additions and 16 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue