forked from crossfilter/reductio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexception-count.spec.js
54 lines (44 loc) · 1.59 KB
/
exception-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
45
46
47
48
49
50
51
52
53
54
// Counting tests
describe('Reductio exception count', function () {
var group;
var accGroup;
beforeEach(function () {
var data = crossfilter([
{ foo: 'one', bar: 'A' },
{ foo: 'two', bar: 'B' },
{ foo: 'three', bar: 'A' },
{ foo: 'one', bar: 'B' },
{ foo: 'one', bar: 'A' },
{ foo: 'two', bar: 'B' },
]);
var dim = data.dimension(function(d) { return d.foo; });
group = dim.group();
accGroup = dim.group();
var reducer = reductio()
.exception(function(d) { return d.bar; })
.exceptionCount(true);
reducer(group);
reductio().exceptionCount(function(d) { return d.bar; })(accGroup);
});
it('has three groups', function () {
expect(group.top(Infinity).length).toEqual(3);
});
it('grouping has the right counts', function () {
var values = {};
group.top(Infinity).forEach(function (d) {
values[d.key] = d.value;
});
expect(values['one'].exceptionCount).toEqual(2);
expect(values['two'].exceptionCount).toEqual(1);
expect(values['three'].exceptionCount).toEqual(1);
});
it('accessor-based grouping has the right counts', function () {
var values = {};
accGroup.top(Infinity).forEach(function (d) {
values[d.key] = d.value;
});
expect(values['one'].exceptionCount).toEqual(2);
expect(values['two'].exceptionCount).toEqual(1);
expect(values['three'].exceptionCount).toEqual(1);
});
});