summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Zhang <brandon.zhang@mongodb.com>2015-07-30 13:37:15 -0400
committerBrandon Zhang <brandon.zhang@mongodb.com>2015-08-12 17:51:34 -0400
commit7b88c26458c6ac82469ca4c061f94314f3bd689c (patch)
treea1b1225a5b48ee7009fa34006133a0dd8e1c382d
parentda780777b278314d7820483882af014b7b773547 (diff)
downloadmongo-7b88c26458c6ac82469ca4c061f94314f3bd689c.tar.gz
CAP-2451 Added distance check and 2dsphere tests to tests involving GeoNearRandomTest
-rw-r--r--jstests/core/geo_near_random1.js27
-rw-r--r--jstests/core/geo_near_random2.js23
-rw-r--r--jstests/libs/geo_near_random.js3
3 files changed, 50 insertions, 3 deletions
diff --git a/jstests/core/geo_near_random1.js b/jstests/core/geo_near_random1.js
index 50539f3ea5d..5c75b458957 100644
--- a/jstests/core/geo_near_random1.js
+++ b/jstests/core/geo_near_random1.js
@@ -1,12 +1,37 @@
-// this tests all points using $near
+// this tests all points
load("jstests/libs/geo_near_random.js");
var test = new GeoNearRandomTest("geo_near_random1");
test.insertPts(50);
+// test.testPt() runs geoNear commands at the given coordinates with
+// limits from 1 to nPts(# of inserted points). At the nth run, it
+// compares the first (n - 1) results with the result of the (n - 1)th
+// run to make sure they are identical. It also makes sure that the
+// distances are in increasing order. The test runs in O(N^2).
+
+// Test $near with a 2dindex
test.testPt([0,0]);
test.testPt(test.mkPt());
test.testPt(test.mkPt());
test.testPt(test.mkPt());
test.testPt(test.mkPt());
+
+opts = {sphere: 1};
+
+// Test $nearSphere with a 2d index
+test.testPt([0,0], opts);
+test.testPt(test.mkPt(), opts);
+test.testPt(test.mkPt(), opts);
+test.testPt(test.mkPt(), opts);
+test.testPt(test.mkPt(), opts);
+
+// Test $nearSphere with a 2dsphere index
+assert.commandWorked(db.geo_near_random1.dropIndex({loc: '2d'}));
+assert.commandWorked(db.geo_near_random1.ensureIndex({loc: '2dsphere'}));
+test.testPt([0,0], opts);
+test.testPt(test.mkPt(), opts);
+test.testPt(test.mkPt(), opts);
+test.testPt(test.mkPt(), opts);
+test.testPt(test.mkPt(), opts); \ No newline at end of file
diff --git a/jstests/core/geo_near_random2.js b/jstests/core/geo_near_random2.js
index 1673abb88e7..d8487df5a07 100644
--- a/jstests/core/geo_near_random2.js
+++ b/jstests/core/geo_near_random2.js
@@ -1,11 +1,18 @@
-// this tests 1% of all points using $near and $nearSphere
+// this tests 1% of all points
load("jstests/libs/geo_near_random.js");
var test = new GeoNearRandomTest("geo_near_random2");
test.insertPts(5000);
-opts = {sphere:0, nToTest:test.nPts*0.01};
+// test.testPt() runs geoNear commands at the given coordinates with
+// limits from 1 to nPts(# of inserted points). At the nth run, it
+// compares the first (n - 1) results with the result of the (n - 1)th
+// run to make sure they are identical. It also makes sure that the
+// distances are in increasing order. The test runs in O(N^2).
+
+// Test $near with 2d index
+opts = {sphere: 0, nToTest: test.nPts*0.01};
test.testPt([0,0], opts);
test.testPt(test.mkPt(), opts);
test.testPt(test.mkPt(), opts);
@@ -13,9 +20,21 @@ test.testPt(test.mkPt(), opts);
test.testPt(test.mkPt(), opts);
opts.sphere = 1
+
+// Test $nearSphere with 2d index
test.testPt([0,0], opts);
+// test.mkPt(0.8) generates a random point in the maximum
+// lat long bounds scaled by 0.8
test.testPt(test.mkPt(0.8), opts);
test.testPt(test.mkPt(0.8), opts);
test.testPt(test.mkPt(0.8), opts);
test.testPt(test.mkPt(0.8), opts);
+// Test $nearSphere with 2dsphere index
+assert.commandWorked(db.geo_near_random2.dropIndex({loc: '2d'}));
+assert.commandWorked(db.geo_near_random2.ensureIndex({loc: '2dsphere'}));
+test.testPt([0,0], opts);
+test.testPt(test.mkPt(0.8), opts);
+test.testPt(test.mkPt(0.8), opts);
+test.testPt(test.mkPt(0.8), opts);
+test.testPt(test.mkPt(0.8), opts); \ No newline at end of file
diff --git a/jstests/libs/geo_near_random.js b/jstests/libs/geo_near_random.js
index 248f5e49a6c..27590322b7a 100644
--- a/jstests/libs/geo_near_random.js
+++ b/jstests/libs/geo_near_random.js
@@ -81,6 +81,9 @@ GeoNearRandomTest.prototype.testPt = function(pt, opts) {
printjson(cmd);
throw e; // rethrow
}
+
+ // Make sure distances are in increasing order
+ assert.gte(ret[ret.length - 1].dis, last[last.length - 1].dis);
last = ret;
}