libvieter/test/tree/test_binary_tree.c

59 lines
1.5 KiB
C
Raw Normal View History

#include "acutest.h"
#include "vieter_tree.h"
#define TEST_SIZE(tree, size) \
TEST_CHECK(vieter_tree_size(tree) == size); \
TEST_MSG("Size: %zu", vieter_tree_size(tree))
void test_init() {
vieter_tree *tree = vieter_tree_init();
TEST_CHECK(tree != NULL);
TEST_SIZE(tree, 0);
2023-01-20 11:07:33 +01:00
vieter_tree_free(tree);
}
void test_insert() {
vieter_tree *tree = vieter_tree_init();
for (uint64_t i = 0; i < 25; i++) {
TEST_CHECK(vieter_tree_insert(tree, i, NULL) == vieter_tree_ok);
TEST_SIZE(tree, i + 1);
}
void *out;
for (uint64_t i = 0; i < 25; i++) {
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_ok);
TEST_CHECK(vieter_tree_insert(tree, i, NULL) == vieter_tree_already_present);
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_ok);
}
2023-01-20 11:07:33 +01:00
vieter_tree_free(tree);
}
void test_remove() {
vieter_tree *tree = vieter_tree_init();
for (uint64_t i = 0; i < 25; i++) {
TEST_CHECK(vieter_tree_insert(tree, i, NULL) == vieter_tree_ok);
}
void *out;
for (uint64_t i = 0; i < 25; i++) {
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_ok);
TEST_CHECK(vieter_tree_remove(&out, tree, i) == vieter_tree_ok);
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_not_present);
2023-01-20 11:07:33 +01:00
TEST_SIZE(tree, 25 - i - 1);
}
2023-01-20 11:07:33 +01:00
vieter_tree_free(tree);
}
TEST_LIST = {
{"test_init", test_init},
{"test_insert", test_insert},
{"test_remove", test_remove},
{NULL, NULL}
};