#include "acutest.h" #include "vieter_cat_heap_internal.h" #define TEST_SIZE(cheap, size) \ TEST_CHECK(vieter_cat_heap_size(cheap) == size); \ TEST_MSG("Size: %zu, expected: %lu", vieter_cat_heap_size(cheap), (uint64_t)size) void test_init() { vieter_cat_heap *cheap = vieter_cat_heap_init(); TEST_CHECK(cheap != NULL); TEST_SIZE(cheap, 0); vieter_cat_heap_free(cheap); } void test_insert() { vieter_cat_heap *cheap = vieter_cat_heap_init(); TEST_SIZE(cheap, 0); void *data; for (uint64_t i = 50; i > 0; i--) { vieter_cat_heap_insert(cheap, "cat1", i, (void *)i); TEST_SIZE(cheap, (uint64_t)51 - i); data = 0; TEST_CHECK(vieter_cat_heap_peek(&data, cheap, "cat1") == vieter_cat_heap_ok); TEST_CHECK_(data == (void *)i, "%lX == %lX", (uint64_t)data, i); } for (uint64_t i = 50; i > 0; i--) { vieter_cat_heap_insert(cheap, "cat2", i, (void *)i); TEST_SIZE(cheap, (uint64_t)101 - i); data = 0; TEST_CHECK(vieter_cat_heap_peek(&data, cheap, "cat2") == vieter_cat_heap_ok); TEST_CHECK_(data == (void *)i, "%lX == %lX", (uint64_t)data, i); } vieter_cat_heap_free(cheap); } TEST_LIST = { {"cat heap init", test_init}, {"cat heap insert", test_insert}, /* {"heap insert random", test_insert_random}, */ /* {"heap pop", test_pop}, */ /* {"heap pop random", test_pop_random}, */ {NULL, NULL} };