/
density.test.ts
132 lines (121 loc) · 3.74 KB
/
density.test.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import {DensityTransformNode} from '../../../src/compile/data/density';
import {Transform} from '../../../src/transform';
import {PlaceholderDataFlowNode} from './util';
describe('compile/data/fold', () => {
describe('assemble', () => {
it('should return a proper vg transform', () => {
const transform: Transform = {
density: 'v',
groupby: ['a', 'b'],
cumulative: false,
counts: false,
bandwidth: 0.5,
extent: [0, 10],
minsteps: 25,
maxsteps: 200,
as: ['x', 'y']
};
const density = new DensityTransformNode(null, transform);
expect(density.assemble()).toEqual({
type: 'kde',
field: 'v',
groupby: ['a', 'b'],
cumulative: false,
counts: false,
bandwidth: 0.5,
extent: [0, 10],
minsteps: 25,
maxsteps: 200,
as: ['x', 'y']
});
});
it('should handle missing "as" field', () => {
const transform: Transform = {
density: 'v'
};
const density = new DensityTransformNode(null, transform);
expect(density.assemble()).toEqual({
type: 'kde',
field: 'v',
as: ['value', 'density']
});
});
it('should handle partial "as" field', () => {
const transform: Transform = {
density: 'v',
as: ['A'] as any
};
const density = new DensityTransformNode(null, transform);
expect(density.assemble()).toEqual({
type: 'kde',
field: 'v',
as: ['A', 'density']
});
});
it('should add steps if we group', () => {
const transform: Transform = {
density: 'v',
groupby: ['a']
};
const density = new DensityTransformNode(null, transform);
expect(density.assemble()).toEqual({
type: 'kde',
groupby: ['a'],
field: 'v',
steps: 200,
as: ['value', 'density']
});
});
});
describe('dependentFields', () => {
it('should return proper dependent fields', () => {
const transform: Transform = {
density: 'v',
groupby: ['f', 'g']
};
const density = new DensityTransformNode(null, transform);
expect(density.dependentFields()).toEqual(new Set(['v', 'f', 'g']));
});
it('should return proper dependent fields without groupby', () => {
const transform: Transform = {
density: 'v'
};
const density = new DensityTransformNode(null, transform);
expect(density.dependentFields()).toEqual(new Set(['v']));
});
});
describe('producedFields', () => {
it('should return proper produced fields for no "as"', () => {
const transform: Transform = {
density: 'v'
};
const density = new DensityTransformNode(null, transform);
expect(density.producedFields()).toEqual(new Set(['value', 'density']));
});
it('should return proper produced fields for complete "as"', () => {
const transform: Transform = {
density: 'v',
as: ['A', 'B']
};
const density = new DensityTransformNode(null, transform);
expect(density.producedFields()).toEqual(new Set(['A', 'B']));
});
});
describe('hash', () => {
it('should generate the correct hash', () => {
const transform: Transform = {
density: 'v',
as: ['A', 'B']
};
const density = new DensityTransformNode(null, transform);
expect(density.hash()).toBe('DensityTransform {"as":["A","B"],"density":"v"}');
});
});
describe('clone', () => {
it('should never clone parent', () => {
const parent = new PlaceholderDataFlowNode(null);
const density = new DensityTransformNode(parent, {density: 'v'});
expect(density.clone().parent).toBeNull();
});
});
});