LastAccumulator_test.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
  3. var assert = require("assert"),
  4. LastAccumulator = require("../../../../lib/pipeline/accumulators/LastAccumulator");
  5. exports.LastAccumulator = {
  6. ".constructor()": {
  7. "should create instance of Accumulator": function() {
  8. assert(new LastAccumulator() instanceof LastAccumulator);
  9. },
  10. "should throw error if called with args": function() {
  11. assert.throws(function() {
  12. new LastAccumulator(123);
  13. });
  14. },
  15. },
  16. ".create()": {
  17. "should return an instance of the accumulator": function() {
  18. assert(LastAccumulator.create() instanceof LastAccumulator);
  19. },
  20. },
  21. "#process()": {
  22. "should return undefined if no inputs evaluated": function testNone() {
  23. var acc = LastAccumulator.create();
  24. assert.strictEqual(acc.getValue(), undefined);
  25. },
  26. "should return value for one input": function testOne() {
  27. var acc = LastAccumulator.create();
  28. acc.process(5);
  29. assert.strictEqual(acc.getValue(), 5);
  30. },
  31. "should return missing for one missing input": function testMissing() {
  32. var acc = LastAccumulator.create();
  33. acc.process(undefined);
  34. assert.strictEqual(acc.getValue(), undefined);
  35. },
  36. "should return last of two inputs": function testTwo() {
  37. var acc = LastAccumulator.create();
  38. acc.process(5);
  39. acc.process(7);
  40. assert.strictEqual(acc.getValue(), 7);
  41. },
  42. "should return last of two inputs (even if last is missing)": function testFirstMissing() {
  43. var acc = LastAccumulator.create();
  44. acc.process(7);
  45. acc.process(undefined);
  46. assert.strictEqual(acc.getValue(), undefined);
  47. },
  48. },
  49. "#getValue()": {
  50. "should get value the same for shard and router": function() {
  51. var acc = LastAccumulator.create();
  52. assert.strictEqual(acc.getValue(false), acc.getValue(true));
  53. acc.process(123);
  54. assert.strictEqual(acc.getValue(false), acc.getValue(true));
  55. },
  56. },
  57. "#reset()": {
  58. "should reset to missing": function() {
  59. var acc = LastAccumulator.create();
  60. assert.strictEqual(acc.getValue(), undefined);
  61. acc.process(123);
  62. assert.notEqual(acc.getValue(), undefined);
  63. acc.reset();
  64. assert.strictEqual(acc.getValue(), undefined);
  65. assert.strictEqual(acc.getValue(true), undefined);
  66. },
  67. },
  68. "#getOpName()": {
  69. "should return the correct op name; $last": function() {
  70. assert.equal(new LastAccumulator().getOpName(), "$last");
  71. },
  72. },
  73. };