SetDifferenceExpression.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. var assert = require("assert"),
  3. SetDifferenceExpression = require("../../../../lib/pipeline/expressions/SetDifferenceExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "SetDifferenceExpression": {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function testConstructor() {
  9. assert.doesNotThrow(function() {
  10. new SetDifferenceExpression();
  11. });
  12. }
  13. },
  14. "#getOpName()": {
  15. "should return the correct op name; $setdifference": function testOpName() {
  16. assert.equal(new SetDifferenceExpression().getOpName(), "$setdifference");
  17. }
  18. },
  19. "#evaluateInternal()": {
  20. "Should fail if array1 is not an array": function testArg1() {
  21. var array1 = "not an array",
  22. array2 = [6, 7, 8, 9];
  23. assert.throws(function() {
  24. Expression.parseOperand({
  25. $setdifference: ["$array1", "$array2"]
  26. }).evaluateInternal({
  27. array1: array1,
  28. array2: array2
  29. });
  30. });
  31. },
  32. "Should fail if array2 is not an array": function testArg2() {
  33. var array1 = [1, 2, 3, 4],
  34. array2 = "not an array";
  35. assert.throws(function() {
  36. Expression.parseOperand({
  37. $setdifference: ["$array1", "$array2"]
  38. }).evaluateInternal({
  39. array1: array1,
  40. array2: array2
  41. });
  42. });
  43. },
  44. "Should fail if both are not an array": function testArg1andArg2() {
  45. var array1 = "not an array",
  46. array2 = "not an array";
  47. assert.throws(function() {
  48. Expression.parseOperand({
  49. $setdifference: ["$array1", "$array2"]
  50. }).evaluateInternal({
  51. array1: array1,
  52. array2: array2
  53. });
  54. });
  55. },
  56. "Should pass and return a difference between the arrays": function testBasicAssignment() {
  57. var array1 = [1, 9, 2, 3, 4, 5],
  58. array2 = [5, 6, 7, 2, 8, 9];
  59. assert.strictEqual(Expression.parseOperand({
  60. $setdifference: ["$array1", "$array2"]
  61. }).evaluateInternal({
  62. array1: array1,
  63. array2: array2
  64. }), [1, 3, 4, 6, 7 , 8]);
  65. },
  66. }
  67. }
  68. };
  69. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);