MultiplyExpression.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var assert = require("assert"),
  3. MultiplyExpression = require("../../../../lib/pipeline/expressions/MultiplyExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "MultiplyExpression": {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function testConstructor(){
  9. assert.doesNotThrow(function(){
  10. new MultiplyExpression();
  11. });
  12. }
  13. },
  14. "#getOpName()": {
  15. "should return the correct op name; $multiply": function testOpName(){
  16. assert.equal(new MultiplyExpression().getOpName(), "$multiply");
  17. }
  18. },
  19. "#evaluate()": {
  20. "should return result of multiplying numbers": function testStuff(){
  21. assert.strictEqual(Expression.parseOperand({$multiply:["$a", "$b"]}).evaluateInternal({a:1, b:2}), 1*2);
  22. assert.strictEqual(Expression.parseOperand({$multiply:["$a", "$b", "$c"]}).evaluateInternal({a:1.345, b:2e45, c:0}), 1.345*2e45*0);
  23. assert.strictEqual(Expression.parseOperand({$multiply:["$a"]}).evaluateInternal({a:1}), 1);
  24. },
  25. "should throw an exception if the result is not a number": function testStuff(){
  26. assert.throws(Expression.parseOperand({$multiply:["$a", "$b"]}).evaluateInternal({a:1e199, b:1e199}));
  27. }
  28. }
  29. }
  30. };
  31. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);