Skip to content

Commit 7449988

Browse files
committed
feat: add tests
--- 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 118bf00 commit 7449988

File tree

2 files changed

+1461
-0
lines changed

2 files changed

+1461
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
25+
var ones = require( '@stdlib/array/ones' );
26+
var zeros = require( '@stdlib/array/zeros' );
27+
var real = require( '@stdlib/complex/float64/real' );
28+
var imag = require( '@stdlib/complex/float64/imag' );
29+
var ndarray = require( '@stdlib/ndarray/ctor' );
30+
var everyBy = 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 everyBy, 'function', 'main export is a function');
38+
t.end();
39+
});
40+
41+
tape( 'the function tests whether every element in a 1-dimensional ndarray is truthy', function test( t ) {
42+
var actual;
43+
var x;
44+
45+
x = ndarray( 'float64', zeros( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' );
46+
47+
actual = everyBy( [ x ], clbk );
48+
t.strictEqual( actual, false, 'returns expected value' );
49+
50+
x = ndarray( 'float64', ones( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' );
51+
52+
actual = everyBy( [ x ], clbk );
53+
t.strictEqual( actual, true, 'returns expected value' );
54+
55+
t.end();
56+
57+
function clbk( v ) {
58+
return v !== 0;
59+
}
60+
});
61+
62+
tape( 'the function tests whether every element in a 1-dimensional ndarray is truthy (accessors)', function test( t ) {
63+
var actual;
64+
var x;
65+
66+
x = ndarray( 'float64', toAccessorArray( zeros( 8, 'float64' ) ), [ 4 ], [ 2 ], 1, 'row-major' );
67+
68+
actual = everyBy( [ x ], clbk );
69+
t.strictEqual( actual, false, 'returns expected value' );
70+
71+
x = ndarray( 'float64', toAccessorArray( ones( 8, 'float64' ) ), [ 4 ], [ 2 ], 1, 'row-major' );
72+
73+
actual = everyBy( [ x ], clbk );
74+
t.strictEqual( actual, true, 'returns expected value' );
75+
76+
t.end();
77+
78+
function clbk( v ) {
79+
return v !== 0;
80+
}
81+
});
82+
83+
tape( 'the function tests whether every element in a 1-dimensional ndarray is truthy (complex)', function test( t ) {
84+
var actual;
85+
var x;
86+
87+
x = ndarray( 'complex128', toAccessorArray( zeros( 6, 'complex128' ) ), [ 4 ], [ 1 ], 1, 'row-major' );
88+
89+
actual = everyBy( [ x ], clbk );
90+
t.strictEqual( actual, false, 'returns expected value' );
91+
92+
x = ndarray( 'complex128', toAccessorArray( ones( 6, 'complex128' ) ), [ 4 ], [ 1 ], 1, 'row-major' );
93+
94+
actual = everyBy( [ x ], clbk );
95+
t.strictEqual( actual, true, 'returns expected value' );
96+
97+
t.end();
98+
99+
function clbk( v ) {
100+
return ( real( v ) !== 0.0 && imag( v ) === 0.0 );
101+
}
102+
});

0 commit comments

Comments
 (0)