aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 19:59:50 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 19:59:50 +0100
commitdc86ed35a4a41ab53bb595e69fe57c29264fd146 (patch)
treefee2b87d32919d5ddb158ef2254546c7543b3ee4 /src/tests
parentddd908706354fa9c4e2dbaa9f62b11078b06bf19 (diff)
downloadkogata-dc86ed35a4a41ab53bb595e69fe57c29264fd146.tar.gz
kogata-dc86ed35a4a41ab53bb595e69fe57c29264fd146.zip
Add lower/upper bound test ; fix id_key_cmp_fun.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/ktests/btree2/test.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/tests/ktests/btree2/test.c b/src/tests/ktests/btree2/test.c
index eb76dba..9e105a9 100644
--- a/src/tests/ktests/btree2/test.c
+++ b/src/tests/ktests/btree2/test.c
@@ -24,6 +24,25 @@ void test_btree_2() {
for (int i = 0; i < n; i++) {
ASSERT(btree_find(ht, (void*)k[i]) == (void*)v[i]);
+ ASSERT(btree_lower(ht, (void*)k[i]) == (void*)v[i]);
+ ASSERT(btree_upper(ht, (void*)k[i]) == (void*)v[i]);
+ }
+
+ // random lower bound/upper bound tests
+ for (int t = 0; t < 100; t++) {
+ const uint32_t xk = prng();
+ int ilower = -1, iupper = -1;
+ for (int i = 1; i < n; i++) {
+ if (k[i] <= xk && (ilower == -1 || k[i] > k[ilower])) ilower = i;
+ if (k[i] >= xk && (iupper == -1 || k[i] < k[iupper])) iupper = i;
+ }
+ dbg_printf("random %d : lower %d (= %d), upper %d (= %d) ; ",
+ xk, k[ilower], v[ilower], k[iupper], v[iupper]);
+ const uint32_t bt_lower = (uint32_t)btree_lower(ht, (void*)xk);
+ const uint32_t bt_upper = (uint32_t)btree_upper(ht, (void*)xk);
+ dbg_printf("got lower %d, upper %d\n", bt_lower, bt_upper);
+ ASSERT(bt_lower == (ilower == -1 ? 0 : v[ilower]));;
+ ASSERT(bt_upper == (iupper == -1 ? 0 : v[iupper]));;
}
for (int i = 0; i < n/2; i++) {