@@ -94,115 +94,115 @@ tape( 'the function calculates the population variance of a strided array (ignor
9494 t . end ( ) ;
9595} ) ;
9696
97- tape ( 'the function calculates the sample variance of a strided array (ignoring `NaN` values)' , function test ( t ) {
97+ tape ( 'the function calculates the population variance of a strided array (ignoring `NaN` values) (accessors )' , function test ( t ) {
9898 var x ;
9999 var v ;
100100 var i ;
101101
102102 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , NaN , 0.0 , 3.0 ] ;
103103
104- v = nanvariancech ( x . length , 1 , x , 1 ) ;
105- t . strictEqual ( v , 53.5 / ( x . length - 2 ) , 'returns expected value' ) ;
104+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
105+ t . strictEqual ( v , 53.5 / ( x . length - 1 ) , 'returns expected value' ) ;
106106
107107 x = [ 1.0 , NaN , NaN , - 2.0 , NaN , - 4.0 , NaN , 5.0 , NaN , 0.0 , 3.0 , NaN ] ;
108108
109- v = nanvariancech ( x . length , 1 , x , 1 ) ;
110- t . strictEqual ( v , 53.5 / ( x . length - 7 ) , 'returns expected value' ) ;
109+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
110+ t . strictEqual ( v , 53.5 / ( x . length - 6 ) , 'returns expected value' ) ;
111111
112112 x = [ - 4.0 , NaN ] ;
113113
114- v = nanvariancech ( x . length , 1 , x , 1 ) ;
115- t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
114+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
115+ t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
116116
117117 x = [ NaN , NaN ] ;
118118
119- v = nanvariancech ( x . length , 1 , x , 1 ) ;
119+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
120120 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
121121
122122 x = [ NaN ] ;
123- v = nanvariancech ( x . length , 1 , x , 1 ) ;
123+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
124124 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
125125
126126 x = [ 4.0 ] ;
127- v = nanvariancech ( x . length , 1 , x , 1 ) ;
128- t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
127+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
128+ t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
129129
130130 x = [ ] ;
131131 for ( i = 0 ; i < 1e3 ; i ++ ) {
132132 x . push ( 100.0 ) ;
133133 }
134- v = nanvariancech ( x . length , 1 , x , 1 ) ;
134+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
135135 t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
136136
137137 x = [ NaN , NaN , NaN , NaN , NaN , NaN , NaN , NaN , NaN , NaN ] ;
138- v = nanvariancech ( x . length , 1 , x , 1 ) ;
138+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
139139 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
140140
141141 x = [ ] ;
142142 for ( i = 0 ; i < 1e3 ; i ++ ) {
143143 x . push ( NaN ) ;
144144 }
145- v = nanvariancech ( x . length , 1 , x , 1 ) ;
145+ v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
146146 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
147147
148148 t . end ( ) ;
149149} ) ;
150150
151- tape ( 'the function calculates the population variance of a strided array (accessors) (ignoring `NaN` values)' , function test ( t ) {
151+ tape ( 'the function calculates the sample variance of a strided array (ignoring `NaN` values)' , function test ( t ) {
152152 var x ;
153153 var v ;
154154 var i ;
155155
156156 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , NaN , 0.0 , 3.0 ] ;
157157
158- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
159- t . strictEqual ( v , 53.5 / ( x . length - 1 ) , 'returns expected value' ) ;
158+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
159+ t . strictEqual ( v , 53.5 / ( x . length - 2 ) , 'returns expected value' ) ;
160160
161161 x = [ 1.0 , NaN , NaN , - 2.0 , NaN , - 4.0 , NaN , 5.0 , NaN , 0.0 , 3.0 , NaN ] ;
162162
163- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
164- t . strictEqual ( v , 53.5 / ( x . length - 6 ) , 'returns expected value' ) ;
163+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
164+ t . strictEqual ( v , 53.5 / ( x . length - 7 ) , 'returns expected value' ) ;
165165
166166 x = [ - 4.0 , NaN ] ;
167167
168- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
169- t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
168+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
169+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
170170
171171 x = [ NaN , NaN ] ;
172172
173- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
173+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
174174 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
175175
176176 x = [ NaN ] ;
177- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
177+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
178178 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
179179
180180 x = [ 4.0 ] ;
181- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
182- t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
181+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
182+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
183183
184184 x = [ ] ;
185185 for ( i = 0 ; i < 1e3 ; i ++ ) {
186186 x . push ( 100.0 ) ;
187187 }
188- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
188+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
189189 t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
190190
191191 x = [ NaN , NaN , NaN , NaN , NaN , NaN , NaN , NaN , NaN , NaN ] ;
192- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
192+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
193193 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
194194
195195 x = [ ] ;
196196 for ( i = 0 ; i < 1e3 ; i ++ ) {
197197 x . push ( NaN ) ;
198198 }
199- v = nanvariancech ( x . length , 0 , toAccessorArray ( x ) , 1 ) ;
199+ v = nanvariancech ( x . length , 1 , x , 1 ) ;
200200 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
201201
202202 t . end ( ) ;
203203} ) ;
204204
205- tape ( 'the function calculates the sample variance of a strided array (accessors) ( ignoring `NaN` values)' , function test ( t ) {
205+ tape ( 'the function calculates the sample variance of a strided array (ignoring `NaN` values) (accessors )' , function test ( t ) {
206206 var x ;
207207 var v ;
208208 var i ;
@@ -271,7 +271,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
271271 t . end ( ) ;
272272} ) ;
273273
274- tape ( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`' , function test ( t ) {
274+ tape ( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors) ' , function test ( t ) {
275275 var x ;
276276 var v ;
277277
@@ -303,6 +303,23 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat
303303 t . end ( ) ;
304304} ) ;
305305
306+ tape ( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` provided the first element is not `NaN` (accessors)' , function test ( t ) {
307+ var x ;
308+ var v ;
309+
310+ x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
311+
312+ v = nanvariancech ( 1 , 0 , toAccessorArray ( x ) , 1 ) ;
313+ t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
314+
315+ x = [ NaN , 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
316+
317+ v = nanvariancech ( 1 , 0 , toAccessorArray ( x ) , 1 ) ;
318+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
319+
320+ t . end ( ) ;
321+ } ) ;
322+
306323tape ( 'if provided an `N` parameter equal to `1`, the function returns a sample variance equal to `NaN`' , function test ( t ) {
307324 var x ;
308325 var v ;
@@ -320,6 +337,23 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a sample
320337 t . end ( ) ;
321338} ) ;
322339
340+ tape ( 'if provided an `N` parameter equal to `1`, the function returns a sample variance equal to `NaN` (accessors)' , function test ( t ) {
341+ var x ;
342+ var v ;
343+
344+ x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
345+
346+ v = nanvariancech ( 1 , 1 , toAccessorArray ( x ) , 1 ) ;
347+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
348+
349+ x = [ NaN , 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
350+
351+ v = nanvariancech ( 1 , 1 , toAccessorArray ( x ) , 1 ) ;
352+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
353+
354+ t . end ( ) ;
355+ } ) ;
356+
323357tape ( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the function returns `NaN`' , function test ( t ) {
324358 var x ;
325359 var v ;
@@ -335,6 +369,21 @@ tape( 'if provided a `correction` parameter yielding a correction term less than
335369 t . end ( ) ;
336370} ) ;
337371
372+ tape ( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the function returns `NaN` (accessors)' , function test ( t ) {
373+ var x ;
374+ var v ;
375+
376+ x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
377+
378+ v = nanvariancech ( x . length , x . length , toAccessorArray ( x ) , 1 ) ;
379+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
380+
381+ v = nanvariancech ( x . length , x . length + 1 , toAccessorArray ( x ) , 1 ) ;
382+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
383+
384+ t . end ( ) ;
385+ } ) ;
386+
338387tape ( 'the function supports a `stride` parameter' , function test ( t ) {
339388 var x ;
340389 var v ;
@@ -465,6 +514,28 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p
465514 t . end ( ) ;
466515} ) ;
467516
517+ tape ( 'if provided a `stride` parameter equal to `0`, the function returns `0` provided the correction term is not less than `0` and the first element is not `NaN` (accessors)' , function test ( t ) {
518+ var x ;
519+ var v ;
520+
521+ x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
522+
523+ v = nanvariancech ( x . length , 1 , toAccessorArray ( x ) , 0 ) ;
524+ t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
525+
526+ x = [ NaN , 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
527+
528+ v = nanvariancech ( x . length , 1 , toAccessorArray ( x ) , 0 ) ;
529+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
530+
531+ x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
532+
533+ v = nanvariancech ( x . length , x . length , toAccessorArray ( x ) , 0 ) ;
534+ t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
535+
536+ t . end ( ) ;
537+ } ) ;
538+
468539tape ( 'the function supports view offsets' , function test ( t ) {
469540 var x0 ;
470541 var x1 ;
@@ -491,3 +562,30 @@ tape( 'the function supports view offsets', function test( t ) {
491562
492563 t . end ( ) ;
493564} ) ;
565+
566+ tape ( 'the function supports view offsets (accessors)' , function test ( t ) {
567+ var x0 ;
568+ var x1 ;
569+ var v ;
570+
571+ x0 = new Float64Array ( [
572+ 2.0 ,
573+ 1.0 , // 0
574+ 2.0 ,
575+ - 2.0 , // 1
576+ - 2.0 ,
577+ 2.0 , // 2
578+ 3.0 ,
579+ 4.0 , // 3
580+ 6.0 ,
581+ NaN , // 4
582+ NaN
583+ ] ) ;
584+
585+ x1 = new Float64Array ( x0 . buffer , x0 . BYTES_PER_ELEMENT * 1 ) ; // start at 2nd element
586+
587+ v = nanvariancech ( 5 , 1 , toAccessorArray ( x1 ) , 2 ) ;
588+ t . strictEqual ( v , 6.25 , 'returns expected value' ) ;
589+
590+ t . end ( ) ;
591+ } ) ;
0 commit comments