2023-01-19 22:23:19 +01:00
|
|
|
#include "acutest.h"
|
2023-01-28 19:27:40 +01:00
|
|
|
#include "vieter_tree_internal.h"
|
2023-01-19 22:23:19 +01:00
|
|
|
|
|
|
|
#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);
|
2023-01-19 22:23:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_insert() {
|
|
|
|
vieter_tree *tree = vieter_tree_init();
|
|
|
|
|
2023-01-20 15:44:32 +01:00
|
|
|
for (uint64_t i = 0; i < 250; i++) {
|
2023-01-19 22:23:19 +01:00
|
|
|
TEST_CHECK(vieter_tree_insert(tree, i, NULL) == vieter_tree_ok);
|
2023-01-19 22:45:22 +01:00
|
|
|
TEST_SIZE(tree, i + 1);
|
2023-01-29 17:32:27 +01:00
|
|
|
TEST_CHECK(vieter_tree_validate(tree));
|
2023-01-19 22:23:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void *out;
|
|
|
|
|
2023-01-20 15:44:32 +01:00
|
|
|
for (uint64_t i = 0; i < 250; i++) {
|
2023-01-19 22:45:22 +01:00
|
|
|
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_ok);
|
2023-01-19 22:23:19 +01:00
|
|
|
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);
|
2023-01-19 22:23:19 +01:00
|
|
|
}
|
|
|
|
|
2023-01-19 22:45:22 +01:00
|
|
|
void test_remove() {
|
|
|
|
vieter_tree *tree = vieter_tree_init();
|
|
|
|
|
2023-01-20 15:44:32 +01:00
|
|
|
for (uint64_t i = 0; i < 250; i++) {
|
2023-01-19 22:45:22 +01:00
|
|
|
TEST_CHECK(vieter_tree_insert(tree, i, NULL) == vieter_tree_ok);
|
2023-01-29 17:32:27 +01:00
|
|
|
TEST_CHECK(vieter_tree_validate(tree));
|
2023-01-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void *out;
|
|
|
|
|
2023-02-01 23:04:35 +01:00
|
|
|
for (uint64_t i = 0; i < 250; i++) {
|
2023-01-19 22:45:22 +01:00
|
|
|
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_ok);
|
|
|
|
TEST_CHECK(vieter_tree_remove(&out, tree, i) == vieter_tree_ok);
|
2023-01-29 17:32:27 +01:00
|
|
|
TEST_CHECK(vieter_tree_validate(tree));
|
2023-01-19 22:45:22 +01:00
|
|
|
TEST_CHECK(vieter_tree_search(&out, tree, i) == vieter_tree_not_present);
|
2023-01-20 15:44:32 +01:00
|
|
|
TEST_SIZE(tree, 250 - i - 1);
|
2023-01-19 22:45:22 +01:00
|
|
|
}
|
2023-01-20 11:07:33 +01:00
|
|
|
|
|
|
|
vieter_tree_free(tree);
|
2023-01-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2023-01-19 22:23:19 +01:00
|
|
|
TEST_LIST = {
|
2023-01-28 09:30:35 +01:00
|
|
|
{"tree init", test_init},
|
|
|
|
{"tree insert", test_insert},
|
|
|
|
{"tree remove", test_remove},
|
2023-01-19 22:23:19 +01:00
|
|
|
{NULL, NULL}
|
|
|
|
};
|