diff --git a/Makefile b/Makefile index 9db32d4..78f6a1c 100644 --- a/Makefile +++ b/Makefile @@ -98,5 +98,11 @@ clean: rm -rf $(BUILD_DIR) +.PHONY: bear +bear: clean + bear -- make + bear --append -- make build-test + + # Make make aware of the .d files -include $(DEPS) diff --git a/test/cat-heap/test_cat_heap.c b/test/cat-heap/test_cat_heap.c new file mode 100644 index 0000000..d415198 --- /dev/null +++ b/test/cat-heap/test_cat_heap.c @@ -0,0 +1,52 @@ +#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} +};