forked from crossfilter/reductio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmin.spec.js
54 lines (40 loc) · 1.59 KB
/
min.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Counting tests
describe('Reductio minimum', function () {
var min = {}, filterDim;
beforeEach(function () {
var data = crossfilter([
{ foo: 'one', bar: 1 },
{ foo: 'two', bar: 2 },
{ foo: 'three', bar: 3 },
{ foo: 'one', bar: 4 },
{ foo: 'one', bar: 5 },
{ foo: 'two', bar: 6 },
]);
var dim = data.dimension(function(d) { return d.foo; });
var group = dim.group();
filterDim = data.dimension(function(d) { return d.bar; });
reductio()
.min(function(d) { return d.bar; })(group);
min = group;
});
it('has three groups', function (topic) {
expect(min.top(Infinity).length).toEqual(3);
});
it('grouping have the right minimums', function (topic) {
var values = {};
min.top(Infinity).forEach(function (d) {
values[d.key] = d.value;
});
expect(Math.round(values['one'].min)).toEqual(Math.round(1));
expect(Math.round(values['two'].min)).toEqual(Math.round(2));
expect(Math.round(values['three'].min)).toEqual(Math.round(3));
filterDim.filter(4);
expect(Math.round(values['one'].min)).toEqual(Math.round(4));
expect(values['two'].min).toBeUndefined();
expect(values['three'].min).toBeUndefined();
filterDim.filterAll();
expect(Math.round(values['one'].min)).toEqual(Math.round(1));
expect(Math.round(values['two'].min)).toEqual(Math.round(2));
expect(Math.round(values['three'].min)).toEqual(Math.round(3));
});
});