@@ -54,41 +54,39 @@ tape( 'the accumulator function incrementally computes a range while ignoring Na
5454 var d ;
5555 var i ;
5656
57- data = [ 2.0 , 3.0 , NaN , 2 .0, 4 .0, NaN , 3.0 , 4.0 ] ;
57+ data = [ 2.0 , NaN , 3.0 , NaN , 4 .0, 43 .0, NaN , 4.0 ] ;
5858 N = data . length ;
5959
60- expected = new Array ( N ) ;
61- actual = new Array ( N ) ;
60+ expected = [ ] ;
61+ actual = [ ] ;
6262
6363 acc = incrnanrange ( ) ;
6464
6565 max = null ;
6666 min = null ;
6767 for ( i = 0 ; i < N ; i ++ ) {
6868 d = data [ i ] ;
69- if ( isnan ( d ) === false ) {
69+ if ( ! isnan ( d ) ) {
7070 if ( max === null || d > max ) {
7171 max = d ;
7272 }
7373 if ( min === null || d < min ) {
7474 min = d ;
7575 }
76- expected [ i ] = max - min ;
77- } else {
78- expected [ i ] = expected [ i - 1 ] ;
7976 }
80- actual [ i ] = acc ( d ) ;
77+ expected . push ( max !== null && min !== null ? max - min : null ) ;
78+ actual . push ( acc ( d ) ) ;
8179 }
8280 t . deepEqual ( actual , expected , 'returns expected incremental results' ) ;
8381 t . end ( ) ;
8482} ) ;
8583
86- tape ( 'if not provided an input value, the accumulator function returns the current range' , function test ( t ) {
84+ tape ( 'if not provided an input value, the accumulator function returns the current range while ignoring the NaN value ' , function test ( t ) {
8785 var data ;
8886 var acc ;
8987 var i ;
9088
91- data = [ - 2.0 , NaN , 3.0 , 1.0 , NaN ] ;
89+ data = [ NaN , - 2.0 , NaN , 3.0 , 1.0 ] ;
9290 acc = incrnanrange ( ) ;
9391 for ( i = 0 ; i < data . length ; i ++ ) {
9492 acc ( data [ i ] ) ;
@@ -107,6 +105,20 @@ tape( 'if provided a `NaN`, the accumulator function returns `NaN` for all futur
107105 for ( i = 0 ; i < data . length ; i ++ ) {
108106 acc ( data [ i ] ) ;
109107 }
110- t . equal ( isnan ( acc ( ) ) , true , 'returns expected value' ) ;
108+ t . equal ( isnan ( acc ( ) ) , false , 'returns expected value' ) ;
109+ t . end ( ) ;
110+ } ) ;
111+
112+ tape ( 'if all provided values are `NaN`, the accumulator function returns `null`' , function test ( t ) {
113+ var data ;
114+ var acc ;
115+ var i ;
116+
117+ data = [ NaN , NaN , NaN ] ;
118+ acc = incrnanrange ( ) ;
119+ for ( i = 0 ; i < data . length ; i ++ ) {
120+ acc ( data [ i ] ) ;
121+ }
122+ t . equal ( acc ( ) , null , 'returns null' ) ;
111123 t . end ( ) ;
112124} ) ;
0 commit comments