summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorJames Cohan <james.cohan@10gen.com>2015-06-30 17:22:51 -0400
committerJames Cohan <james.cohan@10gen.com>2015-06-30 17:34:57 -0400
commit4423ee5c495bf22646de6cb58b60de2a1d9330f4 (patch)
treefb0dc2d61b6b4da2f5742af6ee5905a54c9712e8 /jstests
parent160001354901fb46fff1e6f1b4bc0a7db0407cf6 (diff)
downloadmongo-4423ee5c495bf22646de6cb58b60de2a1d9330f4.tar.gz
SERVER-8568 Add $sqrt aggregation expression
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/bugs/server8568.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/server8568.js b/jstests/aggregation/bugs/server8568.js
new file mode 100644
index 00000000000..665cdbbbeeb
--- /dev/null
+++ b/jstests/aggregation/bugs/server8568.js
@@ -0,0 +1,43 @@
+// SERVER-8568: Adding $sqrt expression
+
+// For assertErrorCode.
+load('jstests/aggregation/extras/utils.js');
+
+(function() {
+ 'use strict';
+ var coll = db.sqrt;
+ coll.drop();
+ assert.writeOK(coll.insert({_id: 0}));
+
+ // 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}]);
+ }
+
+ // Helper for testing that op results in error with code errorCode.
+ function testError(op, errorCode) {
+ var pipeline = [{$project: {_id: 0, result: op}}];
+ assertErrorCode(coll, pipeline, errorCode);
+ }
+
+ // Valid input: Numeric arg >= 0, null, or NaN.
+
+ testOp({$sqrt: [100]}, 10);
+ testOp({$sqrt: [0]}, 0);
+ // All types converted to doubles.
+ testOp({$sqrt: [NumberLong("100")]}, 10);
+ // LLONG_MAX is converted to a double.
+ testOp({$sqrt: [NumberLong("9223372036854775807")]}, 3037000499.97605);
+ // Null inputs result in null.
+ testOp({$sqrt: [null]}, null);
+ // NaN inputs result in NaN.
+ testOp({$sqrt: [NaN]}, NaN);
+
+ // Invalid input: non-numeric/non-null, arg is negative.
+
+ // Arg must be numeric or null.
+ testError({$sqrt: ["string"]}, 28713);
+ // Args cannot be negative.
+ testError({$sqrt: [-1]}, 28714);
+}()); \ No newline at end of file