Skip to content

Commit d502385

Browse files
committed
test: add accessor array testcases
--- 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 40768ac commit d502385

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var Float64Array = require( '@stdlib/array/float64' );
26+
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
2627
var mean = require( './../lib/main.js' );
2728

2829

@@ -56,6 +57,23 @@ tape( 'the function calculates the arithmetic mean of a strided array', function
5657
t.end();
5758
});
5859

60+
tape( 'the function calculates the arithmetic mean of a strided array (accessors)', function test( t ) {
61+
var x;
62+
var v;
63+
64+
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
65+
66+
v = mean( x.length, toAccessorArray( x ), 1 );
67+
t.strictEqual( v, 0.5, 'returns expected value' );
68+
69+
x = [ -4.0 ];
70+
71+
v = mean( x.length, toAccessorArray( x ), 1 );
72+
t.strictEqual( v, -4.0, 'returns expected value' );
73+
74+
t.end();
75+
});
76+
5977
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) {
6078
var x;
6179
var v;
@@ -71,6 +89,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
7189
t.end();
7290
});
7391

92+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
93+
var x;
94+
var v;
95+
96+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
97+
98+
v = mean( 0, toAccessorArray( x ), 1 );
99+
t.strictEqual( isnan( v ), true, 'returns expected value' );
100+
101+
v = mean( -1, toAccessorArray( x ), 1 );
102+
t.strictEqual( isnan( v ), true, 'returns expected value' );
103+
104+
t.end();
105+
});
106+
74107
tape( 'if provided an `N` parameter equal to `1`, the function returns the first element', function test( t ) {
75108
var x;
76109
var v;
@@ -83,6 +116,18 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first
83116
t.end();
84117
});
85118

119+
tape( 'if provided an `N` parameter equal to `1`, the function returns the first element (accessors)', function test( t ) {
120+
var x;
121+
var v;
122+
123+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
124+
125+
v = mean( 1, toAccessorArray( x ), 1 );
126+
t.strictEqual( v, 1.0, 'returns expected value' );
127+
128+
t.end();
129+
});
130+
86131
tape( 'the function supports a `stride` parameter', function test( t ) {
87132
var x;
88133
var v;
@@ -104,6 +149,26 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
104149
t.end();
105150
});
106151

152+
tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
153+
var x;
154+
var v;
155+
156+
x = [
157+
1.0, // 0
158+
2.0,
159+
2.0, // 1
160+
-7.0,
161+
-2.0, // 2
162+
3.0,
163+
4.0, // 3
164+
2.0
165+
];
166+
v = mean( 4, toAccessorArray( x ), 2 );
167+
168+
t.strictEqual( v, 1.25, 'returns expected value' );
169+
t.end();
170+
});
171+
107172
tape( 'the function supports a negative `stride` parameter', function test( t ) {
108173
var x;
109174
var v;
@@ -125,6 +190,27 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
125190
t.end();
126191
});
127192

193+
tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
194+
var x;
195+
var v;
196+
197+
x = [
198+
1.0, // 3
199+
2.0,
200+
2.0, // 2
201+
-7.0,
202+
-2.0, // 1
203+
3.0,
204+
4.0, // 0
205+
2.0
206+
];
207+
208+
v = mean( 4, toAccessorArray( x ), -2 );
209+
210+
t.strictEqual( v, 1.25, 'returns expected value' );
211+
t.end();
212+
});
213+
128214
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) {
129215
var x;
130216
var v;
@@ -137,6 +223,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f
137223
t.end();
138224
});
139225

226+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element (accessors)', function test( t ) {
227+
var x;
228+
var v;
229+
230+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
231+
232+
v = mean( x.length, toAccessorArray( x ), 0 );
233+
t.strictEqual( v, 1.0, 'returns expected value' );
234+
235+
t.end();
236+
});
237+
140238
tape( 'the function supports view offsets', function test( t ) {
141239
var x0;
142240
var x1;
@@ -161,3 +259,28 @@ tape( 'the function supports view offsets', function test( t ) {
161259

162260
t.end();
163261
});
262+
263+
tape( 'the function supports view offsets (accessors)', function test( t ) {
264+
var x0;
265+
var x1;
266+
var v;
267+
268+
x0 = new Float64Array([
269+
2.0,
270+
1.0, // 0
271+
2.0,
272+
-2.0, // 1
273+
-2.0,
274+
2.0, // 2
275+
3.0,
276+
4.0, // 3
277+
6.0
278+
]);
279+
280+
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
281+
282+
v = mean( 4, toAccessorArray( x1 ), 2 );
283+
t.strictEqual( v, 1.25, 'returns expected value' );
284+
285+
t.end();
286+
});

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

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
2526
var mean = require( './../lib/ndarray.js' );
2627

2728

@@ -55,6 +56,23 @@ tape( 'the function calculates the arithmetic mean of a strided array', function
5556
t.end();
5657
});
5758

59+
tape( 'the function calculates the arithmetic mean of a strided array (accessors)', function test( t ) {
60+
var x;
61+
var v;
62+
63+
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
64+
65+
v = mean( x.length, toAccessorArray( x ), 1, 0 );
66+
t.strictEqual( v, 0.5, 'returns expected value' );
67+
68+
x = [ -4.0 ];
69+
70+
v = mean( x.length, toAccessorArray( x ), 1, 0 );
71+
t.strictEqual( v, -4.0, 'returns expected value' );
72+
73+
t.end();
74+
});
75+
5876
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) {
5977
var x;
6078
var v;
@@ -70,6 +88,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
7088
t.end();
7189
});
7290

91+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
92+
var x;
93+
var v;
94+
95+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
96+
97+
v = mean( 0, toAccessorArray( x ), 1, 0 );
98+
t.strictEqual( isnan( v ), true, 'returns expected value' );
99+
100+
v = mean( -1, toAccessorArray( x ), 1, 0 );
101+
t.strictEqual( isnan( v ), true, 'returns expected value' );
102+
103+
t.end();
104+
});
105+
73106
tape( 'if provided an `N` parameter equal to `1`, the function returns the first indexed element', function test( t ) {
74107
var x;
75108
var v;
@@ -82,6 +115,18 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first
82115
t.end();
83116
});
84117

118+
tape( 'if provided an `N` parameter equal to `1`, the function returns the first indexed element (accessors)', function test( t ) {
119+
var x;
120+
var v;
121+
122+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
123+
124+
v = mean( 1, toAccessorArray( x ), 1, 0 );
125+
t.strictEqual( v, 1.0, 'returns expected value' );
126+
127+
t.end();
128+
});
129+
85130
tape( 'the function supports a `stride` parameter', function test( t ) {
86131
var x;
87132
var v;
@@ -103,6 +148,27 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
103148
t.end();
104149
});
105150

151+
tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
152+
var x;
153+
var v;
154+
155+
x = [
156+
1.0, // 0
157+
2.0,
158+
2.0, // 1
159+
-7.0,
160+
-2.0, // 2
161+
3.0,
162+
4.0, // 3
163+
2.0
164+
];
165+
166+
v = mean( 4, toAccessorArray( x ), 2, 0 );
167+
168+
t.strictEqual( v, 1.25, 'returns expected value' );
169+
t.end();
170+
});
171+
106172
tape( 'the function supports a negative `stride` parameter', function test( t ) {
107173
var x;
108174
var v;
@@ -124,6 +190,27 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
124190
t.end();
125191
});
126192

193+
tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
194+
var x;
195+
var v;
196+
197+
x = [
198+
1.0, // 3
199+
2.0,
200+
2.0, // 2
201+
-7.0,
202+
-2.0, // 1
203+
3.0,
204+
4.0, // 0
205+
2.0
206+
];
207+
208+
v = mean( 4, toAccessorArray( x ), -2, 6 );
209+
210+
t.strictEqual( v, 1.25, 'returns expected value' );
211+
t.end();
212+
});
213+
127214
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) {
128215
var x;
129216
var v;
@@ -136,6 +223,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f
136223
t.end();
137224
});
138225

226+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element (accessors)', function test( t ) {
227+
var x;
228+
var v;
229+
230+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
231+
232+
v = mean( x.length, toAccessorArray( x ), 0, 0 );
233+
t.strictEqual( v, 1.0, 'returns expected value' );
234+
235+
t.end();
236+
});
237+
139238
tape( 'the function supports an `offset` parameter', function test( t ) {
140239
var x;
141240
var v;
@@ -156,3 +255,24 @@ tape( 'the function supports an `offset` parameter', function test( t ) {
156255

157256
t.end();
158257
});
258+
259+
tape( 'the function supports an `offset` parameter (accessors)', function test( t ) {
260+
var x;
261+
var v;
262+
263+
x = [
264+
2.0,
265+
1.0, // 0
266+
2.0,
267+
-2.0, // 1
268+
-2.0,
269+
2.0, // 2
270+
3.0,
271+
4.0 // 3
272+
];
273+
274+
v = mean( 4, toAccessorArray( x ), 2, 1 );
275+
t.strictEqual( v, 1.25, 'returns expected value' );
276+
277+
t.end();
278+
});

0 commit comments

Comments
 (0)