Commit 3dfc59f1 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #288

 * Query Tests:
  * Tree is empty (return none).
  * Tree contains only elements to the left.
  * Tree contains only elements to the right.
  * Tree contains only elements to the left and to the right.
  * Tree contains overlaps and elements to the left.
  * Tree contains overlaps and elements to the right.
  * Tree contains overlaps and elements to the left and to the right.


git-svn-id: file:///svn/tokudb@1768 c7de825b-a66e-492c-adef-691d508d4ae1
parent 155a7587
......@@ -12,7 +12,7 @@ void verify_all_overlap(toku_range* query, toku_range* list, unsigned listlen) {
}
}
int nums[100];
int nums[200];
char letters[2] = {'A','B'};
toku_range_tree *tree;
......@@ -27,12 +27,15 @@ toku_range* init_range(toku_range* range, int left, int right, int data) {
return range;
}
void setup_tree(BOOL allow_overlaps, int left, int right, int data) {
void setup_tree(BOOL allow_overlaps, BOOL insert, int left, int right, int data) {
int r;
toku_range range;
r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps); CKERR(r);
r = toku_rt_insert(tree, init_range(&range, left, right, data));CKERR(r);
if (insert) {
r = toku_rt_insert(tree, init_range(&range, left, right, data));
CKERR(r);
}
}
void close_tree(void) {
int r;
......@@ -62,6 +65,8 @@ void runlimitsearch(toku_range* query, unsigned limit, unsigned findexpect) {
int r;
unsigned found;
r=toku_rt_find(tree, query, limit, &buf, &buflen, &found); CKERR(r);
verify_all_overlap(query, buf, found);
assert(found == findexpect);
}
......@@ -76,7 +81,7 @@ void tests(BOOL allow_overlaps) {
/* Tree: {|0-1|,|2-3|,|4-5|,|6-7|,|8-9|}, query of |2-7|, limit 2 finds 2,
limit 3 finds 3, limit 4 finds 3, limit 0 finds 3 */
setup_tree(allow_overlaps, 0, 1, 0);
setup_tree(allow_overlaps, TRUE, 0, 1, 0);
runinsert(0, init_range(&insert, 2, 3, 0));
runinsert(0, init_range(&insert, 4, 5, 0));
runinsert(0, init_range(&insert, 6, 7, 0));
......@@ -88,6 +93,68 @@ void tests(BOOL allow_overlaps) {
runlimitsearch(init_range(&query, 2, 7, 0), 3, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 4, 3);
close_tree();
/*
* Queries
*/
/* Tree is empty (return none) */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runlimitsearch(init_range(&query, 0, 0, 0), 0, 0);
close_tree();
/* Tree contains only elements to the left. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 1, 2, 0));
runinsert(0, init_range(&insert, 3, 4, 0));
runlimitsearch(init_range(&query, 8, 30, 0), 0, 0);
close_tree();
/* Tree contains only elements to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runlimitsearch(init_range(&query, 5, 7, 0), 0, 0);
close_tree();
/* Tree contains only elements to the left and to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 70, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 60, 65, 0), 0, 0);
close_tree();
/* Tree contains overlaps and elements to the left. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
close_tree();
/* Tree contains overlaps and elements to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 110, 120, 0));
runinsert(0, init_range(&insert, 130, 140, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
close_tree();
/* Tree contains overlaps and elements to the left and to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 110, 120, 0));
runinsert(0, init_range(&insert, 130, 140, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
close_tree();
}
int main(int argc, const char *argv[]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment