MultiplyExpression_test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. "should throw Error when constructing with args": function testConstructor(){
  14. assert.throws(function(){
  15. new MultiplyExpression(1);
  16. });
  17. }
  18. },
  19. "#getOpName()": {
  20. "should return the correct op name; $multiply": function testOpName(){
  21. assert.equal(new MultiplyExpression().getOpName(), "$multiply");
  22. }
  23. },
  24. "#evaluate()": {
  25. "should return result of multiplying numbers": function testStuff(){
  26. assert.strictEqual(Expression.parseOperand({$multiply:["$a", "$b"]}).evaluateInternal({a:1, b:2}), 1*2);
  27. assert.strictEqual(Expression.parseOperand({$multiply:["$a", "$b", "$c"]}).evaluateInternal({a:1.345, b:2e45, c:0}), 1.345*2e45*0);
  28. assert.strictEqual(Expression.parseOperand({$multiply:["$a"]}).evaluateInternal({a:1}), 1);
  29. },
  30. "should throw an exception if the result is not a number": function testStuff(){
  31. assert.throws(Expression.parseOperand({$multiply:["$a", "$b"]}).evaluateInternal({a:1e199, b:1e199}));
  32. }
  33. }
  34. }
  35. };
  36. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);