diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2015-07-30 15:03:08 -0400 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2015-08-07 16:56:28 -0400 |
commit | 326aa0029a29f06772665750400473db69945234 (patch) | |
tree | 0afab3691dcb9b98c94285127e3ea583212be0b4 /jstests/aggregation | |
parent | 51a8f1ca3dee1f4698dad6f9cf34ac11edb2e2c3 (diff) | |
download | mongo-326aa0029a29f06772665750400473db69945234.tar.gz |
SERVER-19548 Add $ceil, $floor, and $trunc aggregation expressions
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/bugs/server10176.js | 4 | ||||
-rw-r--r-- | jstests/aggregation/bugs/server18427.js | 10 | ||||
-rw-r--r-- | jstests/aggregation/bugs/server19548.js | 55 | ||||
-rw-r--r-- | jstests/aggregation/bugs/server8568.js | 4 |
4 files changed, 64 insertions, 9 deletions
diff --git a/jstests/aggregation/bugs/server10176.js b/jstests/aggregation/bugs/server10176.js index 4809bcc26d7..50d02ce3a8e 100644 --- a/jstests/aggregation/bugs/server10176.js +++ b/jstests/aggregation/bugs/server10176.js @@ -57,8 +57,8 @@ load('jstests/aggregation/extras/utils.js'); // Invalid // using $abs on string - assertErrorCode(coll, [{$project: {a: {$abs: "string"}}}], 28681); + assertErrorCode(coll, [{$project: {a: {$abs: "string"}}}], 28765); // using $abs on LLONG_MIN (-2 ^ 63) assertErrorCode(coll, [{$project: {a: {$abs: NumberLong("-9223372036854775808")}}}], 28680); -}());
\ No newline at end of file +}()); diff --git a/jstests/aggregation/bugs/server18427.js b/jstests/aggregation/bugs/server18427.js index d164f56f4f1..2fc9f4b70ad 100644 --- a/jstests/aggregation/bugs/server18427.js +++ b/jstests/aggregation/bugs/server18427.js @@ -43,18 +43,18 @@ load('jstests/aggregation/extras/utils.js'); // Args/bases must be numeric or null. assertErrorCode(coll, [{$project: {log: {$log: ["string", 5]}}}], 28756); assertErrorCode(coll, [{$project: {log: {$log: [5, "string"]}}}], 28757); - assertErrorCode(coll, [{$project: {log10: {$log10: ["string"]}}}], 28760); - assertErrorCode(coll, [{$project: {ln: {$ln: ["string"]}}}], 28766); + assertErrorCode(coll, [{$project: {log10: {$log10: ["string"]}}}], 28765); + assertErrorCode(coll, [{$project: {ln: {$ln: ["string"]}}}], 28765); // Args/bases cannot equal 0. assertErrorCode(coll, [{$project: {log: {$log: [0, 5]}}}], 28758); assertErrorCode(coll, [{$project: {log: {$log: [5, 0]}}}], 28759); assertErrorCode(coll, [{$project: {log10: {$log10: [0]}}}], 28761); - assertErrorCode(coll, [{$project: {ln: {$ln: [0]}}}], 28767); + assertErrorCode(coll, [{$project: {ln: {$ln: [0]}}}], 28766); // Args/bases cannot be negative. assertErrorCode(coll, [{$project: {log: {$log: [-1, 5]}}}], 28758); assertErrorCode(coll, [{$project: {log: {$log: [5, -1]}}}], 28759); assertErrorCode(coll, [{$project: {log10: {$log10: [-1]}}}], 28761); - assertErrorCode(coll, [{$project: {ln: {$ln: [-1]}}}], 28767); + assertErrorCode(coll, [{$project: {ln: {$ln: [-1]}}}], 28766); // Base can't equal 1. assertErrorCode(coll, [{$project: {log: {$log: [5, 1]}}}], 28759); @@ -108,4 +108,4 @@ load('jstests/aggregation/extras/utils.js'); assertErrorCode(coll, [{$project: {pow: {$pow: ["string", 5]}}}], 28762); assertErrorCode(coll, [{$project: {pow: {$pow: [5, "string"]}}}], 28763); assertErrorCode(coll, [{$project: {exp: {$exp: ["string"]}}}], 28765); -}());
\ No newline at end of file +}()); diff --git a/jstests/aggregation/bugs/server19548.js b/jstests/aggregation/bugs/server19548.js new file mode 100644 index 00000000000..82030884d41 --- /dev/null +++ b/jstests/aggregation/bugs/server19548.js @@ -0,0 +1,55 @@ +// SERVER-19548: Add $floor, $ceil, and $trunc aggregation expressions. + +// For assertErrorCode. +load("jstests/aggregation/extras/utils.js"); + +(function() { + "use strict"; + var coll = db.server19548; + coll.drop(); + // Seed collection so that the pipeline will execute. + assert.writeOK(coll.insert({})); + + // Helper for testing that op returns expResult. + function testOp(op, expResult) { + var pipeline = [{$project: {_id: 0, result: op}}]; + assert.eq(coll.aggregate(pipeline).toArray(), [{result: expResult}]); + } + + testOp({$ceil: NumberLong(4)}, NumberLong(4)); + testOp({$ceil: NaN}, NaN); + testOp({$ceil: Infinity}, Infinity); + testOp({$ceil: -Infinity}, -Infinity); + testOp({$ceil: null}, null); + testOp({$ceil: -2.0}, -2.0); + testOp({$ceil: 0.9}, 1.0); + testOp({$ceil: -1.2}, -1.0); + + testOp({$floor: NumberLong(4)}, NumberLong(4)); + testOp({$floor: NaN}, NaN); + testOp({$floor: Infinity}, Infinity); + testOp({$floor: -Infinity}, -Infinity); + testOp({$floor: null}, null); + testOp({$floor: -2.0}, -2.0); + testOp({$floor: 0.9}, 0.0); + testOp({$floor: -1.2}, -2.0); + + testOp({$trunc: NumberLong(4)}, NumberLong(4)); + testOp({$trunc: NaN}, NaN); + testOp({$trunc: Infinity}, Infinity); + testOp({$trunc: -Infinity}, -Infinity); + testOp({$trunc: null}, null); + testOp({$trunc: -2.0}, -2.0); + testOp({$trunc: 0.9}, 0.0); + testOp({$trunc: -1.2}, -1.0); + + // More than 1 argument. + assertErrorCode(coll, [{$project: {a: {$ceil: [1, 2]}}}], 16020); + assertErrorCode(coll, [{$project: {a: {$floor: [1, 2]}}}], 16020); + assertErrorCode(coll, [{$project: {a: {$trunc: [1, 2]}}}], 16020); + + // Non-numeric input. + assertErrorCode(coll, [{$project: {a: {$ceil: "string"}}}], 28765); + assertErrorCode(coll, [{$project: {a: {$floor: "string"}}}], 28765); + assertErrorCode(coll, [{$project: {a: {$trunc: "string"}}}], 28765); +}()); diff --git a/jstests/aggregation/bugs/server8568.js b/jstests/aggregation/bugs/server8568.js index a03472ad4fa..7490b286e38 100644 --- a/jstests/aggregation/bugs/server8568.js +++ b/jstests/aggregation/bugs/server8568.js @@ -37,7 +37,7 @@ load('jstests/aggregation/extras/utils.js'); // Invalid input: non-numeric/non-null, arg is negative. // Arg must be numeric or null. - testError({$sqrt: ["string"]}, 28715); + testError({$sqrt: ["string"]}, 28765); // Args cannot be negative. testError({$sqrt: [-1]}, 28714); -}());
\ No newline at end of file +}()); |