Commit b32ac2cb authored by Yoni Fogel's avatar Yoni Fogel

Addresses #288

test Cases for pred/succ
 * Empty tree
  * Pred return nothing.
  * Succ return nothing.
 * 1 element tree.
  * Pred
  * Before
  * left
  * middle
  * right
  * after.
 * Succ
  * Before
  * left
  * middle
  * right
  * after
 * 2 element tree.
  * Pred, Succ
   * In empty space
    * Nothing to the left/Right (pred/succ) respectively.
    * something to the left/right (pred/succ) respectively.
   * On left endpoint.
    * Nothing to the left/Right (pred/succ) respectively.
    * something to the left/right (pred/succ) respectively.
   * On right endpoint.
    * Nothing to the left/Right (pred/succ) respectively.
    * something to the left/right (pred/succ) respectively.
   * In middle of range.
    * Nothing to the left/Right (pred/succ) respectively.
    * something to the left/right (pred/succ) respectively.


git-svn-id: file:///svn/tokudb@1774 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8db3779f
...@@ -25,6 +25,12 @@ toku_range* init_range(toku_range* range, int left, int right, int data) { ...@@ -25,6 +25,12 @@ toku_range* init_range(toku_range* range, int left, int right, int data) {
return range; return range;
} }
void* init_point(int left) {
assert(left >= 0);
assert(left < sizeof(nums) / sizeof(nums[0]));
return (&nums[left]);
}
void setup_tree(BOOL allow_overlaps, BOOL insert, int left, int right, int data) { void setup_tree(BOOL allow_overlaps, BOOL insert, int left, int right, int data) {
int r; int r;
toku_range range; toku_range range;
...@@ -68,95 +74,175 @@ void runlimitsearch(toku_range* query, unsigned limit, unsigned findexpect) { ...@@ -68,95 +74,175 @@ void runlimitsearch(toku_range* query, unsigned limit, unsigned findexpect) {
assert(found == findexpect); assert(found == findexpect);
} }
typedef enum {PRED=0, SUCC=1} predsucc;
void runtest(predsucc testtype, void* query, BOOL findexpect,
int left, int right, int data) {
int r;
BOOL found;
toku_range out;
assert(data >= 0 && data < sizeof(letters) / sizeof(letters[0]));
assert(left >= 0 && left < sizeof(nums) / sizeof(nums[0]));
assert(right >= 0 && right < sizeof(nums) / sizeof(nums[0]));
if (testtype == PRED) {
r = toku_rt_predecessor(tree, query, &out, &found);
}
else {
assert(testtype == SUCC);
r = toku_rt_successor(tree, query, &out, &found);
}
CKERR(r);
assert(found == findexpect);
if (findexpect) {
assert(int_cmp(out.left, &nums[left]) == 0);
assert(int_cmp(out.right, &nums[right]) == 0);
assert(char_cmp(out.data, &letters[data]) == 0);
}
}
void tests(BOOL allow_overlaps) { void tests(BOOL allow_overlaps) {
toku_range query;
toku_range insert; toku_range insert;
/*
Limited/Unlimited Queries
Limit of k does not produce all, but limit of 0 does. Single point overlaps /*
Empty
Only empty space test.
1 element
standard tree
Pred/Succ:
1: In empty space
* Nothing to the left/Right (pred/succ) respectively.
* something to the left/right (pred/succ) respectively.
2: On left endpoint.
* Nothing to the left/Right (pred/succ) respectively.
* something to the left/right (pred/succ) respectively.
3: On right endpoint.
* Nothing to the left/Right (pred/succ) respectively.
* something to the left/right (pred/succ) respectively.
4: In middle of range.
* Nothing to the left/Right (pred/succ) respectively.
* something to the left/right (pred/succ) respectively.
*/ */
/* Tree: {|0-1|,|2-3|,|4-5|,|6-7|,|8-9|}, query of |2-7|, limit 2 finds 2, /* Empty tree. */
limit 3 finds 3, limit 4 finds 3, limit 0 finds 3 */
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));
runinsert(0, init_range(&insert, 8, 9, 0));
runlimitsearch(init_range(&query, 2, 7, 0), 0, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 1, 1);
runlimitsearch(init_range(&query, 2, 7, 0), 2, 2);
runlimitsearch(init_range(&query, 2, 7, 0), 3, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 4, 3);
close_tree();
/* Tree is empty (return none) */
setup_tree(allow_overlaps, FALSE, 0, 0, 0); setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runlimitsearch(init_range(&query, 0, 0, 0), 0, 0); runtest(PRED, init_point(5), FALSE, 0, 0, 0);
runtest(SUCC, init_point(5), FALSE, 0, 0, 0);
close_tree(); close_tree();
/* Tree contains only elements to the left. */ /* Single element tree. Before left, left end point, middle,
setup_tree(allow_overlaps, FALSE, 0, 0, 0); right end point, after right. */
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); setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0)); runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0)); runtest(PRED, init_point(5), FALSE, 0, 0, 0);
runlimitsearch(init_range(&query, 5, 7, 0), 0, 0); runtest(PRED, init_point(10), FALSE, 0, 0, 0);
runtest(PRED, init_point(15), FALSE, 0, 0, 0);
runtest(PRED, init_point(20), FALSE, 0, 0, 0);
runtest(PRED, init_point(25), TRUE, 10, 20, 0);
runtest(SUCC, init_point(5), TRUE, 10, 20, 0);
runtest(SUCC, init_point(10), FALSE, 0, 0, 0);
runtest(SUCC, init_point(15), FALSE, 0, 0, 0);
runtest(SUCC, init_point(20), FALSE, 0, 0, 0);
runtest(SUCC, init_point(25), FALSE, 0, 0, 0);
close_tree(); close_tree();
/* Tree contains only elements to the left and to the right. */ /*
Swap left and right for succ.
Multi element tree.
* In empty space.
* Something on left.
* Nothing on left.
* At a left end point.
* Something on left.
* Nothing on left.
* Inside a range.
* Something on left.
* Nothing on left.
* At a right end point.
* Something on left.
* Nothing on left.
*/
setup_tree(allow_overlaps, FALSE, 0, 0, 0); setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0)); runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 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); * In empty space.
runinsert(0, init_range(&insert, 10, 20, 0)); * Something on left.
runinsert(0, init_range(&insert, 30, 40, 0)); * Nothing on left.
runinsert(0, init_range(&insert, 60, 80, 0)); */
runinsert(0, init_range(&insert, 90, 100, 0)); runtest(PRED, init_point(25), TRUE, 10, 20, 0);
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2); runtest(PRED, init_point(5), FALSE, 0, 0, 0);
close_tree();
/* Tree contains overlaps and elements to the right. */ /*
setup_tree(allow_overlaps, FALSE, 0, 0, 0); * At a left end point.
runinsert(0, init_range(&insert, 110, 120, 0)); * Something on left.
runinsert(0, init_range(&insert, 130, 140, 0)); * Nothing on left.
runinsert(0, init_range(&insert, 60, 80, 0)); */
runinsert(0, init_range(&insert, 90, 100, 0)); runtest(PRED, init_point(30), TRUE, 10, 20, 0);
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2); runtest(PRED, init_point(10), FALSE, 0, 0, 0);
close_tree();
/*
* Inside a range.
* Something on left.
* Nothing on left.
*/
runtest(PRED, init_point(35), TRUE, 10, 20, 0);
runtest(PRED, init_point(15), FALSE, 0, 0, 0);
/*
* At a right end point.
* Something on left.
* Nothing on left.
*/
runtest(PRED, init_point(40), TRUE, 10, 20, 0);
runtest(PRED, init_point(20), FALSE, 0, 0, 0);
/*
* In empty space.
* Something on right.
* Nothing on right.
*/
runtest(SUCC, init_point(25), TRUE, 30, 40, 0);
runtest(SUCC, init_point(45), FALSE, 0, 0, 0);
/*
* At a right end point.
* Something on right.
* Nothing on right.
*/
runtest(SUCC, init_point(20), TRUE, 30, 40, 0);
runtest(SUCC, init_point(40), FALSE, 0, 0, 0);
/*
* Inside a range.
* Something on right.
* Nothing on right.
*/
runtest(SUCC, init_point(15), TRUE, 30, 40, 0);
runtest(SUCC, init_point(35), FALSE, 0, 0, 0);
/*
* At a right end point.
* Something on right.
* Nothing on right.
*/
runtest(SUCC, init_point(20), TRUE, 30, 40, 0);
runtest(SUCC, init_point(40), FALSE, 0, 0, 0);
/* 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(); close_tree();
} }
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
int i; int i;
for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) nums[i] = i; for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) nums[i] = i;
buflen = 2; buflen = 2;
buf = (toku_range*)toku_malloc(2 * sizeof(toku_range)); buf = (toku_range*)toku_malloc(2 * sizeof(toku_range));
tests(FALSE); tests(FALSE);
tests(TRUE);
tree = NULL; tree = NULL;
toku_free(buf); toku_free(buf);
......
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