ModExpression.js 2.0 KB

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