MultiplyExpression.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. "#getFactory()": {
  20. "should return the constructor for this class": function factoryIsConstructor(){
  21. assert.strictEqual(new MultiplyExpression().getFactory(), MultiplyExpression);
  22. }
  23. },
  24. "#evaluate()": {
  25. "should return result of multiplying numbers": function testStuff(){
  26. assert.strictEqual(Expression.parseOperand({$multiply:["$a", "$b"]}).evaluate({a:1, b:2}), 1*2);
  27. assert.strictEqual(Expression.parseOperand({$multiply:["$a", "$b", "$c"]}).evaluate({a:1.345, b:2e45, c:0}), 1.345*2e45*0);
  28. assert.strictEqual(Expression.parseOperand({$multiply:["$a"]}).evaluate({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"]}).evaluate({a:1e199, b:1e199}));
  32. }
  33. }
  34. }
  35. };
  36. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);