|
| 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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); |
| 26 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 27 | +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); |
| 28 | +var ndarray = require( '@stdlib/ndarray/ctor' ); |
| 29 | +var every = require( './../lib' ); |
| 30 | + |
| 31 | + |
| 32 | +// TESTS // |
| 33 | + |
| 34 | +tape( 'main export is a function', function test( t ) { |
| 35 | + t.ok( true, __filename ); |
| 36 | + t.strictEqual( typeof every, 'function', 'main export is a function'); |
| 37 | + t.end(); |
| 38 | +}); |
| 39 | + |
| 40 | +tape( 'the function tests whether every element in a 0-dimensional ndarray is truthy', function test( t ) { |
| 41 | + var actual; |
| 42 | + var x; |
| 43 | + |
| 44 | + x = scalar2ndarray( 0.0, { |
| 45 | + 'dtype': 'float64' |
| 46 | + }); |
| 47 | + |
| 48 | + actual = every( [ x ] ); |
| 49 | + t.strictEqual( actual, false, 'returns expected value' ); |
| 50 | + |
| 51 | + x = scalar2ndarray( 1.0, { |
| 52 | + 'dtype': 'float64' |
| 53 | + }); |
| 54 | + |
| 55 | + actual = every( [ x ] ); |
| 56 | + t.strictEqual( actual, true, 'returns expected value' ); |
| 57 | + |
| 58 | + t.end(); |
| 59 | +}); |
| 60 | + |
| 61 | +tape( 'the function tests whether every element in a 0-dimensional ndarray is truthy (accessors)', function test( t ) { |
| 62 | + var actual; |
| 63 | + var x; |
| 64 | + |
| 65 | + x = ndarray( 'float64', toAccessorArray( new Float64Array( [ 0.0 ] ) ), [], [ 0 ], 0, 'row-major' ); |
| 66 | + |
| 67 | + actual = every( [ x ] ); |
| 68 | + t.strictEqual( actual, false, 'returns expected value' ); |
| 69 | + |
| 70 | + x = ndarray( 'float64', toAccessorArray( new Float64Array( [ 1.0 ] ) ), [], [ 0 ], 0, 'row-major' ); |
| 71 | + |
| 72 | + actual = every( [ x ] ); |
| 73 | + t.strictEqual( actual, true, 'returns expected value' ); |
| 74 | + |
| 75 | + t.end(); |
| 76 | +}); |
| 77 | + |
| 78 | +tape( 'the function tests whether every element in a 0-dimensional ndarray is truthy (complex)', function test( t ) { |
| 79 | + var actual; |
| 80 | + var x; |
| 81 | + |
| 82 | + x = scalar2ndarray( new Complex128( 0.0, 0.0 ), { |
| 83 | + 'dtype': 'complex128' |
| 84 | + }); |
| 85 | + |
| 86 | + actual = every( [ x ] ); |
| 87 | + t.strictEqual( actual, false, 'returns expected value' ); |
| 88 | + |
| 89 | + x = scalar2ndarray( new Complex128( 1.0, 0.0 ), { |
| 90 | + 'dtype': 'complex128' |
| 91 | + }); |
| 92 | + |
| 93 | + actual = every( [ x ] ); |
| 94 | + t.strictEqual( actual, true, 'returns expected value' ); |
| 95 | + |
| 96 | + t.end(); |
| 97 | +}); |
0 commit comments