MinAccumulator.js 2.0 KB

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