summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorChibuikem Amaechi <cramaechi@me.com>2018-01-17 20:50:36 -0600
committerNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-01-25 12:17:54 -0500
commit048da5de50a2f6aa8776f1ecd626313f5ca1e575 (patch)
tree6d3030fecb4d223ddcef66d7db8239fcf0dbbb03 /jstests
parenta9c8f03bb791e7ab23f3451f03ae7a79385b8194 (diff)
downloadmongo-048da5de50a2f6aa8776f1ecd626313f5ca1e575.tar.gz
SERVER-31970 Modernize core/geo_polygon3.js and improve error handling
Adding assertions on failure to write, drop collection or build an index will make this test easier to troubleshoot. Closes #1205. Signed-off-by: Nick Zolnierz <nicholas.zolnierz@mongodb.com>
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/geo_polygon3.js90
1 files changed, 48 insertions, 42 deletions
diff --git a/jstests/core/geo_polygon3.js b/jstests/core/geo_polygon3.js
index 1f81e70adfa..ac668f37c04 100644
--- a/jstests/core/geo_polygon3.js
+++ b/jstests/core/geo_polygon3.js
@@ -2,60 +2,66 @@
// Tests for polygon querying with varying levels of accuracy
//
-var numTests = 31;
+(function() {
+ "use strict";
-for (var n = 0; n < numTests; n++) {
- t = db.geo_polygon3;
- t.drop();
+ const numTests = 31;
- num = 0;
- for (x = 1; x < 9; x++) {
- for (y = 1; y < 9; y++) {
- o = {_id: num++, loc: [x, y]};
- t.save(o);
+ for (let n = 0; n < numTests; n++) {
+ let t = db.geo_polygon3;
+ t.drop();
+
+ let num = 0;
+ for (let x = 1; x < 9; x++) {
+ for (let y = 1; y < 9; y++) {
+ let o = {_id: num++, loc: [x, y]};
+ assert.writeOK(t.insert(o));
+ }
}
- }
- t.ensureIndex({loc: "2d"}, {bits: 2 + n});
+ assert.commandWorked(t.createIndex({loc: "2d"}, {bits: 2 + n}));
- triangle = [[0, 0], [1, 1], [0, 2]];
+ const triangle = [[0, 0], [1, 1], [0, 2]];
- // Look at only a small slice of the data within a triangle
- assert.eq(1, t.find({loc: {"$within": {"$polygon": triangle}}}).itcount(), "Triangle Test");
+ // Look at only a small slice of the data within a triangle
+ assert.eq(1, t.find({loc: {"$within": {"$polygon": triangle}}}).itcount(), "Triangle Test");
- boxBounds = [[0, 0], [0, 10], [10, 10], [10, 0]];
+ let boxBounds = [[0, 0], [0, 10], [10, 10], [10, 0]];
- assert.eq(
- num, t.find({loc: {"$within": {"$polygon": boxBounds}}}).itcount(), "Bounding Box Test");
+ assert.eq(num,
+ t.find({loc: {"$within": {"$polygon": boxBounds}}}).itcount(),
+ "Bounding Box Test");
- // Look in a box much bigger than the one we have data in
- boxBounds = [[-100, -100], [-100, 100], [100, 100], [100, -100]];
- assert.eq(num,
- t.find({loc: {"$within": {"$polygon": boxBounds}}}).itcount(),
- "Big Bounding Box Test");
+ // Look in a box much bigger than the one we have data in
+ boxBounds = [[-100, -100], [-100, 100], [100, 100], [100, -100]];
+ assert.eq(num,
+ t.find({loc: {"$within": {"$polygon": boxBounds}}}).itcount(),
+ "Big Bounding Box Test");
- t.drop();
+ assert(t.drop());
- pacman = [
- [0, 2],
- [0, 4],
- [2, 6],
- [4, 6], // Head
- [6, 4],
- [4, 3],
- [6, 2], // Mouth
- [4, 0],
- [2, 0] // Bottom
- ];
+ const pacman = [
+ [0, 2],
+ [0, 4],
+ [2, 6],
+ [4, 6], // Head
+ [6, 4],
+ [4, 3],
+ [6, 2], // Mouth
+ [4, 0],
+ [2, 0] // Bottom
+ ];
- t.save({loc: [1, 3]}); // Add a point that's in
- t.ensureIndex({loc: "2d"}, {bits: 2 + t});
+ assert.writeOK(t.insert({loc: [1, 3]})); // Add a point that's in
+ assert.commandWorked(t.createIndex({loc: "2d"}, {bits: 2 + n}));
- assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).itcount(), "Pacman single point");
+ assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).itcount(), "Pacman single point");
- t.save({loc: [5, 3]}); // Add a point that's out right in the mouth opening
- t.save({loc: [3, 7]}); // Add a point above the center of the head
- t.save({loc: [3, -1]}); // Add a point below the center of the bottom
+ assert.writeOK(
+ t.insert({loc: [5, 3]})); // Add a point that's out right in the mouth opening
+ assert.writeOK(t.insert({loc: [3, 7]})); // Add a point above the center of the head
+ assert.writeOK(t.insert({loc: [3, -1]})); // Add a point below the center of the bottom
- assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).itcount(), "Pacman double point");
-}
+ assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).itcount(), "Pacman double point");
+ }
+})();