Skip to content

Commit 6b8e327

Browse files
committed
docs: update test files for clarity and consistency
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5357283 commit 6b8e327

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

lib/node_modules/@stdlib/stats/base/variancetk/test/test.main.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,44 @@ tape( 'the function calculates the population variance of a strided array', func
5959
t.end();
6060
});
6161

62+
tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) {
63+
var x;
64+
var v;
65+
66+
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
67+
v = variancetk( x.length, 0, toAccessorArray( x ), 1 );
68+
t.strictEqual( v, 53.5/x.length, 'returns expected value' );
69+
70+
x = [ -4.0, -4.0 ];
71+
v = variancetk( x.length, 0, toAccessorArray( x ), 1 );
72+
t.strictEqual( v, 0.0, 'returns expected value' );
73+
74+
x = [ NaN, 4.0 ];
75+
v = variancetk( x.length, 0, toAccessorArray( x ), 1 );
76+
t.strictEqual( isnan( v ), true, 'returns expected value' );
77+
78+
t.end();
79+
});
80+
81+
tape( 'the function calculates the sample variance of a strided array', function test( t ) {
82+
var x;
83+
var v;
84+
85+
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
86+
v = variancetk( x.length, 1, x, 1 );
87+
t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' );
88+
89+
x = [ -4.0, -4.0 ];
90+
v = variancetk( x.length, 1, x, 1 );
91+
t.strictEqual( v, 0.0, 'returns expected value' );
92+
93+
x = [ NaN, 4.0 ];
94+
v = variancetk( x.length, 1, x, 1 );
95+
t.strictEqual( isnan( v ), true, 'returns expected value' );
96+
97+
t.end();
98+
});
99+
62100
tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) {
63101
var x;
64102
var v;
@@ -93,6 +131,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
93131
t.end();
94132
});
95133

134+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
135+
var x;
136+
var v;
137+
138+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
139+
140+
v = variancetk( 0, 1, toAccessorArray( x ), 1 );
141+
t.strictEqual( isnan( v ), true, 'returns expected value' );
142+
143+
v = variancetk( -1, 1, toAccessorArray( x ), 1 );
144+
t.strictEqual( isnan( v ), true, 'returns expected value' );
145+
146+
t.end();
147+
});
148+
96149
tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) {
97150
var x;
98151
var v;
@@ -105,6 +158,18 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat
105158
t.end();
106159
});
107160

161+
tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) {
162+
var x;
163+
var v;
164+
165+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
166+
167+
v = variancetk( 1, 0, toAccessorArray( x ), 1 );
168+
t.strictEqual( v, 0.0, 'returns expected value' );
169+
170+
t.end();
171+
});
172+
108173
tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) {
109174
var x;
110175
var v;
@@ -120,6 +185,21 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or
120185
t.end();
121186
});
122187

188+
tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
189+
var x;
190+
var v;
191+
192+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
193+
194+
v = variancetk( x.length, x.length, toAccessorArray( x ), 1 );
195+
t.strictEqual( isnan( v ), true, 'returns expected value' );
196+
197+
v = variancetk( x.length, x.length+1, toAccessorArray( x ), 1 );
198+
t.strictEqual( isnan( v ), true, 'returns expected value' );
199+
200+
t.end();
201+
});
202+
123203
tape( 'the function supports a `stride` parameter', function test( t ) {
124204
var x;
125205
var v;
@@ -216,6 +296,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`',
216296
t.end();
217297
});
218298

299+
tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) {
300+
var x;
301+
var v;
302+
303+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
304+
305+
v = variancetk( x.length, 1, toAccessorArray( x ), 0 );
306+
t.strictEqual( v, 0.0, 'returns expected value' );
307+
308+
t.end();
309+
});
310+
219311
tape( 'the function supports view offsets', function test( t ) {
220312
var x0;
221313
var x1;
@@ -240,3 +332,28 @@ tape( 'the function supports view offsets', function test( t ) {
240332

241333
t.end();
242334
});
335+
336+
tape( 'the function supports view offsets (accessors)', function test( t ) {
337+
var x0;
338+
var x1;
339+
var v;
340+
341+
x0 = new Float64Array([
342+
2.0,
343+
1.0, // 0
344+
2.0,
345+
-2.0, // 1
346+
-2.0,
347+
2.0, // 2
348+
3.0,
349+
4.0, // 3
350+
6.0
351+
]);
352+
353+
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
354+
355+
v = variancetk( 4, 1, toAccessorArray( x1 ), 2 );
356+
t.strictEqual( v, 6.25, 'returns expected value' );
357+
358+
t.end();
359+
});

lib/node_modules/@stdlib/stats/base/variancetk/test/test.ndarray.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
130130
t.end();
131131
});
132132

133+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
134+
var x;
135+
var v;
136+
137+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
138+
139+
v = variancetk( 0, 1, toAccessorArray( x ), 1, 0 );
140+
t.strictEqual( isnan( v ), true, 'returns expected value' );
141+
142+
v = variancetk( -1, 1, toAccessorArray( x ), 1, 0 );
143+
t.strictEqual( isnan( v ), true, 'returns expected value' );
144+
145+
t.end();
146+
});
147+
133148
tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) {
134149
var x;
135150
var v;
@@ -142,6 +157,18 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat
142157
t.end();
143158
});
144159

160+
tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) {
161+
var x;
162+
var v;
163+
164+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
165+
166+
v = variancetk( 1, 0, toAccessorArray( x ), 1, 0 );
167+
t.strictEqual( v, 0.0, 'returns expected value' );
168+
169+
t.end();
170+
});
171+
145172
tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) {
146173
var x;
147174
var v;
@@ -157,6 +184,21 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or
157184
t.end();
158185
});
159186

187+
tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
188+
var x;
189+
var v;
190+
191+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
192+
193+
v = variancetk( x.length, x.length, toAccessorArray( x ), 1, 0 );
194+
t.strictEqual( isnan( v ), true, 'returns expected value' );
195+
196+
v = variancetk( x.length, x.length+1, toAccessorArray( x ), 1, 0 );
197+
t.strictEqual( isnan( v ), true, 'returns expected value' );
198+
199+
t.end();
200+
});
201+
160202
tape( 'the function supports a `stride` parameter', function test( t ) {
161203
var x;
162204
var v;

0 commit comments

Comments
 (0)