summaryrefslogtreecommitdiff
path: root/jstests/core/geo_s2index.js
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2014-01-14 14:09:42 -0500
committerRandolph Tan <randolph@10gen.com>2014-02-28 16:26:33 -0500
commit5595b945603b0712c537787e31e6da661c424fee (patch)
tree90945ee3fe4931032f3af2d397bb755fbf5d30ef /jstests/core/geo_s2index.js
parentcd62080dcb036e83f8fca6d68d9bcab67bf7a21c (diff)
downloadmongo-5595b945603b0712c537787e31e6da661c424fee.tar.gz
SERVER-12127 migrate js tests to jscore suite when not related to writes
Moved test jstest/[a-i].js -> jstests/core/ and made changes to comply with write command api
Diffstat (limited to 'jstests/core/geo_s2index.js')
-rwxr-xr-xjstests/core/geo_s2index.js114
1 files changed, 114 insertions, 0 deletions
diff --git a/jstests/core/geo_s2index.js b/jstests/core/geo_s2index.js
new file mode 100755
index 00000000000..974e4578dce
--- /dev/null
+++ b/jstests/core/geo_s2index.js
@@ -0,0 +1,114 @@
+t = db.geo_s2index
+t.drop()
+
+// We internally drop adjacent duplicate points in lines.
+someline = { "type" : "LineString", "coordinates": [ [40,5], [40,5], [ 40, 5], [41, 6], [41,6]]}
+t.insert( {geo : someline , nonGeo: "someline"})
+t.ensureIndex({geo: "2dsphere"})
+foo = t.find({geo: {$geoIntersects: {$geometry: {type: "Point", coordinates: [40,5]}}}}).next();
+assert.eq(foo.geo, someline);
+t.dropIndex({geo: "2dsphere"})
+
+pointA = { "type" : "Point", "coordinates": [ 40, 5 ] }
+t.insert( {geo : pointA , nonGeo: "pointA"})
+
+pointD = { "type" : "Point", "coordinates": [ 41.001, 6.001 ] }
+t.insert( {geo : pointD , nonGeo: "pointD"})
+
+pointB = { "type" : "Point", "coordinates": [ 41, 6 ] }
+t.insert( {geo : pointB , nonGeo: "pointB"})
+
+pointC = { "type" : "Point", "coordinates": [ 41, 6 ] }
+t.insert( {geo : pointC} )
+
+// Add a point within the polygon but not on the border. Don't want to be on
+// the path of the polyline.
+pointE = { "type" : "Point", "coordinates": [ 40.6, 5.4 ] }
+t.insert( {geo : pointE} )
+
+// Make sure we can index this without error.
+t.insert({nonGeo: "noGeoField!"})
+
+somepoly = { "type" : "Polygon",
+ "coordinates" : [ [ [40,5], [40,6], [41,6], [41,5], [40,5]]]}
+t.insert( {geo : somepoly, nonGeo: "somepoly" })
+
+var res = t.ensureIndex( { geo : "2dsphere", nonGeo: 1 } );
+// We have a point without any geo data. Don't error.
+assert.writeOK(res);
+
+res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : pointA} } });
+assert.eq(res.itcount(), 3);
+
+res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : pointB} } });
+assert.eq(res.itcount(), 4);
+
+res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : pointD} } });
+assert.eq(res.itcount(), 1);
+
+res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : someline} } })
+assert.eq(res.itcount(), 5);
+
+res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : somepoly} } })
+assert.eq(res.itcount(), 6);
+
+res = t.find({ "geo" : { "$within" : { "$geometry" : somepoly} } })
+assert.eq(res.itcount(), 6);
+
+res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : somepoly} } }).limit(1)
+assert.eq(res.itcount(), 1);
+
+res = t.find({ "nonGeo": "pointA",
+ "geo" : { "$geoIntersects" : { "$geometry" : somepoly} } })
+assert.eq(res.itcount(), 1);
+
+// Don't crash mongod if we give it bad input.
+t.drop()
+t.ensureIndex({loc: "2dsphere", x:1})
+t.save({loc: [0,0]})
+assert.throws(function() { return t.count({loc: {$foo:[0,0]}}) })
+assert.throws(function() { return t.find({ "nonGeo": "pointA",
+ "geo" : { "$geoIntersects" : { "$geometry" : somepoly},
+ "$near": {"$geometry" : somepoly }}}).count()})
+
+// If we specify a datum, it has to be valid (WGS84).
+t.drop()
+t.ensureIndex({loc: "2dsphere"})
+res = t.insert({ loc: { type: 'Point',
+ coordinates: [40, 5],
+ crs: { type: 'name', properties: { name: 'EPSG:2000' }}}});
+assert.writeError(res);
+assert.eq(0, t.find().itcount())
+res = t.insert({ loc: { type: 'Point', coordinates: [40, 5] }});
+assert.writeOK(res);
+res = t.insert({ loc: { type: 'Point',
+ coordinates: [40, 5],
+ crs: { type: 'name', properties: {name :'EPSG:4326' }}}});
+assert.writeOK(res);
+res = t.insert({ loc: { type:'Point',
+ coordinates: [40, 5],
+ crs: { type: 'name',
+ properties: { name: 'urn:ogc:def:crs:OGC:1.3:CRS84'}}}});
+assert.writeOK(res);
+
+// We can pass level parameters and we verify that they're valid.
+// 0 <= coarsestIndexedLevel <= finestIndexedLevel <= 30.
+t.drop();
+t.save({loc: [0,0]})
+res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 17, coarsestIndexedLevel: 5 });
+assert.writeOK(res);
+
+t.drop();
+t.save({loc: [0,0]})
+res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 31, coarsestIndexedLevel: 5 });
+assert.writeError(res);
+
+t.drop();
+t.save({loc: [0,0]})
+res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 30, coarsestIndexedLevel: 0 });
+assert.writeOK(res);
+
+t.drop();
+t.save({loc: [0,0]})
+res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 30, coarsestIndexedLevel: -1 });
+assert.writeError(res);