2121// MODULES //
2222
2323var tape = require ( 'tape' ) ;
24- var floor = require ( '@stdlib/math /base/special/floor ' ) ;
24+ var toAccessorArray = require ( '@stdlib/array /base/to-accessor-array ' ) ;
2525var sqrt = require ( '@stdlib/math/base/special/sqrt' ) ;
2626var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
2727var stdevpn = require ( './../lib/ndarray.js' ) ;
@@ -45,15 +45,15 @@ tape( 'the function calculates the population standard deviation of a strided ar
4545 var v ;
4646
4747 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 0.0 , 3.0 ] ;
48- v = stdevpn ( x . length , 0 , x , 1 , 0 ) ;
48+ v = stdevpn ( x . length , 0 , toAccessorArray ( x ) , 1 , 0 ) ;
4949 t . strictEqual ( v , sqrt ( 53.5 / x . length ) , 'returns expected value' ) ;
5050
5151 x = [ - 4.0 , - 4.0 ] ;
52- v = stdevpn ( x . length , 0 , x , 1 , 0 ) ;
52+ v = stdevpn ( x . length , 0 , toAccessorArray ( x ) , 1 , 0 ) ;
5353 t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
5454
5555 x = [ NaN , 4.0 ] ;
56- v = stdevpn ( x . length , 0 , x , 1 , 0 ) ;
56+ v = stdevpn ( x . length , 0 , toAccessorArray ( x ) , 1 , 0 ) ;
5757 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
5858
5959 t . end ( ) ;
@@ -64,15 +64,15 @@ tape( 'the function calculates the sample standard deviation of a strided array'
6464 var v ;
6565
6666 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 0.0 , 3.0 ] ;
67- v = stdevpn ( x . length , 1 , x , 1 , 0 ) ;
67+ v = stdevpn ( x . length , 1 , toAccessorArray ( x ) , 1 , 0 ) ;
6868 t . strictEqual ( v , sqrt ( 53.5 / ( x . length - 1 ) ) , 'returns expected value' ) ;
6969
7070 x = [ - 4.0 , - 4.0 ] ;
71- v = stdevpn ( x . length , 1 , x , 1 , 0 ) ;
71+ v = stdevpn ( x . length , 1 , toAccessorArray ( x ) , 1 , 0 ) ;
7272 t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
7373
7474 x = [ NaN , 4.0 ] ;
75- v = stdevpn ( x . length , 1 , x , 1 , 0 ) ;
75+ v = stdevpn ( x . length , 1 , toAccessorArray ( x ) , 1 , 0 ) ;
7676 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
7777
7878 t . end ( ) ;
@@ -84,10 +84,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
8484
8585 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
8686
87- v = stdevpn ( 0 , 1 , x , 1 , 0 ) ;
87+ v = stdevpn ( 0 , 1 , toAccessorArray ( x ) , 1 , 0 ) ;
8888 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
8989
90- v = stdevpn ( - 1 , 1 , x , 1 , 0 ) ;
90+ v = stdevpn ( - 1 , 1 , toAccessorArray ( x ) , 1 , 0 ) ;
9191 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
9292
9393 t . end ( ) ;
@@ -99,7 +99,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat
9999
100100 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
101101
102- v = stdevpn ( 1 , 0 , x , 1 , 0 ) ;
102+ v = stdevpn ( 1 , 0 , toAccessorArray ( x ) , 1 , 0 ) ;
103103 t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
104104
105105 t . end ( ) ;
@@ -111,17 +111,16 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or
111111
112112 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
113113
114- v = stdevpn ( x . length , x . length , x , 1 , 0 ) ;
114+ v = stdevpn ( x . length , x . length , toAccessorArray ( x ) , 1 , 0 ) ;
115115 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
116116
117- v = stdevpn ( x . length , x . length + 1 , x , 1 , 0 ) ;
117+ v = stdevpn ( x . length , x . length + 1 , toAccessorArray ( x ) , 1 , 0 ) ;
118118 t . strictEqual ( isnan ( v ) , true , 'returns expected value' ) ;
119119
120120 t . end ( ) ;
121121} ) ;
122122
123123tape ( 'the function supports a `stride` parameter' , function test ( t ) {
124- var N ;
125124 var x ;
126125 var v ;
127126
@@ -136,15 +135,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
136135 2.0
137136 ] ;
138137
139- N = floor ( x . length / 2 ) ;
140- v = stdevpn ( N , 1 , x , 2 , 0 ) ;
138+ v = stdevpn ( 4 , 1 , toAccessorArray ( x ) , 2 , 0 ) ;
141139
142140 t . strictEqual ( v , 2.5 , 'returns expected value' ) ;
143141 t . end ( ) ;
144142} ) ;
145143
146144tape ( 'the function supports a negative `stride` parameter' , function test ( t ) {
147- var N ;
148145 var x ;
149146 var v ;
150147
@@ -159,8 +156,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
159156 2.0
160157 ] ;
161158
162- N = floor ( x . length / 2 ) ;
163- v = stdevpn ( N , 1 , x , - 2 , 6 ) ;
159+ v = stdevpn ( 4 , 1 , toAccessorArray ( x ) , - 2 , 6 ) ;
164160
165161 t . strictEqual ( v , 2.5 , 'returns expected value' ) ;
166162 t . end ( ) ;
@@ -172,14 +168,13 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`',
172168
173169 x = [ 1.0 , - 2.0 , - 4.0 , 5.0 , 3.0 ] ;
174170
175- v = stdevpn ( x . length , 1 , x , 0 , 0 ) ;
171+ v = stdevpn ( x . length , 1 , toAccessorArray ( x ) , 0 , 0 ) ;
176172 t . strictEqual ( v , 0.0 , 'returns expected value' ) ;
177173
178174 t . end ( ) ;
179175} ) ;
180176
181177tape ( 'the function supports an `offset` parameter' , function test ( t ) {
182- var N ;
183178 var x ;
184179 var v ;
185180
@@ -193,9 +188,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) {
193188 3.0 ,
194189 4.0 // 3
195190 ] ;
196- N = floor ( x . length / 2 ) ;
197191
198- v = stdevpn ( N , 1 , x , 2 , 1 ) ;
192+ v = stdevpn ( 4 , 1 , toAccessorArray ( x ) , 2 , 1 ) ;
199193 t . strictEqual ( v , 2.5 , 'returns expected value' ) ;
200194
201195 t . end ( ) ;
0 commit comments