summaryrefslogtreecommitdiff
path: root/jstests/core/geo_near_random2.js
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 /jstests/core/geo_near_random2.js
parentda780777b278314d7820483882af014b7b773547 (diff)
downloadmongo-7b88c26458c6ac82469ca4c061f94314f3bd689c.tar.gz
CAP-2451 Added distance check and 2dsphere tests to tests involving GeoNearRandomTest
Diffstat (limited to 'jstests/core/geo_near_random2.js')
-rw-r--r--jstests/core/geo_near_random2.js23
1 files changed, 21 insertions, 2 deletions
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