diff options
author | Randolph Tan <randolph@10gen.com> | 2014-01-14 14:09:42 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-02-28 16:26:33 -0500 |
commit | 5595b945603b0712c537787e31e6da661c424fee (patch) | |
tree | 90945ee3fe4931032f3af2d397bb755fbf5d30ef /jstests/core/geo_s2dupe_points.js | |
parent | cd62080dcb036e83f8fca6d68d9bcab67bf7a21c (diff) | |
download | mongo-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_s2dupe_points.js')
-rw-r--r-- | jstests/core/geo_s2dupe_points.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/jstests/core/geo_s2dupe_points.js b/jstests/core/geo_s2dupe_points.js new file mode 100644 index 00000000000..8dd6e804c78 --- /dev/null +++ b/jstests/core/geo_s2dupe_points.js @@ -0,0 +1,71 @@ +// See: SERVER-9240, SERVER-9401. +// s2 rejects shapes with duplicate adjacent points as invalid, but they are +// valid in GeoJSON. We store the duplicates, but internally remove them +// before indexing or querying. +t = db.geo_s2dupe_points +t.drop() +t.ensureIndex({geo: "2dsphere"}) + +function testDuplicates(shapeName, shapeWithDupes, shapeWithoutDupes) { + // insert a doc with dupes + assert.writeOK(t.insert(shapeWithDupes)); + + // duplicates are preserved when the document is fetched by _id + assert.eq(shapeWithDupes, t.findOne({_id: shapeName})); + assert.neq(shapeWithoutDupes, t.findOne({_id: shapeName}).geo); + + // can query with $geoIntersects inserted doc using both the duplicated and de-duplicated docs + assert.eq(t.find({ geo: { $geoIntersects: { $geometry : shapeWithDupes.geo } } } ).itcount(), 1); + assert.eq(t.find({ geo: { $geoIntersects: { $geometry : shapeWithoutDupes } } } ).itcount(), 1); + + // direct document equality in queries is preserved + assert.eq(t.find({ geo: shapeWithoutDupes} ).itcount(), 0); + assert.eq(t.find({ geo: shapeWithDupes.geo } ).itcount(), 1); +} + +// LineString +var lineWithDupes = { _id: "line", geo: { type: "LineString", + coordinates: [ [40,5], [40,5], [ 40, 5], [41, 6], [41,6] ] + } +}; +var lineWithoutDupes = { type: "LineString", coordinates: [ [40,5], [41,6] ] }; + +// Polygon +var polygonWithDupes = { _id: "poly", geo: { type: "Polygon", + coordinates: [ + [ [-3.0, -3.0], [3.0, -3.0], [3.0, 3.0], [-3.0, 3.0], [-3.0, -3.0] ], + [ [-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0], [-2.0, -2.0] ] + ] } +}; +var polygonWithoutDupes = { type: "Polygon", + coordinates: [ + [ [-3.0, -3.0], [3.0, -3.0], [3.0, 3.0], [-3.0, 3.0], [-3.0, -3.0] ], + [ [-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0] ] + ] +}; + +// MultiPolygon +var multiPolygonWithDupes = { _id: "multi", geo: { type: "MultiPolygon", coordinates: [ + [ + [ [102.0, 2.0], [103.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ] + ], + [ + [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], + [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.8, 0.8], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] + ] + ] +} }; +var multiPolygonWithoutDupes = { type: "MultiPolygon", coordinates: [ + [ + [ [102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ] + ], + [ + [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], + [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] + ] + ] +}; + +testDuplicates("line", lineWithDupes, lineWithoutDupes); +testDuplicates("poly", polygonWithDupes, polygonWithoutDupes); +testDuplicates("multi", multiPolygonWithDupes, multiPolygonWithoutDupes); |