@@ -246,5 +246,76 @@ describe('Test histogram', function() {
246
246
] ) ;
247
247
} ) ;
248
248
249
+ describe ( 'cumulative distribution functions' , function ( ) {
250
+ var base = { x : [ 1 , 2 , 3 , 4 , 2 , 3 , 4 , 3 , 4 , 4 ] } ;
251
+
252
+ it ( 'makes the right base histogram' , function ( ) {
253
+ var baseOut = _calc ( base ) ;
254
+ expect ( baseOut ) . toEqual ( [
255
+ { b : 0 , p : 1 , s : 1 } ,
256
+ { b : 0 , p : 2 , s : 2 } ,
257
+ { b : 0 , p : 3 , s : 3 } ,
258
+ { b : 0 , p : 4 , s : 4 } ,
259
+ ] ) ;
260
+ } ) ;
261
+
262
+ var CDFs = [
263
+ { p : [ 1 , 2 , 3 , 4 ] , s : [ 1 , 3 , 6 , 10 ] } ,
264
+ {
265
+ direction : 'decreasing' ,
266
+ p : [ 1 , 2 , 3 , 4 ] , s : [ 10 , 9 , 7 , 4 ]
267
+ } ,
268
+ {
269
+ currentbin : 'exclude' ,
270
+ p : [ 2 , 3 , 4 , 5 ] , s : [ 1 , 3 , 6 , 10 ]
271
+ } ,
272
+ {
273
+ direction : 'decreasing' , currentbin : 'exclude' ,
274
+ p : [ 0 , 1 , 2 , 3 ] , s : [ 10 , 9 , 7 , 4 ]
275
+ } ,
276
+ {
277
+ currentbin : 'half' ,
278
+ p : [ 1 , 2 , 3 , 4 , 5 ] , s : [ 0.5 , 2 , 4.5 , 8 , 10 ]
279
+ } ,
280
+ {
281
+ direction : 'decreasing' , currentbin : 'half' ,
282
+ p : [ 0 , 1 , 2 , 3 , 4 ] , s : [ 10 , 9.5 , 8 , 5.5 , 2 ]
283
+ } ,
284
+ {
285
+ direction : 'decreasing' , currentbin : 'half' , histnorm : 'percent' ,
286
+ p : [ 0 , 1 , 2 , 3 , 4 ] , s : [ 100 , 95 , 80 , 55 , 20 ]
287
+ } ,
288
+ {
289
+ currentbin : 'exclude' , histnorm : 'probability' ,
290
+ p : [ 2 , 3 , 4 , 5 ] , s : [ 0.1 , 0.3 , 0.6 , 1 ]
291
+ }
292
+ ] ;
293
+
294
+ CDFs . forEach ( function ( CDF ) {
295
+ var direction = CDF . direction ,
296
+ currentbin = CDF . currentbin ,
297
+ histnorm = CDF . histnorm ,
298
+ p = CDF . p ,
299
+ s = CDF . s ;
300
+
301
+ it ( 'handles direction=' + direction + ', currentbin=' + currentbin + ', histnorm=' + histnorm , function ( ) {
302
+ var traceIn = Lib . extendFlat ( { } , base , {
303
+ cumulative : true ,
304
+ direction : direction ,
305
+ currentbin : currentbin ,
306
+ histnorm : histnorm
307
+ } ) ;
308
+ var out = _calc ( traceIn ) ;
309
+
310
+ expect ( out . length ) . toBe ( p . length ) ;
311
+ out . forEach ( function ( outi , i ) {
312
+ expect ( outi . p ) . toBe ( p [ i ] ) ;
313
+ expect ( outi . s ) . toBeCloseTo ( s [ i ] , 6 ) ;
314
+ expect ( outi . b ) . toBe ( 0 ) ;
315
+ } ) ;
316
+ } ) ;
317
+ } ) ;
318
+ } ) ;
319
+
249
320
} ) ;
250
321
} ) ;
0 commit comments