diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/matcher/expression_geo_test.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/matcher/expression_geo_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_geo_test.cpp | 235 |
1 files changed, 123 insertions, 112 deletions
diff --git a/src/mongo/db/matcher/expression_geo_test.cpp b/src/mongo/db/matcher/expression_geo_test.cpp index 67d51f5580c..0bc96f33e7f 100644 --- a/src/mongo/db/matcher/expression_geo_test.cpp +++ b/src/mongo/db/matcher/expression_geo_test.cpp @@ -41,137 +41,148 @@ namespace mongo { - TEST( ExpressionGeoTest, Geo1 ) { - BSONObj query = fromjson("{loc:{$within:{$box:[{x: 4, y:4},[6,6]]}}}"); +TEST(ExpressionGeoTest, Geo1) { + BSONObj query = fromjson("{loc:{$within:{$box:[{x: 4, y:4},[6,6]]}}}"); - std::unique_ptr<GeoExpression> gq(new GeoExpression); - ASSERT_OK( gq->parseFrom( query["loc"].Obj() ) ); + std::unique_ptr<GeoExpression> gq(new GeoExpression); + ASSERT_OK(gq->parseFrom(query["loc"].Obj())); - GeoMatchExpression ge; - ASSERT( ge.init("a", gq.release(), query ).isOK() ); + GeoMatchExpression ge; + ASSERT(ge.init("a", gq.release(), query).isOK()); - ASSERT(!ge.matchesBSON(fromjson("{a: [3,4]}"))); - ASSERT(ge.matchesBSON(fromjson("{a: [4,4]}"))); - ASSERT(ge.matchesBSON(fromjson("{a: [5,5]}"))); - ASSERT(ge.matchesBSON(fromjson("{a: [5,5.1]}"))); - ASSERT(ge.matchesBSON(fromjson("{a: {x: 5, y:5.1}}"))); - - } + ASSERT(!ge.matchesBSON(fromjson("{a: [3,4]}"))); + ASSERT(ge.matchesBSON(fromjson("{a: [4,4]}"))); + ASSERT(ge.matchesBSON(fromjson("{a: [5,5]}"))); + ASSERT(ge.matchesBSON(fromjson("{a: [5,5.1]}"))); + ASSERT(ge.matchesBSON(fromjson("{a: {x: 5, y:5.1}}"))); +} - TEST(ExpressionGeoTest, GeoNear1) { - BSONObj query = fromjson("{loc:{$near:{$maxDistance:100, " - "$geometry:{type:\"Point\", coordinates:[0,0]}}}}"); - std::unique_ptr<GeoNearExpression> nq(new GeoNearExpression); - ASSERT_OK(nq->parseFrom(query["loc"].Obj())); +TEST(ExpressionGeoTest, GeoNear1) { + BSONObj query = fromjson( + "{loc:{$near:{$maxDistance:100, " + "$geometry:{type:\"Point\", coordinates:[0,0]}}}}"); + std::unique_ptr<GeoNearExpression> nq(new GeoNearExpression); + ASSERT_OK(nq->parseFrom(query["loc"].Obj())); - GeoNearMatchExpression gne; - ASSERT(gne.init("a", nq.release(), query).isOK()); + GeoNearMatchExpression gne; + ASSERT(gne.init("a", nq.release(), query).isOK()); - // We can't match the data but we can make sure it was parsed OK. - ASSERT_EQUALS(gne.getData().centroid->crs, SPHERE); - ASSERT_EQUALS(gne.getData().minDistance, 0); - ASSERT_EQUALS(gne.getData().maxDistance, 100); - } + // We can't match the data but we can make sure it was parsed OK. + ASSERT_EQUALS(gne.getData().centroid->crs, SPHERE); + ASSERT_EQUALS(gne.getData().minDistance, 0); + ASSERT_EQUALS(gne.getData().maxDistance, 100); +} - std::unique_ptr<GeoMatchExpression> makeGeoMatchExpression(const BSONObj& locQuery) { - std::unique_ptr<GeoExpression> gq(new GeoExpression); - ASSERT_OK(gq->parseFrom(locQuery)); +std::unique_ptr<GeoMatchExpression> makeGeoMatchExpression(const BSONObj& locQuery) { + std::unique_ptr<GeoExpression> gq(new GeoExpression); + ASSERT_OK(gq->parseFrom(locQuery)); - std::unique_ptr<GeoMatchExpression> ge = stdx::make_unique<GeoMatchExpression>(); - ASSERT_OK(ge->init("a", gq.release(), locQuery)); + std::unique_ptr<GeoMatchExpression> ge = stdx::make_unique<GeoMatchExpression>(); + ASSERT_OK(ge->init("a", gq.release(), locQuery)); - return ge; - } + return ge; +} - std::unique_ptr<GeoNearMatchExpression> makeGeoNearMatchExpression(const BSONObj& locQuery) { - std::unique_ptr<GeoNearExpression> nq(new GeoNearExpression); - ASSERT_OK(nq->parseFrom(locQuery)); +std::unique_ptr<GeoNearMatchExpression> makeGeoNearMatchExpression(const BSONObj& locQuery) { + std::unique_ptr<GeoNearExpression> nq(new GeoNearExpression); + ASSERT_OK(nq->parseFrom(locQuery)); - std::unique_ptr<GeoNearMatchExpression> gne = stdx::make_unique<GeoNearMatchExpression>(); - ASSERT_OK(gne->init("a", nq.release(), locQuery)); + std::unique_ptr<GeoNearMatchExpression> gne = stdx::make_unique<GeoNearMatchExpression>(); + ASSERT_OK(gne->init("a", nq.release(), locQuery)); - return gne; - } + return gne; +} - /** - * A bunch of cases in which a geo expression is equivalent() to both itself or to another - * expression. - */ - TEST(ExpressionGeoTest, GeoEquivalent) { - { - BSONObj query = fromjson("{$within: {$box: [{x: 4, y: 4}, [6, 6]]}}"); - std::unique_ptr<GeoMatchExpression> ge(makeGeoMatchExpression(query)); - ASSERT(ge->equivalent(ge.get())); - } - { - BSONObj query = fromjson("{$within: {$geometry: {type: 'Polygon'," - "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"); - std::unique_ptr<GeoMatchExpression> ge(makeGeoMatchExpression(query)); - ASSERT(ge->equivalent(ge.get())); - } - { - BSONObj query1 = fromjson("{$within: {$geometry: {type: 'Polygon'," - "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"), - query2 = fromjson("{$within: {$geometry: {type: 'Polygon'," - "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"); - std::unique_ptr<GeoMatchExpression> ge1(makeGeoMatchExpression(query1)), - ge2(makeGeoMatchExpression(query2)); - ASSERT(ge1->equivalent(ge2.get())); - } +/** + * A bunch of cases in which a geo expression is equivalent() to both itself or to another + * expression. + */ +TEST(ExpressionGeoTest, GeoEquivalent) { + { + BSONObj query = fromjson("{$within: {$box: [{x: 4, y: 4}, [6, 6]]}}"); + std::unique_ptr<GeoMatchExpression> ge(makeGeoMatchExpression(query)); + ASSERT(ge->equivalent(ge.get())); } - - /** - * A bunch of cases in which a *geoNear* expression is equivalent both to itself or to - * another expression. - */ - TEST(ExpressionGeoTest, GeoNearEquivalent) { - { - BSONObj query = fromjson("{$near: {$maxDistance: 100, " - "$geometry: {type: 'Point', coordinates: [0, 0]}}}"); - std::unique_ptr<GeoNearMatchExpression> gne(makeGeoNearMatchExpression(query)); - ASSERT(gne->equivalent(gne.get())); - } - { - BSONObj query = fromjson("{$near: {$minDistance: 10, $maxDistance: 100," - "$geometry: {type: 'Point', coordinates: [0, 0]}}}"); - std::unique_ptr<GeoNearMatchExpression> gne(makeGeoNearMatchExpression(query)); - ASSERT(gne->equivalent(gne.get())); - } - { - BSONObj query1 = fromjson("{$near: {$maxDistance: 100, " - "$geometry: {type: 'Point', coordinates: [1, 0]}}}"), - query2 = fromjson("{$near: {$maxDistance: 100, " - "$geometry: {type: 'Point', coordinates: [1, 0]}}}"); - std::unique_ptr<GeoNearMatchExpression> gne1(makeGeoNearMatchExpression(query1)), - gne2(makeGeoNearMatchExpression(query2)); - ASSERT(gne1->equivalent(gne2.get())); - } + { + BSONObj query = fromjson( + "{$within: {$geometry: {type: 'Polygon'," + "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"); + std::unique_ptr<GeoMatchExpression> ge(makeGeoMatchExpression(query)); + ASSERT(ge->equivalent(ge.get())); } - - /** - * A geo expression being not equivalent to another expression. - */ - TEST(ExpressionGeoTest, GeoNotEquivalent) { - BSONObj query1 = fromjson("{$within: {$geometry: {type: 'Polygon'," - "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"), - query2 = fromjson("{$within: {$geometry: {type: 'Polygon'," - "coordinates: [[[0, 0], [3, 6], [6, 2], [0, 0]]]}}}"); + { + BSONObj query1 = fromjson( + "{$within: {$geometry: {type: 'Polygon'," + "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"), + query2 = fromjson( + "{$within: {$geometry: {type: 'Polygon'," + "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"); std::unique_ptr<GeoMatchExpression> ge1(makeGeoMatchExpression(query1)), - ge2(makeGeoMatchExpression(query2)); - ASSERT(!ge1->equivalent(ge2.get())); + ge2(makeGeoMatchExpression(query2)); + ASSERT(ge1->equivalent(ge2.get())); } +} - /** - * A *geoNear* expression being not equivalent to another expression. - */ - TEST(ExpressionGeoTest, GeoNearNotEquivalent) { - BSONObj query1 = fromjson("{$near: {$maxDistance: 100, " - "$geometry: {type: 'Point', coordinates: [0, 0]}}}"), - query2 = fromjson("{$near: {$maxDistance: 100, " - "$geometry: {type: 'Point', coordinates: [1, 0]}}}"); +/** + * A bunch of cases in which a *geoNear* expression is equivalent both to itself or to + * another expression. + */ +TEST(ExpressionGeoTest, GeoNearEquivalent) { + { + BSONObj query = fromjson( + "{$near: {$maxDistance: 100, " + "$geometry: {type: 'Point', coordinates: [0, 0]}}}"); + std::unique_ptr<GeoNearMatchExpression> gne(makeGeoNearMatchExpression(query)); + ASSERT(gne->equivalent(gne.get())); + } + { + BSONObj query = fromjson( + "{$near: {$minDistance: 10, $maxDistance: 100," + "$geometry: {type: 'Point', coordinates: [0, 0]}}}"); + std::unique_ptr<GeoNearMatchExpression> gne(makeGeoNearMatchExpression(query)); + ASSERT(gne->equivalent(gne.get())); + } + { + BSONObj query1 = fromjson( + "{$near: {$maxDistance: 100, " + "$geometry: {type: 'Point', coordinates: [1, 0]}}}"), + query2 = fromjson( + "{$near: {$maxDistance: 100, " + "$geometry: {type: 'Point', coordinates: [1, 0]}}}"); std::unique_ptr<GeoNearMatchExpression> gne1(makeGeoNearMatchExpression(query1)), - gne2(makeGeoNearMatchExpression(query2)); - ASSERT(!gne1->equivalent(gne2.get())); + gne2(makeGeoNearMatchExpression(query2)); + ASSERT(gne1->equivalent(gne2.get())); } } + +/** + * A geo expression being not equivalent to another expression. + */ +TEST(ExpressionGeoTest, GeoNotEquivalent) { + BSONObj query1 = fromjson( + "{$within: {$geometry: {type: 'Polygon'," + "coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}}}"), + query2 = fromjson( + "{$within: {$geometry: {type: 'Polygon'," + "coordinates: [[[0, 0], [3, 6], [6, 2], [0, 0]]]}}}"); + std::unique_ptr<GeoMatchExpression> ge1(makeGeoMatchExpression(query1)), + ge2(makeGeoMatchExpression(query2)); + ASSERT(!ge1->equivalent(ge2.get())); +} + +/** + * A *geoNear* expression being not equivalent to another expression. + */ +TEST(ExpressionGeoTest, GeoNearNotEquivalent) { + BSONObj query1 = fromjson( + "{$near: {$maxDistance: 100, " + "$geometry: {type: 'Point', coordinates: [0, 0]}}}"), + query2 = fromjson( + "{$near: {$maxDistance: 100, " + "$geometry: {type: 'Point', coordinates: [1, 0]}}}"); + std::unique_ptr<GeoNearMatchExpression> gne1(makeGeoNearMatchExpression(query1)), + gne2(makeGeoNearMatchExpression(query2)); + ASSERT(!gne1->equivalent(gne2.get())); +} +} |