| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- "use strict";
- if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
- var assert = require("assert"),
- ModExpression = require("../../../../lib/pipeline/expressions/ModExpression"),
- VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
- VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
- Expression = require("../../../../lib/pipeline/expressions/Expression");
- exports.ModExpression = {
- "constructor()": {
- "should construct instance": function() {
- assert(new ModExpression() instanceof ModExpression);
- assert(new ModExpression() instanceof Expression);
- },
- "should error if given args": function() {
- assert.throws(function() {
- new ModExpression("bad stuff");
- });
- },
- },
- "#getOpName()": {
- "should return the correct op name; $mod": function() {
- assert.equal(new ModExpression().getOpName(), "$mod");
- },
- },
- "#evaluate()": {
- "should return modulus of two numbers": function() {
- var idGenerator = new VariablesIdGenerator(),
- vps = new VariablesParseState(idGenerator),
- expr = Expression.parseOperand({$mod: ["$a", "$b"]}, vps),
- input = {a: 6, b: 2};
- assert.strictEqual(expr.evaluate(input), 0);
- },
- "should return null if first is null": function() {
- var idGenerator = new VariablesIdGenerator(),
- vps = new VariablesParseState(idGenerator),
- expr = Expression.parseOperand({$mod: ["$a", "$b"]}, vps),
- input = {a: null, b: 2};
- assert.strictEqual(expr.evaluate(input), null);
- },
- "should return null if first is undefined": function() {
- var idGenerator = new VariablesIdGenerator(),
- vps = new VariablesParseState(idGenerator),
- expr = Expression.parseOperand({$mod: ["$a", "$b"]}, vps),
- input = {a: undefined, b: 2};
- assert.strictEqual(expr.evaluate(input), null);
- },
- "should return null if second is null": function() {
- var idGenerator = new VariablesIdGenerator(),
- vps = new VariablesParseState(idGenerator),
- expr = Expression.parseOperand({$mod: ["$a", "$b"]}, vps),
- input = {a: 11, b: null};
- assert.strictEqual(expr.evaluate(input), null);
- },
- "should return null if second is undefined": function() {
- var idGenerator = new VariablesIdGenerator(),
- vps = new VariablesParseState(idGenerator),
- expr = Expression.parseOperand({$mod: ["$a", "$b"]}, vps),
- input = {a: 42, b: undefined};
- assert.strictEqual(expr.evaluate(input), null);
- },
- },
- };
|