forked from crossfilter/reductio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcount.spec.js
44 lines (36 loc) · 1.17 KB
/
count.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
// Counting tests
describe('Reductio count', function () {
var group;
beforeEach(function () {
var data = crossfilter([
{ foo: 'one' },
{ foo: 'two' },
{ foo: 'three' },
{ foo: 'one' },
{ foo: 'one' },
{ foo: 'two' },
]);
var dim = data.dimension(function(d) { return d.foo; });
group = dim.group();
var reducer = reductio()
.count(true);
reducer(group);
});
it('has three groups', function () {
expect(group.top(Infinity).length).toEqual(3);
});
it('grouping have the right counts', function () {
var values = {};
group.top(Infinity).forEach(function (d) {
values[d.key] = d.value;
});
expect(values['one'].count).toEqual(3);
expect(values['two'].count).toEqual(2);
expect(values['three'].count).toEqual(1);
});
it('has a user-defined property name', function() {
reductio().count(true, 'otherCount')(group);
expect(group.top(1)[0].value.otherCount).toEqual(3);
expect(group.top(1)[0].value.count).toEqual(undefined);
})
});