@@ -25,7 +25,6 @@ const raggedFixtureData = [
25
25
describe ( " utils" , function ( ) {
26
26
27
27
describe ( ".PivotData()" , function ( ) {
28
- const aggregator = utils . aggregators [ "Sum over Sum" ] ( [ "a" , "b" ] ) ;
29
28
30
29
describe ( "with no options" , function ( ) {
31
30
const aoaInput = [ [ "a" , "b" ] , [ 1 , 2 ] , [ 3 , 4 ] ] ;
@@ -39,7 +38,8 @@ describe(" utils", function() {
39
38
40
39
describe ( "with array-of-array input" , function ( ) {
41
40
const aoaInput = [ [ "a" , "b" ] , [ 1 , 2 ] , [ 3 , 4 ] ] ;
42
- const pd = new utils . PivotData ( { data : aoaInput , aggregator} ) ;
41
+ const pd = new utils . PivotData ( {
42
+ data : aoaInput , aggregatorName : "Sum over Sum" , vals : [ "a" , "b" ] } ) ;
43
43
44
44
it ( "has the correct grand total value" , ( ) =>
45
45
expect ( pd . getAggregator ( [ ] , [ ] ) . value ( ) )
@@ -49,7 +49,8 @@ describe(" utils", function() {
49
49
50
50
describe ( "with array-of-object input" , function ( ) {
51
51
const aosInput = [ { a :1 , b :2 } , { a :3 , b :4 } ] ;
52
- const pd = new utils . PivotData ( { data : aosInput , aggregator} ) ;
52
+ const pd = new utils . PivotData ( {
53
+ data : aosInput , aggregatorName : "Sum over Sum" , vals : [ "a" , "b" ] } ) ;
53
54
54
55
it ( "has the correct grand total value" , ( ) =>
55
56
expect ( pd . getAggregator ( [ ] , [ ] ) . value ( ) )
@@ -59,7 +60,8 @@ describe(" utils", function() {
59
60
60
61
describe ( "with ragged array-of-object input" , function ( ) {
61
62
const raggedAosInput = [ { a :1 } , { b :4 } , { a : 3 , b : 2 } ] ;
62
- const pd = new utils . PivotData ( { data : raggedAosInput , aggregator} ) ;
63
+ const pd = new utils . PivotData ( {
64
+ data : raggedAosInput , aggregatorName : "Sum over Sum" , vals : [ "a" , "b" ] } ) ;
63
65
64
66
it ( "has the correct grand total value" , ( ) =>
65
67
expect ( pd . getAggregator ( [ ] , [ ] ) . value ( ) )
@@ -72,7 +74,8 @@ describe(" utils", function() {
72
74
record ( { a :1 , b :2 } ) ;
73
75
record ( { a :3 , b :4 } ) ;
74
76
} ;
75
- const pd = new utils . PivotData ( { data : functionInput , aggregator} ) ;
77
+ const pd = new utils . PivotData ( {
78
+ data : functionInput , aggregatorName : "Sum over Sum" , vals : [ "a" , "b" ] } ) ;
76
79
77
80
it ( "has the correct grand total value" , ( ) =>
78
81
expect ( pd . getAggregator ( [ ] , [ ] ) . value ( ) )
@@ -142,125 +145,132 @@ describe(" utils", function() {
142
145
143
146
describe ( ".aggregatorTemplates" , function ( ) {
144
147
145
- const getVal = ( agg ) => new utils . PivotData ( { data : fixtureData , aggregator : agg } ) . getAggregator ( [ ] , [ ] ) . value ( ) ;
148
+ const getVal = ( agg , vals ) => {
149
+ return new utils . PivotData ( {
150
+ data : fixtureData ,
151
+ aggregators : { agg} ,
152
+ aggregatorName : "agg" ,
153
+ vals
154
+ } ) . getAggregator ( [ ] , [ ] ) . value ( ) ;
155
+ }
146
156
const tpl = utils . aggregatorTemplates ;
147
157
148
158
describe ( ".count" , ( ) =>
149
159
it ( "works" , ( ) =>
150
- expect ( getVal ( tpl . count ( ) ( ) ) )
160
+ expect ( getVal ( tpl . count ( ) , [ ] ) )
151
161
. toBe ( 4 )
152
162
)
153
163
) ;
154
164
155
165
describe ( ".countUnique" , ( ) =>
156
166
it ( "works" , ( ) =>
157
- expect ( getVal ( tpl . countUnique ( ) ( [ 'gender' ] ) ) )
167
+ expect ( getVal ( tpl . countUnique ( ) , [ 'gender' ] ) )
158
168
. toBe ( 2 )
159
169
)
160
170
) ;
161
171
162
172
describe ( ".listUnique" , ( ) =>
163
173
it ( "works" , ( ) =>
164
- expect ( getVal ( tpl . listUnique ( ) ( [ 'gender' ] ) ) )
174
+ expect ( getVal ( tpl . listUnique ( ) , [ 'gender' ] ) )
165
175
. toBe ( 'male,female' )
166
176
)
167
177
) ;
168
178
169
179
describe ( ".average" , ( ) =>
170
180
it ( "works" , ( ) =>
171
- expect ( getVal ( tpl . average ( ) ( [ 'trials' ] ) ) )
181
+ expect ( getVal ( tpl . average ( ) , [ 'trials' ] ) )
172
182
. toBe ( 103 )
173
183
)
174
184
) ;
175
185
176
186
describe ( ".sum" , ( ) =>
177
187
it ( "works" , ( ) =>
178
- expect ( getVal ( tpl . sum ( ) ( [ 'trials' ] ) ) )
188
+ expect ( getVal ( tpl . sum ( ) , [ 'trials' ] ) )
179
189
. toBe ( 412 )
180
190
)
181
191
) ;
182
192
183
193
describe ( ".min" , ( ) =>
184
194
it ( "works" , ( ) =>
185
- expect ( getVal ( tpl . min ( ) ( [ 'trials' ] ) ) )
195
+ expect ( getVal ( tpl . min ( ) , [ 'trials' ] ) )
186
196
. toBe ( 95 )
187
197
)
188
198
) ;
189
199
190
200
describe ( ".max" , ( ) =>
191
201
it ( "works" , ( ) =>
192
- expect ( getVal ( tpl . max ( ) ( [ 'trials' ] ) ) )
202
+ expect ( getVal ( tpl . max ( ) , [ 'trials' ] ) )
193
203
. toBe ( 112 )
194
204
)
195
205
) ;
196
206
197
207
describe ( ".first" , ( ) =>
198
208
it ( "works" , ( ) =>
199
- expect ( getVal ( tpl . first ( ) ( [ 'name' ] ) ) )
209
+ expect ( getVal ( tpl . first ( ) , [ 'name' ] ) )
200
210
. toBe ( 'Carol' )
201
211
)
202
212
) ;
203
213
204
214
describe ( ".last" , ( ) =>
205
215
it ( "works" , ( ) =>
206
- expect ( getVal ( tpl . last ( ) ( [ 'name' ] ) ) )
216
+ expect ( getVal ( tpl . last ( ) , [ 'name' ] ) )
207
217
. toBe ( 'Nick' )
208
218
)
209
219
) ;
210
220
211
221
describe ( ".average" , ( ) =>
212
222
it ( "works" , ( ) =>
213
- expect ( getVal ( tpl . average ( ) ( [ 'trials' ] ) ) )
223
+ expect ( getVal ( tpl . average ( ) , [ 'trials' ] ) )
214
224
. toBe ( 103 )
215
225
)
216
226
) ;
217
227
218
228
describe ( ".median" , ( ) =>
219
229
it ( "works" , ( ) =>
220
- expect ( getVal ( tpl . median ( ) ( [ 'trials' ] ) ) )
230
+ expect ( getVal ( tpl . median ( ) , [ 'trials' ] ) )
221
231
. toBe ( 102.5 )
222
232
)
223
233
) ;
224
234
225
235
describe ( ".quantile" , ( ) =>
226
236
it ( "works" , function ( ) {
227
- expect ( getVal ( tpl . quantile ( 0 ) ( [ 'trials' ] ) ) )
237
+ expect ( getVal ( tpl . quantile ( 0 ) , [ 'trials' ] ) )
228
238
. toBe ( 95 ) ;
229
- expect ( getVal ( tpl . quantile ( 0.1 ) ( [ 'trials' ] ) ) )
239
+ expect ( getVal ( tpl . quantile ( 0.1 ) , [ 'trials' ] ) )
230
240
. toBe ( 98.5 ) ;
231
- expect ( getVal ( tpl . quantile ( 0.25 ) ( [ 'trials' ] ) ) )
241
+ expect ( getVal ( tpl . quantile ( 0.25 ) , [ 'trials' ] ) )
232
242
. toBe ( 98.5 ) ;
233
- expect ( getVal ( tpl . quantile ( 1 / 3 ) ( [ 'trials' ] ) ) )
243
+ expect ( getVal ( tpl . quantile ( 1 / 3 ) , [ 'trials' ] ) )
234
244
. toBe ( 102 ) ;
235
- expect ( getVal ( tpl . quantile ( 1 ) ( [ 'trials' ] ) ) )
245
+ expect ( getVal ( tpl . quantile ( 1 ) , [ 'trials' ] ) )
236
246
. toBe ( 112 ) ;
237
247
} )
238
248
) ;
239
249
240
250
describe ( ".var" , ( ) =>
241
251
it ( "works" , ( ) =>
242
- expect ( getVal ( tpl . var ( ) ( [ 'trials' ] ) ) )
252
+ expect ( getVal ( tpl . var ( ) , [ 'trials' ] ) )
243
253
. toBe ( 48.666666666666686 )
244
254
)
245
255
) ;
246
256
247
257
describe ( ".stdev" , ( ) =>
248
258
it ( "works" , ( ) =>
249
- expect ( getVal ( tpl . stdev ( ) ( [ 'trials' ] ) ) )
259
+ expect ( getVal ( tpl . stdev ( ) , [ 'trials' ] ) )
250
260
. toBe ( 6.976149845485451 )
251
261
)
252
262
) ;
253
263
254
264
describe ( ".sumOverSum" , ( ) =>
255
265
it ( "works" , ( ) =>
256
- expect ( getVal ( tpl . sumOverSum ( ) ( [ 'successes' , 'trials' ] ) ) )
266
+ expect ( getVal ( tpl . sumOverSum ( ) , [ 'successes' , 'trials' ] ) )
257
267
. toBe ( ( 12 + 25 + 30 + 14 ) / ( 95 + 102 + 103 + 112 ) )
258
268
)
259
269
) ;
260
270
261
271
describe ( ".fractionOf" , ( ) =>
262
272
it ( "works" , ( ) =>
263
- expect ( getVal ( tpl . fractionOf ( tpl . sum ( ) ) ( [ 'trials' ] ) ) )
273
+ expect ( getVal ( tpl . fractionOf ( tpl . sum ( ) ) , [ 'trials' ] ) )
264
274
. toBe ( 1 )
265
275
)
266
276
) ;
0 commit comments