|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 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 constantFunction = require( '@stdlib/utils/constant-function' ); |
| 30 | +var scalar2ndarray = require( './../../../from-scalar' ); |
| 31 | +var nullary = 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 nullary, 'function', 'main export is a function'); |
| 39 | + t.end(); |
| 40 | +}); |
| 41 | + |
| 42 | +tape( 'the function applies a nullary callback to each indexed element of a 0-dimensional ndarray', function test( t ) { |
| 43 | + var expected; |
| 44 | + var x; |
| 45 | + |
| 46 | + x = scalar2ndarray( 0.0, { |
| 47 | + 'dtype': 'float64' |
| 48 | + }); |
| 49 | + |
| 50 | + nullary( [ x ], constantFunction( 10.0 ) ); |
| 51 | + |
| 52 | + expected = new Float64Array( [ 10.0 ] ); |
| 53 | + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); |
| 54 | + |
| 55 | + t.end(); |
| 56 | +}); |
| 57 | + |
| 58 | +tape( 'the function applies a nullary callback to each indexed element of a 0-dimensional ndarray (accessors)', function test( t ) { |
| 59 | + var expected; |
| 60 | + var x; |
| 61 | + |
| 62 | + x = scalar2ndarray( new Complex128( 0.0, 0.0 ), { |
| 63 | + 'dtype': 'complex128' |
| 64 | + }); |
| 65 | + |
| 66 | + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); |
| 67 | + |
| 68 | + expected = new Complex128Array( [ 10.0, 10.0 ] ); |
| 69 | + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); |
| 70 | + |
| 71 | + t.end(); |
| 72 | +}); |
0 commit comments