Browse Source

Refs #5298. Fixed minor bugs in accumulators during acceptance.

Spencer Rathbun 11 years ago
parent
commit
943c8af61d

+ 6 - 5
lib/pipeline/accumulators/AvgAccumulator.js

@@ -1,6 +1,6 @@
 "use strict";
 
-/** 
+/**
  * A class for constructing accumulators to calculate avg.
  * @class AvgAccumulator
  * @namespace mungedb-aggregate.pipeline.accumulators
@@ -51,10 +51,11 @@ proto.getValue = function getValue(toBeMerged){
 			throw new Error("$sum resulted in a non-numeric type");
 		}
 	} else {
-		return {
-			subTotalName : this.total,
-			countName : this.count
-		};
+		var ret = {};
+		ret[this.subTotalName] = this.total;
+		ret[this.countName] = this.count;
+
+		return ret;
 	}
 };
 

+ 3 - 3
lib/pipeline/accumulators/MinMaxAccumulator.js

@@ -1,6 +1,6 @@
 "use strict";
 
-/** 
+/**
  * Constructor for MinMaxAccumulator, wraps SingleValueAccumulator's constructor and adds flag to track whether we have started or not
  * @class MinMaxAccumulator
  * @namespace mungedb-aggregate.pipeline.accumulators
@@ -12,7 +12,7 @@ var MinMaxAccumulator = module.exports = function MinMaxAccumulator(sense){
 	base.call(this);
 	this.sense = sense; /* 1 for min, -1 for max; used to "scale" comparison */
 	if (this.sense !== 1 && this.sense !== -1) throw new Error("this should never happen");
-}, klass = MinMaxAccumulator, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+}, klass = MinMaxAccumulator, base = require("./Accumulator"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 // DEPENDENCIES
 var Value = require("../Value");
@@ -50,4 +50,4 @@ proto.processInternal = function processInternal(input, merging) {
 	}
 
 	return this.value;
-};
+};

+ 0 - 1
test/lib/pipeline/accumulators/AddToSetAccumulator.js

@@ -58,7 +58,6 @@ module.exports = {
 			"should return array with one element that equals 5": function test5InSet() {
 				var acc = createAccumulator();
 				acc.processInternal(5);
-				console.log(acc.set);
 				acc.processInternal(5);
 				var value = acc.getValue();
 				assert.deepEqual(JSON.stringify(value), JSON.stringify([5]));