From 0b6026ae2a96c4757688af51d927261536cc2873 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 14 Jun 2021 20:59:28 +0200 Subject: tests --- tests/tree.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/tree.c (limited to 'tests/tree.c') diff --git a/tests/tree.c b/tests/tree.c new file mode 100644 index 0000000..42bf248 --- /dev/null +++ b/tests/tree.c @@ -0,0 +1,52 @@ +/* + * tests/tree.c + * (c) 2021 Jonas Gunz + * License: MIT + */ + +#include "tests.h" + +#include "../src/tree.h" + +#include + +START_TEST(tree_basic) { + unsigned int i, j; + + unsigned const int len = pow ( 'z' - 'a' + 1, 2); + unsigned int len_cnt = 0; + char* keys[len]; + char* data[len]; + + struct tree_node* root = NULL; + + for ( i = 'a'; i <= 'z'; i++ ) { + for ( j = 'a'; j <= 'z'; j++ ) { + keys[len_cnt] = malloc (3); + keys[len_cnt][0] = i; + keys[len_cnt][1] = j; + keys[len_cnt][2] = 0; + + data[len_cnt] = malloc(10); + snprintf( data[len_cnt], 10, "N%i", len_cnt ); + + len_cnt ++; + } + } + + ck_assert_int_eq(tree_balanced_insert( &root, (void**)data, keys, len ),0); + + for ( i = 0; i < len; i++ ) { + ck_assert_str_eq( tree_get(&root, keys[i]), data[i] ); + } + + ck_assert_int_eq( tree_destroy (&root, _TREE_FREE_DATA | _TREE_FREE_KEY), 0 ); +} END_TEST + +TCase* test_tree(void) { + TCase *tc = tcase_create("Tree"); + + tcase_add_test(tc, tree_basic); + + return tc; +} -- cgit v1.2.3