Skip to content

Commit a7e5ce4

Browse files
committed
docs: add test files
--- 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent d656176 commit a7e5ce4

File tree

2 files changed

+277
-0
lines changed

2 files changed

+277
-0
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var dasumpw = require( './../lib' );
26+
27+
28+
// TESTS //
29+
30+
tape( 'main export is an object', function test( t ) {
31+
t.ok( true, __filename );
32+
t.strictEqual( typeof dasumpw, 'object', 'main export is an object' );
33+
t.end();
34+
});
35+
36+
tape( 'the function has an arity of 4', function test( t ) {
37+
t.strictEqual( dasumpw.ndarray.length, 4, 'returns expected value' );
38+
t.end();
39+
});
40+
41+
tape( 'the function calculates the sum of absolute values', function test( t ) {
42+
var x;
43+
var v;
44+
var i;
45+
46+
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, NaN, 0.0, NaN, 3.0 ] );
47+
v = dasumpw.ndarray( x.length, x, 1, 0 );
48+
t.strictEqual( v, 3.0, 'returns expected value' );
49+
50+
x = new Float64Array( [ 1.0, -2.0, NaN, 5.0, 0.0, 3.0 ] );
51+
v = dasumpw.ndarray( x.length, x, 1, 0 );
52+
t.strictEqual( v, 7.0, 'returns expected value' );
53+
54+
x = new Float64Array( [ 4.0, NaN ] );
55+
v = dasumpw.ndarray( x.length, x, 1, 0 );
56+
t.strictEqual( v, 4.0, 'returns expected value' );
57+
58+
x = new Float64Array( [ 1.0, 1.0e100, NaN, -1.0e100 ] );
59+
v = dasumpw.ndarray( x.length, x, 1, 0 );
60+
t.strictEqual( v, 1.0, 'returns expected value' );
61+
62+
x = new Float64Array( 1e3 );
63+
for ( i = 0; i < 1e3; i++ ) {
64+
x[ i ] = i + 1;
65+
}
66+
v = dasumpw.ndarray( x.length, x, 1, 0 );
67+
t.strictEqual( v, 500500.0, 'returns expected value' );
68+
69+
t.end();
70+
});
71+
72+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test( t ) {
73+
var x;
74+
var v;
75+
76+
x = new Float64Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] );
77+
78+
v = dasumpw.ndarray( 0, x, 1, 0 );
79+
t.strictEqual( v, 0.0, 'returns expected value' );
80+
81+
v = dasumpw.ndarray( -1, x, 1, 0 );
82+
t.strictEqual( v, 0.0, 'returns expected value' );
83+
84+
t.end();
85+
});
86+
87+
tape( 'if provided an `N` parameter equal to `1`, the function returns the first element', function test( t ) {
88+
var x;
89+
var v;
90+
91+
x = new Float64Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] );
92+
93+
v = dasumpw.ndarray( 1, x, 1, 0 );
94+
t.strictEqual( v, 1.0, 'returns expected value' );
95+
96+
t.end();
97+
});
98+
99+
tape( 'the function supports a `stride` parameter', function test( t ) {
100+
var x;
101+
var v;
102+
103+
x = new Float64Array([
104+
1.0, // 0
105+
2.0,
106+
2.0, // 1
107+
-7.0,
108+
NaN, // 2
109+
3.0,
110+
4.0, // 3
111+
2.0
112+
]);
113+
114+
v = dasumpw.ndarray( 4, x, 2, 0 );
115+
116+
t.strictEqual( v, 7.0, 'returns expected value' );
117+
t.end();
118+
});
119+
120+
tape( 'the function supports a negative `stride` parameter', function test( t ) {
121+
var x;
122+
var v;
123+
var i;
124+
125+
x = new Float64Array([
126+
1.0, // 3
127+
2.0,
128+
2.0, // 2
129+
-7.0,
130+
NaN, // 1
131+
3.0,
132+
4.0, // 0
133+
2.0
134+
]);
135+
136+
v = dasumpw.ndarray( 4, x, -2, 6 );
137+
138+
t.strictEqual( v, 7.0, 'returns expected value' );
139+
140+
x = new Float64Array( 1e3 );
141+
for ( i = 0; i < 1e3; i++ ) {
142+
x[ i ] = i + 1;
143+
}
144+
v = dasumpw.ndarray( x.length, x, -1, 1e3-1 );
145+
t.strictEqual( v, 500500.0, 'returns expected value' );
146+
147+
t.end();
148+
});
149+
150+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) {
151+
var x;
152+
var v;
153+
154+
x = new Float64Array( [ 1.0, -2.0, NaN, 5.0, 3.0 ] );
155+
156+
v = dasumpw.ndarray( x.length, x, 0, 0 );
157+
t.strictEqual( v, 5.0, 'returns expected value' );
158+
159+
t.end();
160+
});
161+
162+
tape( 'the function supports view offsets', function test( t ) {
163+
var x0;
164+
var x1;
165+
var v;
166+
167+
x0 = new Float64Array([
168+
2.0,
169+
1.0, // 0
170+
2.0,
171+
-2.0, // 1
172+
NaN,
173+
2.0, // 2
174+
3.0,
175+
4.0, // 3
176+
6.0
177+
]);
178+
179+
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
180+
181+
v = dasumpw.ndarray( 4, x1, 2, 0 );
182+
t.strictEqual( v, 5.0, 'returns expected value' );
183+
184+
t.end();
185+
});
186+
187+
tape( 'the `ndarray` method supports an `offset` parameter', function test( t ) {
188+
var x;
189+
var v;
190+
191+
x = new Float64Array([
192+
2.0,
193+
1.0, // 0
194+
2.0,
195+
-2.0, // 1
196+
NaN,
197+
2.0, // 2
198+
3.0,
199+
4.0 // 3
200+
]);
201+
202+
v = dasumpw.ndarray( 4, x, 2, 1 );
203+
t.strictEqual( v, 5.0, 'returns expected value' );
204+
205+
t.end();
206+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' );
25+
var Module = require( './../lib/module.js' );
26+
var Routine = require( './../lib/routine.js' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof Routine, 'function', 'returns expected value' );
34+
t.end();
35+
});
36+
37+
tape( 'the function is a constructor', function test( t ) {
38+
var mod = new Routine();
39+
t.strictEqual( mod instanceof Routine, true, 'returns expected value' );
40+
t.end();
41+
});
42+
43+
tape( 'the function is a constructor which does not require `new`', function test( t ) {
44+
var mod = Routine(); // eslint-disable-line new-cap
45+
t.strictEqual( mod instanceof Routine, true, 'returns expected value' );
46+
t.end();
47+
});
48+
49+
tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) {
50+
var mod = new Routine();
51+
t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' );
52+
t.end();
53+
});
54+
55+
tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) {
56+
var mod = new Routine();
57+
t.strictEqual( mod instanceof Module, true, 'returns expected value' );
58+
t.end();
59+
});
60+
61+
tape( 'attached to a module instance is a `main` method', function test( t ) {
62+
var mod = new Routine();
63+
t.strictEqual( typeof mod.main, 'function', 'returns expected value' );
64+
t.end();
65+
});
66+
67+
tape( 'attached to a module instance is an `ndarray` method', function test( t ) {
68+
var mod = new Routine();
69+
t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' );
70+
t.end();
71+
});

0 commit comments

Comments
 (0)