FirstAccumulator.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. var assert = require("assert"),
  3. FirstAccumulator = require("../../../../lib/pipeline/accumulators/FirstAccumulator");
  4. function createAccumulator(){
  5. return new FirstAccumulator();
  6. }
  7. module.exports = {
  8. "FirstAccumulator": {
  9. "constructor()": {
  10. "should not throw Error when constructing without args": function testConstructor(){
  11. assert.doesNotThrow(function(){
  12. new FirstAccumulator();
  13. });
  14. }
  15. },
  16. "#getOpName()": {
  17. "should return the correct op name; $first": function testOpName(){
  18. assert.equal(new FirstAccumulator().getOpName(), "$first");
  19. }
  20. },
  21. "#getFactory()": {
  22. "should return the constructor for this class": function factoryIsConstructor(){
  23. assert.strictEqual(new FirstAccumulator().getFactory(), FirstAccumulator);
  24. }
  25. },
  26. "#processInternal()": {
  27. "The accumulator has no value": function none() {
  28. // The accumulator returns no value in this case.
  29. var acc = createAccumulator();
  30. assert.ok(!acc.getValue());
  31. },
  32. "The accumulator uses processInternal on one input and retains its value": function one() {
  33. var acc = createAccumulator();
  34. acc.processInternal(5);
  35. assert.strictEqual(acc.getValue(), 5);
  36. },
  37. "The accumulator uses processInternal on one input with the field missing and retains undefined": function missing() {
  38. var acc = createAccumulator();
  39. acc.processInternal();
  40. assert.strictEqual(acc.getValue(), undefined);
  41. },
  42. "The accumulator uses processInternal on two inputs and retains the value in the first": function two() {
  43. var acc = createAccumulator();
  44. acc.processInternal(5);
  45. acc.processInternal(7);
  46. assert.strictEqual(acc.getValue(), 5);
  47. },
  48. "The accumulator uses processInternal on two inputs and retains the undefined value in the first": function firstMissing() {
  49. var acc = createAccumulator();
  50. acc.processInternal();
  51. acc.processInternal(7);
  52. assert.strictEqual(acc.getValue(), undefined);
  53. }
  54. }
  55. }
  56. };
  57. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);