Skip to content

Commit f5b05ea

Browse files
headlessNodekgryte
andauthored
test: add tests to ndarray/base/some-by
PR-URL: #7305 Ref: #2656 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent e995411 commit f5b05ea

File tree

13 files changed

+20599
-1
lines changed

13 files changed

+20599
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 Complex128 = require( '@stdlib/complex/float64/ctor' );
25+
var real = require( '@stdlib/complex/float64/real' );
26+
var imag = require( '@stdlib/complex/float64/imag' );
27+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
28+
var someBy = require( './../lib' );
29+
30+
31+
// TESTS //
32+
33+
tape( 'main export is a function', function test( t ) {
34+
t.ok( true, __filename );
35+
t.strictEqual( typeof someBy, 'function', 'main export is a function');
36+
t.end();
37+
});
38+
39+
tape( 'the function tests whether at least `n` elements in a 0-dimensional ndarray pass a test implemented by a predicate function', function test( t ) {
40+
var actual;
41+
var x;
42+
var n;
43+
44+
n = scalar2ndarray( 1, {
45+
'dtype': 'generic'
46+
});
47+
48+
x = scalar2ndarray( 0.0, {
49+
'dtype': 'float64'
50+
});
51+
actual = someBy( [ x, n ], clbk );
52+
t.strictEqual( actual, false, 'returns expected value' );
53+
54+
x = scalar2ndarray( 1.0, {
55+
'dtype': 'float64'
56+
});
57+
actual = someBy( [ x, n ], clbk );
58+
t.strictEqual( actual, true, 'returns expected value' );
59+
60+
t.end();
61+
62+
function clbk( v ) {
63+
return v !== 0.0;
64+
}
65+
});
66+
67+
tape( 'the function tests whether at least `n` elements in a 0-dimensional ndarray pass a test implemented by a predicate function (accessors)', function test( t ) {
68+
var actual;
69+
var x;
70+
var n;
71+
72+
n = scalar2ndarray( 1, {
73+
'dtype': 'generic'
74+
});
75+
76+
x = scalar2ndarray( new Complex128( 0.0, 0.0 ), {
77+
'dtype': 'complex128'
78+
});
79+
actual = someBy( [ x, n ], clbk );
80+
t.strictEqual( actual, false, 'returns expected value' );
81+
82+
x = scalar2ndarray( new Complex128( 1.0, 1.0 ), {
83+
'dtype': 'complex128'
84+
});
85+
actual = someBy( [ x, n ], clbk );
86+
t.strictEqual( actual, true, 'returns expected value' );
87+
88+
t.end();
89+
90+
function clbk( v ) {
91+
return ( real( v ) !== 0.0 && imag( v ) !== 0.0 );
92+
}
93+
});

0 commit comments

Comments
 (0)