aboutsummaryrefslogtreecommitdiff
path: root/src/tests/ktests/btree1/test.c
blob: 1d387f01fbdf20e00823ca0bc3a47a2e69f98603 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <btree.h>

void test_btree_1() {
	BEGIN_TEST("test-btree-1");

	btree_t *ht = create_btree(str_key_cmp_fun, 0);
	ASSERT(ht != 0);

	ASSERT(btree_add(ht, "test1", "STRTEST1"));
	ASSERT(btree_add(ht, "test2", "STRTEST2"));
	ASSERT(btree_find(ht, "test1") != 0 && 
			strcmp(btree_find(ht, "test1"), "STRTEST1") == 0);
	ASSERT(btree_find(ht, "test2") != 0 &&
			strcmp(btree_find(ht, "test2"), "STRTEST2") == 0);
	ASSERT(btree_find(ht, "test") == 0);

	ASSERT(btree_add(ht, "test", "Forever alone"));
	ASSERT(btree_find(ht, "test1") != 0 &&
			strcmp(btree_find(ht, "test1"), "STRTEST1") == 0);
	ASSERT(btree_find(ht, "test2") != 0 &&
			strcmp(btree_find(ht, "test2"), "STRTEST2") == 0);
	ASSERT(btree_find(ht, "test") != 0 &&
			strcmp(btree_find(ht, "test"), "Forever alone") == 0);

	btree_remove(ht, "test1");
	ASSERT(btree_find(ht, "test1") == 0);
	ASSERT(btree_find(ht, "test2") != 0 &&
			strcmp(btree_find(ht, "test2"), "STRTEST2") == 0);
	ASSERT(btree_find(ht, "test") != 0 &&
			strcmp(btree_find(ht, "test"), "Forever alone") == 0);

	delete_btree(ht);

	TEST_OK;
}

#undef TEST_PLACEHOLDER_AFTER_TASKING
#define TEST_PLACEHOLDER_AFTER_TASKING { test_btree_1(); }

/* vim: set ts=4 sw=4 tw=0 noet :*/