diff --git a/spec/reduce_mean.js b/spec/reduce_mean.js index 91610c9..2d1dedc 100644 --- a/spec/reduce_mean.js +++ b/spec/reduce_mean.js @@ -1,15 +1,15 @@ var data = [ - { id : 1, g : "A", w : 1, x : 10 }, - { id : 2, g : "A", w : 3, x : 4 }, - { id : 3, g : "A", w : 2, x : 2 }, - { id : 4, g : "A", w : 0, x : 0 }, - { id : 5, g : "A", w : 1, x : 2 }, - { id : 6, g : "B", w : 2.5, x : 0 }, - { id : 7, g : "B", w : 10, x : 0.15 }, - { id : 8, g : "B", w : 5.2, x : 0.09 }, - { id : 9, g : "B", w : 0.2, x : 0.2 }, - { id : 10, g : "B", w : 2, x : 0.1 } + { id : 1, g : "A", w : 1, x : 10 }, + { id : 2, g : "A", w : 3, x : 4 }, + { id : 3, g : "A", w : 2, x : 2 }, + { id : 4, g : "A", w : 0, x : 10 }, + { id : 5, g : "A", w : 1, x : 2 }, + { id : 6, g : "B", w : 10, x : 0 }, + { id : 7, g : "B", w : 10, x : 2 }, + { id : 8, g : "B", w : 4, x : 2 }, + { id : 9, g : "B", w : 0.2, x : 0.2 }, + { id : 10, g : "B", w : 2, x : 10 } ], cross = require('crossfilter')(data), decimal = require('decimal.js'), @@ -22,7 +22,7 @@ describe('Reduce by (weighted) mean', function() { var dimf = cross.dimension(function(d){ return d.id; }), - dimg = cross.dimension(function(d){ return d.f; }), + dimg = cross.dimension(function(d){ return d.g; }), red_x = function(d){ return d.x }, red_w = function(d){ return d.w }, @@ -77,55 +77,55 @@ describe('Reduce by (weighted) mean', function() { describe('When weight function is not provided, it sets weight to 1 for every data point', function() { - it('whole dataset to 1.854', function() { + it('whole dataset to 4.22', function() { reduceVal = reduceAcc_1( reduceAll_1.value() ); - expect(reduceVal).toBe(1.854); + expect(reduceVal).toBe(4.22); }); }); - // describe('calculates reduction values correctly using arbitrary precision arithmetic', function() { + describe('calculates reduction values correctly using arbitrary precision arithmetic', function() { - // it('whole dataset to 18.6', function() { - // reduceVal = reduceAcc( reduceAll.value() ); - // expect(reduceVal).toBe(18.6); - // }); + it('whole dataset to 2.2903614457831325', function() { + reduceVal = reduceAcc_w( reduceAll_w.value() ); + expect(reduceVal).toBe(2.2903614457831325); + }); - // it('group A to 18', function() { - // dimf.filter('A'); - // reduceVal = reduceAcc( reduce.all()[0].value ); - // expect( reduceVal ).toBe(18); - // }); + it('group A to 4', function() { + dimf.filter('A'); + reduceVal = reduceAcc_w( reduce_w.all()[0].value ); + expect( reduceVal ).toBe(4); + }); - // it('group B to 0.6', function() { - // dimf.filter('B'); - // reduceVal = reduceAcc( reduce.all()[1].value ); - // expect( reduceVal ).toBe(0.6); - // }); + it('group B to 1.833587786259542', function() { + dimf.filter('B'); + reduceVal = reduceAcc_w( reduce_w.all()[1].value ); + expect( reduceVal ).toBe(1.833587786259542); + }); - // }); + }); - // describe('also when a dimension is filtered', function() { + describe('also when a dimension is filtered', function() { - // beforeEach(function() { - // dimf.filter(6); - // }); + beforeEach(function() { + dimf.filter(9); + }); - // it('whole dataset reduced to 0', function() { - // reduceVal = reduceAcc( reduceAll.value() ); - // expect(reduceVal).toBe(0); - // }); + it('whole dataset reduced to 0.2', function() { + reduceVal = reduceAcc_w( reduceAll_w.value() ); + expect(reduceVal).toBe(0.2); + }); - // it('group A reduced to 0', function() { - // reduceVal = reduceAcc( reduce.all()[0].value ); - // expect( reduceVal ).toBe(0); - // }); + it('group A reduced to 0', function() { + reduceVal = reduceAcc_w( reduce_w.all()[0].value ); + expect( reduceVal ).toBe(0); + }); - // it('group B reduced to 0', function() { - // reduceVal = reduceAcc( reduce.all()[1].value ); - // expect( reduceVal ).toBe(0); - // }); + it('group B reduced to 0.2', function() { + reduceVal = reduceAcc_w( reduce_w.all()[1].value ); + expect( reduceVal ).toBe(0.2); + }); - // }); + }); }); \ No newline at end of file