ModExpression.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. var assert = require("assert"),
  3. ModExpression = require("../../../../lib/pipeline/expressions/ModExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "ModExpression": {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function testConstructor(){
  9. assert.doesNotThrow(function(){
  10. new ModExpression();
  11. });
  12. }
  13. },
  14. "#getOpName()": {
  15. "should return the correct op name; $mod": function testOpName(){
  16. assert.equal(new ModExpression().getOpName(), "$mod");
  17. }
  18. },
  19. "#getFactory()": {
  20. "should return the constructor for this class": function factoryIsConstructor(){
  21. assert.strictEqual(new ModExpression().getFactory(), undefined);
  22. }
  23. },
  24. "#evaluate()": {
  25. "should return rhs if rhs is undefined or null": function testStuff(){
  26. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:20.453, rhs:null}), null);
  27. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:20.453}), undefined);
  28. },
  29. "should return lhs if lhs is undefined or null": function testStuff(){
  30. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:null, rhs:20.453}), null);
  31. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({rhs:20.453}), undefined);
  32. },
  33. "should return undefined if rhs is 0": function testStuff(){
  34. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:20.453, rhs:0}), undefined);
  35. },
  36. "should return proper mod of rhs and lhs if both are numbers": function testStuff(){
  37. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:234.4234, rhs:45}), 234.4234 % 45);
  38. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:0, rhs:45}), 0 % 45);
  39. assert.strictEqual(Expression.parseOperand({$mod:["$lhs", "$rhs"]}).evaluate({lhs:-6, rhs:-0.5}), -6 % -0.5);
  40. }
  41. }
  42. }
  43. };
  44. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);