forked from crossfilter/reductio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata-list.spec.js
72 lines (56 loc) · 1.83 KB
/
data-list.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Counting tests
describe('Reductio data list', function() {
var max = {},
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()
.dataList(true)(group);
max = group;
});
it('has three groups', function(topic) {
expect(max.top(Infinity).length).toEqual(3);
});
it('grouping have the right maximums', function(topic) {
var rows = {};
max.top(Infinity).forEach(function(d) {
rows[d.key] = d.value;
});
expect(Math.round(rows['one'].dataList.length)).toEqual(Math.round(3));
expect(Math.round(rows['two'].dataList.length)).toEqual(Math.round(2));
expect(Math.round(rows['three'].dataList.length)).toEqual(Math.round(1));
filterDim.filterExact(1);
expect(Math.round(rows['one'].dataList.length)).toEqual(Math.round(1));
expect(rows['two'].dataList.length).toEqual(Math.round(0));
expect(rows['three'].dataList.length).toEqual(Math.round(0));
filterDim.filterAll();
expect(Math.round(rows['one'].dataList.length)).toEqual(Math.round(3));
expect(Math.round(rows['two'].dataList.length)).toEqual(Math.round(2));
expect(Math.round(rows['three'].dataList.length)).toEqual(Math.round(1));
});
});