diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-14 19:43:47 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-14 19:43:47 +0100 |
commit | ddd908706354fa9c4e2dbaa9f62b11078b06bf19 (patch) | |
tree | 252263002752b7ceff16001b30f3f5bb0c51005c | |
parent | 8336422c8ad72b98e3af9c038468b62a9eafac3c (diff) | |
download | kogata-ddd908706354fa9c4e2dbaa9f62b11078b06bf19.tar.gz kogata-ddd908706354fa9c4e2dbaa9f62b11078b06bf19.zip |
Add second btree test (btw it works)
-rw-r--r-- | src/tests/ktests/btree1/test.c | 1 | ||||
l--------- | src/tests/ktests/btree2/Makefile | 1 | ||||
-rw-r--r-- | src/tests/ktests/btree2/test.c | 46 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/tests/ktests/btree1/test.c b/src/tests/ktests/btree1/test.c index 1207a28..1d387f0 100644 --- a/src/tests/ktests/btree1/test.c +++ b/src/tests/ktests/btree1/test.c @@ -3,7 +3,6 @@ void test_btree_1() { BEGIN_TEST("test-btree-1"); - // hashtable test btree_t *ht = create_btree(str_key_cmp_fun, 0); ASSERT(ht != 0); diff --git a/src/tests/ktests/btree2/Makefile b/src/tests/ktests/btree2/Makefile new file mode 120000 index 0000000..4630a7c --- /dev/null +++ b/src/tests/ktests/btree2/Makefile @@ -0,0 +1 @@ +../rules.make
\ No newline at end of file diff --git a/src/tests/ktests/btree2/test.c b/src/tests/ktests/btree2/test.c new file mode 100644 index 0000000..eb76dba --- /dev/null +++ b/src/tests/ktests/btree2/test.c @@ -0,0 +1,46 @@ +#include <btree.h> + +uint32_t prng() { + static uint32_t prng_s = 5091; + prng_s = ((prng_s + 24162) * 15322) % 100001; + return prng_s; +} + +void test_btree_2() { + BEGIN_TEST("test-btree-2"); + + btree_t *ht = create_btree(id_key_cmp_fun, 0); + ASSERT(ht != 0); + + const int n = 100; + uint32_t k[n], v[n]; + for (int i = 0; i < n; i++) { + k[i] = prng(); + v[i] = prng(); + dbg_printf("add %d -> %d\n", k[i], v[i]); + ASSERT(btree_add(ht, (void*)k[i], (void*)v[i])); + ASSERT(btree_find(ht, (void*)k[i]) == (void*)v[i]); + } + + for (int i = 0; i < n; i++) { + ASSERT(btree_find(ht, (void*)k[i]) == (void*)v[i]); + } + + for (int i = 0; i < n/2; i++) { + btree_remove(ht, (void*)k[i]); + ASSERT(btree_find(ht, (void*)k[i]) == 0); + } + + for (int i = 0; i < n; i++) { + ASSERT(btree_find(ht, (void*)k[i]) == (i < n/2 ? 0 : (void*)v[i])); + } + + delete_btree(ht); + + TEST_OK; +} + +#undef TEST_PLACEHOLDER_AFTER_TASKING +#define TEST_PLACEHOLDER_AFTER_TASKING { test_btree_2(); } + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |