MultiplyExpression.js 1.5 KB

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