Skip to content

Commit 48d41cc

Browse files
committed
test: add tests upto 3d
--- 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 528116b commit 48d41cc

File tree

5 files changed

+2682
-2
lines changed

5 files changed

+2682
-2
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' );
25+
var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
26+
var Complex128Array = require( '@stdlib/array/complex128' );
27+
var Float64Array = require( '@stdlib/array/float64' );
28+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
29+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
30+
var unary = require( './../lib' );
31+
32+
33+
// TESTS //
34+
35+
tape( 'main export is a function', function test( t ) {
36+
t.ok( true, __filename );
37+
t.strictEqual( typeof unary, 'function', 'main export is a function');
38+
t.end();
39+
});
40+
41+
tape( 'the function applies a unary callback to each indexed element of a 0-dimensional ndarray', function test( t ) {
42+
var expected;
43+
var x;
44+
var y;
45+
46+
x = scalar2ndarray( 5.0, {
47+
'dtype': 'float64'
48+
});
49+
50+
y = scalar2ndarray( 0.0, {
51+
'dtype': 'float64'
52+
});
53+
54+
unary( [ x, y ], scale );
55+
56+
expected = new Float64Array( [ 50.0 ] );
57+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
58+
59+
t.end();
60+
61+
function scale( x ) {
62+
return x * 10.0;
63+
}
64+
});
65+
66+
tape( 'the function applies a unary callback to each indexed element of a 0-dimensional ndarray (accessors)', function test( t ) {
67+
var expected;
68+
var x;
69+
var y;
70+
71+
x = scalar2ndarray( new Complex128( 5.0, 5.0 ), {
72+
'dtype': 'complex128'
73+
});
74+
75+
y = scalar2ndarray( new Complex128( 0.0, 0.0 ), {
76+
'dtype': 'complex128'
77+
});
78+
79+
unary( [ x, y ], scale );
80+
81+
expected = new Complex128Array( [ 50.0, 50.0 ] );
82+
t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' );
83+
84+
t.end();
85+
86+
function scale( z ) {
87+
return new Complex128( z.re*10.0, z.im*10.0 );
88+
}
89+
});
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' );
25+
var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
26+
var Complex128Array = require( '@stdlib/array/complex128' );
27+
var Float64Array = require( '@stdlib/array/float64' );
28+
var zeros = require( '@stdlib/array/zeros' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var ndarray = require( '@stdlib/ndarray/ctor' );
31+
var unary = require( './../lib' );
32+
33+
34+
// TESTS //
35+
36+
tape( 'main export is a function', function test( t ) {
37+
t.ok( true, __filename );
38+
t.strictEqual( typeof unary, 'function', 'main export is a function');
39+
t.end();
40+
});
41+
42+
tape( 'the function applies a unary callback to each indexed element of a 1-dimensional ndarray', function test( t ) {
43+
var expected;
44+
var x;
45+
var y;
46+
47+
x = ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
48+
y = ndarray( 'float64', zeros( 4, 'float64' ), [ 4 ], [ 1 ], 0, 'row-major' );
49+
50+
unary( [ x, y ], scale );
51+
52+
expected = new Float64Array([
53+
10.0,
54+
20.0,
55+
30.0,
56+
40.0
57+
]);
58+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
59+
t.end();
60+
61+
function scale( x ) {
62+
return x * 10.0;
63+
}
64+
});
65+
66+
tape( 'the function applies a unary callback to each indexed element of a 1-dimensional ndarray (empty array)', function test( t ) {
67+
var expected;
68+
var x;
69+
var y;
70+
71+
x = ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 0 ], [ 1 ], 0, 'row-major' );
72+
y = ndarray( 'float64', zeros( 4, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' );
73+
74+
unary( [ x, y ], scale );
75+
76+
expected = new Float64Array([
77+
0.0,
78+
0.0,
79+
0.0,
80+
0.0
81+
]);
82+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
83+
t.end();
84+
85+
function scale( x ) {
86+
return x * 10.0;
87+
}
88+
});
89+
90+
tape( 'the function applies a unary callback to each indexed element of a 1-dimensional ndarray (accessors)', function test( t ) {
91+
var expected;
92+
var x;
93+
var y;
94+
95+
x = ndarray( 'complex128', new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
96+
y = ndarray( 'complex128', zeros( 4, 'complex128' ), [ 4 ], [ 1 ], 0, 'row-major' );
97+
98+
unary( [ x, y ], scale );
99+
100+
expected = new Complex128Array([
101+
10.0,
102+
20.0,
103+
30.0,
104+
40.0,
105+
50.0,
106+
60.0,
107+
70.0,
108+
80.0
109+
]);
110+
t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' );
111+
t.end();
112+
113+
function scale( z ) {
114+
return new Complex128( z.re*10.0, z.im*10.0 );
115+
}
116+
});

0 commit comments

Comments
 (0)