Skip to content

Commit

Permalink
test: add tests to @stdlib/ndarray/base/nullary
Browse files Browse the repository at this point in the history
PR-URL: #2350
Ref: #2229
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
headlessNode and kgryte authored Jul 14, 2024
1 parent 35af244 commit 903c51c
Show file tree
Hide file tree
Showing 13 changed files with 7,379 additions and 2 deletions.
72 changes: 72 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/nullary/test/test.0d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var tape = require( 'tape' );
var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' );
var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
var Complex128Array = require( '@stdlib/array/complex128' );
var Float64Array = require( '@stdlib/array/float64' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var constantFunction = require( '@stdlib/utils/constant-function' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var nullary = require( './../lib' );


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof nullary, 'function', 'main export is a function');
t.end();
});

tape( 'the function applies a nullary callback to each indexed element of a 0-dimensional ndarray', function test( t ) {
var expected;
var x;

x = scalar2ndarray( 0.0, {
'dtype': 'float64'
});

nullary( [ x ], constantFunction( 10.0 ) );

expected = new Float64Array( [ 10.0 ] );
t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function applies a nullary callback to each indexed element of a 0-dimensional ndarray (accessors)', function test( t ) {
var expected;
var x;

x = scalar2ndarray( new Complex128( 0.0, 0.0 ), {
'dtype': 'complex128'
});

nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) );

expected = new Complex128Array( [ 10.0, 10.0 ] );
t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' );

t.end();
});
Loading

1 comment on commit 903c51c

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
ndarray/base/nullary $\color{red}8208/8520$
$\color{green}+96.34\%$
$\color{red}305/409$
$\color{green}+74.57\%$
$\color{green}43/43$
$\color{green}+100.00\%$
$\color{red}8208/8520$
$\color{green}+96.34\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.