From 6826ae9cc453af3024b41ea13441bf5be5e43fc2 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 22 Sep 2025 15:05:15 +0500 Subject: [PATCH 1/5] test: add tests to ndarray/some-by for complete test coverage --- 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: passed - 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 --- --- .../@stdlib/ndarray/some-by/lib/validate.js | 3 - .../ndarray/some-by/test/test.assign.js | 1249 ++++++++++++++++ .../@stdlib/ndarray/some-by/test/test.js | 2 - .../@stdlib/ndarray/some-by/test/test.main.js | 1255 +++++++++++++++++ 4 files changed, 2504 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js diff --git a/lib/node_modules/@stdlib/ndarray/some-by/lib/validate.js b/lib/node_modules/@stdlib/ndarray/some-by/lib/validate.js index fe5c7b00edc0..b7985b72461f 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/lib/validate.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/lib/validate.js @@ -76,9 +76,6 @@ function validate( opts, ndims, options ) { if ( tmp.length !== opts.dims.length ) { return new Error( format( 'invalid option. `%s` option contains duplicate indices. Option: [%s].', 'dims', join( opts.dims, ',' ) ) ); } - if ( tmp.length > ndims ) { - return new RangeError( format( 'invalid option. `%s` option specifies more dimensions than exists in the input array. Number of dimensions: %d. Option: [%s].', 'dims', ndims, join( opts.dims, ',' ) ) ); - } opts.dims = tmp; } return null; diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js new file mode 100644 index 000000000000..5d78028c1f48 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js @@ -0,0 +1,1249 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var assign = require( './../lib/assign.js' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {*} value - array element +* @returns {boolean} test result +*/ +function clbk1( value ) { + return value > 0; +} + +/** +* Callback function. +* +* @private +* @param {*} value - array element +* @returns {boolean} test result +*/ +function clbk2( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value > 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_scalar)', function test( t ) { + var values; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, 1, y, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray)', function test( t ) { + var values; + var opts; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( value, scalar2ndarray( 1, opts ), y, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n_scalar, options)', function test( t ) { + var values; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, 1, y, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray, options)', function test( t ) { + var values; + var opts; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( value, scalar2ndarray( 1, opts ), y, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n_scalar)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n_ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (n_scalar, options)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, value, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n_ndarray, options)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), value, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, y, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options, thisArg)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, y, {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), y, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options, thisArg)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), y, {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object(n_scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, y, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object(n_ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), y, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options with invalid `dims` property(n_scalar)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dims': value + }; + assign( x, 1, y, opts, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options with invalid `dims` property(n_ndarray)', function test( t ) { + var values; + var opts1; + var opts2; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts1 = { + 'dims': value + }; + opts2 = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the output array', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + opts = { + 'dtype': 'int32' + }; + + values = [ + empty( [ 2, 2 ], opts ), + empty( [ 2, 2, 2 ], opts ), + empty( [ 1, 1, 1, 4 ], opts ), + empty( [ 3, 3, 3, 3, 3 ], opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the output array(options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + opts = { + 'dtype': 'int32' + }; + + values = [ + empty( [ 2, 2 ], opts ), + empty( [ 2, 2, 2 ], opts ), + empty( [ 1, 1, 1, 4 ], opts ), + empty( [ 3, 3, 3, 3, 3 ], opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, {}, clbk1 ); + }; + } +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_scalar)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + + actual = assign( x, 2, y, clbk1 ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + // Reset output array + y = empty( [], { + 'dtype': 'bool' + }); + + actual = assign( x, 3, y, clbk1 ); + expected = false; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + opts = { + 'dtype': 'int32' + }; + + actual = assign( x, scalar2ndarray( 2, opts ), y, clbk1 ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + // Reset output array + y = empty( [], { + 'dtype': 'bool' + }); + + actual = assign( x, scalar2ndarray( 3, opts ), y, clbk1 ); + expected = false; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_scalar)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + + actual = assign( x, 2, y, clbk1 ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + // Reset output array + y = empty( [], { + 'dtype': 'bool' + }); + + actual = assign( x, 3, y, clbk1 ); + expected = false; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + opts = { + 'dtype': 'int32' + }; + + actual = assign( x, scalar2ndarray( 2, opts ), y, clbk1 ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + // Reset output array + y = empty( [], { + 'dtype': 'bool' + }); + + actual = assign( x, scalar2ndarray( 3, opts ), y, clbk1 ); + expected = false; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major, n_scalar)', function test( t ) { + var expected; + var actual; + var opts; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, -5.0, 0.0, -7.0, 0.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts = { + 'dims': [ 0 ] + }; + y = empty( [ 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, 1, y, opts, clbk1 ); + expected = [ true, false, true, false ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts1; + var opts2; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, -5.0, 0.0, -7.0, 0.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts1 = { + 'dims': [ 0 ] + }; + opts2 = { + 'dtype': 'int32' + }; + y = empty( [ 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk1 ); + expected = [ true, false, true, false ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major, n_scalar)', function test( t ) { + var expected; + var actual; + var opts; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + + opts = { + 'dims': [ 1 ] + }; + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + actual = assign( x, 2, y, opts, clbk1 ); + expected = [ true, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts1; + var opts2; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + + opts1 = { + 'dims': [ 1 ] + }; + opts2 = { + 'dtype': 'int32' + }; + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 2, opts2 ), y, opts1, clbk1 ); + expected = [ true, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_scalar)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + + ctx = { + 'count': 0 + }; + + actual = assign( x, 2, y, clbk2, ctx ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_ndarray)', function test( t ) { + var expected; + var actual; + var opts; + var ctx; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + + ctx = { + 'count': 0 + }; + opts = { + 'dtype': 'int32' + }; + actual = assign( x, scalar2ndarray( 2, opts ), y, clbk2, ctx ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_scalar, options)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + + ctx = { + 'count': 0 + }; + + actual = assign( x, 2, y, {}, clbk2, ctx ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_ndarray, options)', function test( t ) { + var expected; + var actual; + var opts; + var ctx; + var x; + var y; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + y = empty( [], { + 'dtype': 'bool' + }); + + ctx = { + 'count': 0 + }; + opts = { + 'dtype': 'int32' + }; + actual = assign( x, scalar2ndarray( 2, opts ), y, {}, clbk2, ctx ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.js index 2d2917d3a951..e7d7dbd59961 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.js @@ -37,5 +37,3 @@ tape( 'attached to the main export is an `assign` method', function test( t ) { t.strictEqual( isMethod( someBy, 'assign' ), true, 'returns expected value' ); t.end(); }); - -// TODO: add tests diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js new file mode 100644 index 000000000000..94efea31700c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js @@ -0,0 +1,1255 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var someBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {*} value - array element +* @returns {boolean} test result +*/ +function clbk1( value ) { + return value > 0; +} + +/** +* Callback function. +* +* @private +* @param {*} value - array element +* @returns {boolean} test result +*/ +function clbk2( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value > 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof someBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_scalar)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( value, 1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray)', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( value, scalar2ndarray( 1, opts ), clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n_scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( value, 1, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray, options)', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( value, scalar2ndarray( 1, opts ), {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, {}, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, 1, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, 1, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options, thisArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, 1, {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options, thisArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object(n_scalar)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, 1, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object(n_ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with invalid `dims` property(n_scalar)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dims': value + }; + someBy( x, 1, opts, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with invalid `dims` property(n_ndarray)', function test( t ) { + var values; + var opts1; + var opts2; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts1 = { + 'dims': value + }; + opts2 = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n_scalar)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + [ 1, 3 ], + [ 3, 0 ], + [ 0, 2 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dims': value + }; + someBy( x, 1, opts, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n_ndarray)', function test( t ) { + var values; + var opts1; + var opts2; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + [ 1, 3 ], + [ 3, 0 ], + [ 0, 2 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts1 = { + 'dims': value + }; + opts2 = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n_scalar)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dims': value + }; + someBy( x, 1, opts, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n_ndarray)', function test( t ) { + var values; + var opts1; + var opts2; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts1 = { + 'dims': value + }; + opts2 = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n_scalar)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3, 4 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dims': value + }; + someBy( x, 1, opts, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n_ndarray)', function test( t ) { + var values; + var opts1; + var opts2; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3, 4 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts1 = { + 'dims': value + }; + opts2 = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n_scalar)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'keepdims': value + }; + someBy( x, 1, opts, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n_ndarray)', function test( t ) { + var values; + var opts1; + var opts2; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts1 = { + 'keepdims': value + }; + opts2 = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + opts = { + 'dtype': 'int32' + }; + + values = [ + empty( [ 2, 2 ], opts ), + empty( [ 2, 2, 2 ], opts ), + empty( [ 1, 1, 1, 4 ], opts ), + empty( [ 3, 3, 3, 3, 3 ], opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, clbk1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array(options)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + opts = { + 'dtype': 'int32' + }; + + values = [ + empty( [ 2, 2 ], opts ), + empty( [ 2, 2, 2 ], opts ), + empty( [ 1, 1, 1, 4 ], opts ), + empty( [ 3, 3, 3, 3, 3 ], opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, {}, clbk1 ); + }; + } +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_scalar)', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + + actual = someBy( x, 2, clbk1 ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + actual = someBy( x, 3, clbk1 ); + expected = false; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + opts = { + 'dtype': 'int32' + }; + + actual = someBy( x, scalar2ndarray( 2, opts ), clbk1 ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + actual = someBy( x, scalar2ndarray( 3, opts ), clbk1 ); + expected = false; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_scalar)', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); + + actual = someBy( x, 2, clbk1 ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + actual = someBy( x, 3, clbk1 ); + expected = false; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); + + opts = { + 'dtype': 'int32' + }; + actual = someBy( x, scalar2ndarray( 2, opts ), clbk1 ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + actual = someBy( x, scalar2ndarray( 3, opts ), clbk1 ); + expected = false; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major, n_scalar)', function test( t ) { + var expected; + var actual; + var opts; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, -5.0, 0.0, -7.0, 0.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts = { + 'dims': [ 0 ] + }; + actual = someBy( x, 1, opts, clbk1 ); + expected = [ true, false, true, false ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk1 ); + expected = [ [ true, false, true, false ] ]; + + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts1; + var opts2; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, -5.0, 0.0, -7.0, 0.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts1 = { + 'dims': [ 0 ] + }; + opts2 = { + 'dtype': 'int32' + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + expected = [ true, false, true, false ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + expected = [ [ true, false, true, false ] ]; + + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major, n_scalar)', function test( t ) { + var expected; + var actual; + var opts; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + + opts = { + 'dims': [ 1 ] + }; + actual = someBy( x, 2, opts, clbk1 ); + expected = [ true, false ]; + + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = someBy( x, 2, opts, clbk1 ); + expected = [ [ true ], [ false ] ]; + + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major, n_ndarray)', function test( t ) { + var expected; + var actual; + var opts1; + var opts2; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + + opts1 = { + 'dims': [ 1 ] + }; + opts2 = { + 'dtype': 'int32' + }; + actual = someBy( x, scalar2ndarray( 2, opts2 ), opts1, clbk1 ); + expected = [ true, false ]; + + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 2, opts2 ), opts1, clbk1 ); + expected = [ [ true ], [ false ] ]; + + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_scalar)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + + ctx = { + 'count': 0 + }; + + actual = someBy( x, 2, clbk2, ctx ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_ndarray)', function test( t ) { + var expected; + var actual; + var opts; + var ctx; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + + ctx = { + 'count': 0 + }; + opts = { + 'dtype': 'int32' + }; + actual = someBy( x, scalar2ndarray( 2, opts ), clbk2, ctx ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_scalar, options)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + + ctx = { + 'count': 0 + }; + + actual = someBy( x, 2, {}, clbk2, ctx ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a callback execution context(n_ndarray, options)', function test( t ) { + var expected; + var actual; + var opts; + var ctx; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + + ctx = { + 'count': 0 + }; + opts = { + 'dtype': 'int32' + }; + actual = someBy( x, scalar2ndarray( 2, opts ), {}, clbk2, ctx ); + expected = true; + + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); +}); From d059154448dc33160cafbcac711c114fdb426d9b Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 23 Sep 2025 14:03:27 +0500 Subject: [PATCH 2/5] docs: apply suggestions from code review --- 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 --- --- .../ndarray/some-by/test/test.assign.js | 60 ++++++++-------- .../@stdlib/ndarray/some-by/test/test.main.js | 68 +++++++++---------- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js index 5d78028c1f48..875fadbea09c 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js @@ -63,7 +63,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=scalar)', function test( t ) { var values; var y; var i; @@ -97,7 +97,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray)', function test( t ) { var values; var opts; var y; @@ -135,7 +135,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n_scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=scalar, options)', function test( t ) { var values; var y; var i; @@ -169,7 +169,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, options)', function test( t ) { var values; var opts; var y; @@ -304,7 +304,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=scalar)', function test( t ) { var values; var x; var i; @@ -338,7 +338,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=ndarray)', function test( t ) { var values; var opts; var x; @@ -376,7 +376,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (n_scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (n=scalar, options)', function test( t ) { var values; var x; var i; @@ -410,7 +410,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n_ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=ndarray, options)', function test( t ) { var values; var opts; var x; @@ -448,7 +448,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar)', function test( t ) { var values; var x; var y; @@ -485,7 +485,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options)', function test( t ) { var values; var x; var y; @@ -522,7 +522,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options, thisArg)', function test( t ) { var values; var x; var y; @@ -559,7 +559,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray)', function test( t ) { var values; var opts; var x; @@ -600,7 +600,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options)', function test( t ) { var values; var opts; var x; @@ -641,7 +641,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options, thisArg)', function test( t ) { var values; var opts; var x; @@ -682,7 +682,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object(n=scalar)', function test( t ) { var values; var x; var y; @@ -718,7 +718,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray)', function test( t ) { var values; var opts; var x; @@ -758,7 +758,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options with invalid `dims` property(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options with invalid `dims` property(n=scalar)', function test( t ) { var values; var opts; var x; @@ -797,7 +797,7 @@ tape( 'the function throws an error if provided an options with invalid `dims` p } }); -tape( 'the function throws an error if provided an options with invalid `dims` property(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options with invalid `dims` property(n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -912,7 +912,7 @@ tape( 'the function throws an error if provided a second argument which is not b } }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_scalar)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n=scalar)', function test( t ) { var expected; var actual; var x; @@ -943,7 +943,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_ndarray)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n=ndarray)', function test( t ) { var expected; var actual; var opts; @@ -978,7 +978,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_scalar)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n=scalar)', function test( t ) { var expected; var actual; var x; @@ -1009,7 +1009,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_ndarray)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n=ndarray)', function test( t ) { var expected; var actual; var opts; @@ -1044,7 +1044,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function supports specifying reduction dimensions (row-major, n_scalar)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (row-major, n=scalar)', function test( t ) { var expected; var actual; var opts; @@ -1066,7 +1066,7 @@ tape( 'the function supports specifying reduction dimensions (row-major, n_scala t.end(); }); -tape( 'the function supports specifying reduction dimensions (row-major, n_ndarray)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (row-major, n=ndarray)', function test( t ) { var expected; var actual; var opts1; @@ -1092,7 +1092,7 @@ tape( 'the function supports specifying reduction dimensions (row-major, n_ndarr t.end(); }); -tape( 'the function supports specifying reduction dimensions (column-major, n_scalar)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (column-major, n=scalar)', function test( t ) { var expected; var actual; var opts; @@ -1115,7 +1115,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n_sc t.end(); }); -tape( 'the function supports specifying reduction dimensions (column-major, n_ndarray)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (column-major, n=ndarray)', function test( t ) { var expected; var actual; var opts1; @@ -1142,7 +1142,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n_nd t.end(); }); -tape( 'the function supports providing a callback execution context(n_scalar)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=scalar)', function test( t ) { var expected; var actual; var ctx; @@ -1167,7 +1167,7 @@ tape( 'the function supports providing a callback execution context(n_scalar)', t.end(); }); -tape( 'the function supports providing a callback execution context(n_ndarray)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=ndarray)', function test( t ) { var expected; var actual; var opts; @@ -1195,7 +1195,7 @@ tape( 'the function supports providing a callback execution context(n_ndarray)', t.end(); }); -tape( 'the function supports providing a callback execution context(n_scalar, options)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=scalar, options)', function test( t ) { var expected; var actual; var ctx; @@ -1220,7 +1220,7 @@ tape( 'the function supports providing a callback execution context(n_scalar, op t.end(); }); -tape( 'the function supports providing a callback execution context(n_ndarray, options)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=ndarray, options)', function test( t ) { var expected; var actual; var opts; diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js index 94efea31700c..87dcb298393c 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js @@ -63,7 +63,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=scalar)', function test( t ) { var values; var i; @@ -92,7 +92,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray)', function test( t ) { var values; var opts; var i; @@ -125,7 +125,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n_scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=scalar, options)', function test( t ) { var values; var i; @@ -154,7 +154,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n_ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, options)', function test( t ) { var values; var opts; var i; @@ -272,7 +272,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar)', function test( t ) { var values; var x; var i; @@ -305,7 +305,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options)', function test( t ) { var values; var x; var i; @@ -338,7 +338,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_scalar, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options, thisArg)', function test( t ) { var values; var x; var i; @@ -371,7 +371,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray)', function test( t ) { var values; var opts; var x; @@ -408,7 +408,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options)', function test( t ) { var values; var opts; var x; @@ -445,7 +445,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n_ndarray, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options, thisArg)', function test( t ) { var values; var opts; var x; @@ -482,7 +482,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object(n=scalar)', function test( t ) { var values; var x; var i; @@ -514,7 +514,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray)', function test( t ) { var values; var opts; var x; @@ -550,7 +550,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument with invalid `dims` property(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with invalid `dims` property(n=scalar)', function test( t ) { var values; var opts; var x; @@ -586,7 +586,7 @@ tape( 'the function throws an error if provided an options argument with invalid } }); -tape( 'the function throws an error if provided an options argument with invalid `dims` property(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with invalid `dims` property(n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -626,7 +626,7 @@ tape( 'the function throws an error if provided an options argument with invalid } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n=scalar)', function test( t ) { var values; var opts; var x; @@ -657,7 +657,7 @@ tape( 'the function throws an error if provided an options argument with a `dims } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -692,7 +692,7 @@ tape( 'the function throws an error if provided an options argument with a `dims } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n=scalar)', function test( t ) { var values; var opts; var x; @@ -722,7 +722,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -756,7 +756,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n=scalar)', function test( t ) { var values; var opts; var x; @@ -787,7 +787,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -822,7 +822,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n_scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n=scalar)', function test( t ) { var values; var opts; var x; @@ -858,7 +858,7 @@ tape( 'the function throws an error if provided an options argument with invalid } }); -tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n_ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -962,7 +962,7 @@ tape( 'the function throws an error if provided a second argument which is not b } }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_scalar)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n=scalar)', function test( t ) { var expected; var actual; var x; @@ -982,7 +982,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n_ndarray)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (row-major, n=ndarray)', function test( t ) { var expected; var actual; var opts; @@ -1006,7 +1006,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_scalar)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n=scalar)', function test( t ) { var expected; var actual; var x; @@ -1026,7 +1026,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n_ndarray)', function test( t ) { +tape( 'the function tests whether at least `n` elements along one or more ndarray dimensions pass a test implemented by a predicate function (column-major, n=ndarray)', function test( t ) { var expected; var actual; var opts; @@ -1050,7 +1050,7 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra t.end(); }); -tape( 'the function supports specifying reduction dimensions (row-major, n_scalar)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (row-major, n=scalar)', function test( t ) { var expected; var actual; var opts; @@ -1077,7 +1077,7 @@ tape( 'the function supports specifying reduction dimensions (row-major, n_scala t.end(); }); -tape( 'the function supports specifying reduction dimensions (row-major, n_ndarray)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (row-major, n=ndarray)', function test( t ) { var expected; var actual; var opts1; @@ -1108,7 +1108,7 @@ tape( 'the function supports specifying reduction dimensions (row-major, n_ndarr t.end(); }); -tape( 'the function supports specifying reduction dimensions (column-major, n_scalar)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (column-major, n=scalar)', function test( t ) { var expected; var actual; var opts; @@ -1136,7 +1136,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n_sc t.end(); }); -tape( 'the function supports specifying reduction dimensions (column-major, n_ndarray)', function test( t ) { +tape( 'the function supports specifying reduction dimensions (column-major, n=ndarray)', function test( t ) { var expected; var actual; var opts1; @@ -1168,7 +1168,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n_nd t.end(); }); -tape( 'the function supports providing a callback execution context(n_scalar)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=scalar)', function test( t ) { var expected; var actual; var ctx; @@ -1188,7 +1188,7 @@ tape( 'the function supports providing a callback execution context(n_scalar)', t.end(); }); -tape( 'the function supports providing a callback execution context(n_ndarray)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=ndarray)', function test( t ) { var expected; var actual; var opts; @@ -1211,7 +1211,7 @@ tape( 'the function supports providing a callback execution context(n_ndarray)', t.end(); }); -tape( 'the function supports providing a callback execution context(n_scalar, options)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=scalar, options)', function test( t ) { var expected; var actual; var ctx; @@ -1231,7 +1231,7 @@ tape( 'the function supports providing a callback execution context(n_scalar, op t.end(); }); -tape( 'the function supports providing a callback execution context(n_ndarray, options)', function test( t ) { +tape( 'the function supports providing a callback execution context(n=ndarray, options)', function test( t ) { var expected; var actual; var opts; From 5c988545a5597bcc23d20632d0056be476d0c12f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 23 Sep 2025 15:04:17 +0500 Subject: [PATCH 3/5] refactor: apply suggestions from code review --- 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 --- --- .../@stdlib/ndarray/some-by/test/test.main.js | 972 ++++++++++++++++-- 1 file changed, 889 insertions(+), 83 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js index 87dcb298393c..8268a15cacbd 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var empty = require( '@stdlib/ndarray/empty' ); @@ -38,19 +39,7 @@ var someBy = require( './../lib' ); * @param {*} value - array element * @returns {boolean} test result */ -function clbk1( value ) { - return value > 0; -} - -/** -* Callback function. -* -* @private -* @param {*} value - array element -* @returns {boolean} test result -*/ -function clbk2( value ) { - this.count += 1; // eslint-disable-line no-invalid-this +function clbk( value ) { return value > 0; } @@ -87,7 +76,36 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - someBy( value, 1, clbk1 ); + someBy( value, 1, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=scalar, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( value, 1, clbk, {} ); }; } }); @@ -120,7 +138,40 @@ tape( 'the function throws an error if provided a first argument which is not an opts = { 'dtype': 'int32' }; - someBy( value, scalar2ndarray( 1, opts ), clbk1 ); + someBy( value, scalar2ndarray( 1, opts ), clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, thisArg)', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( value, scalar2ndarray( 1, opts ), clbk, {} ); }; } }); @@ -149,7 +200,36 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - someBy( value, 1, {}, clbk1 ); + someBy( value, 1, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=scalar, options, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( value, 1, {}, clbk, {} ); }; } }); @@ -182,7 +262,40 @@ tape( 'the function throws an error if provided a first argument which is not an opts = { 'dtype': 'int32' }; - someBy( value, scalar2ndarray( 1, opts ), {}, clbk1 ); + someBy( value, scalar2ndarray( 1, opts ), {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, options, thisArg)', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( value, scalar2ndarray( 1, opts ), {}, clbk, {} ); }; } }); @@ -215,7 +328,106 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - someBy( x, value, clbk1 ); + someBy( x, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(thisArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options, thisArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, {}, clbk, {} ); }; } }); @@ -241,7 +453,33 @@ tape( 'the function throws an error if provided a second argument which is an nd function badValue( value ) { return function badValue() { - someBy( x, value, clbk1 ); + someBy( x, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(thiArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, clbk, {} ); }; } }); @@ -267,7 +505,33 @@ tape( 'the function throws an error if provided a second argument which is an nd function badValue( value ) { return function badValue() { - someBy( x, value, {}, clbk1 ); + someBy( x, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options, thisArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, {}, clbk, {} ); }; } }); @@ -305,6 +569,39 @@ tape( 'the function throws an error if provided a callback argument which is not } }); +tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, thisArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, 1, value, {} ); + }; + } +}); + tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options)', function test( t ) { var values; var x; @@ -408,6 +705,43 @@ tape( 'the function throws an error if provided a callback argument which is not } }); +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, thisArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), value, {} ); + }; + } +}); + tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options)', function test( t ) { var values; var opts; @@ -445,9 +779,77 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options, thisArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), {}, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object(n=scalar)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, 1, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object(n=scalar, thisArg)', function test( t ) { var values; - var opts; var x; var i; @@ -463,7 +865,6 @@ tape( 'the function throws an error if provided a callback argument which is not false, null, void 0, - {}, [] ]; @@ -474,16 +875,14 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - opts = { - 'dtype': 'int32' - }; - someBy( x, scalar2ndarray( 1, opts ), {}, value, {} ); + someBy( x, 1, value, clbk, {} ); }; } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray)', function test( t ) { var values; + var opts; var x; var i; @@ -509,12 +908,15 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - someBy( x, 1, value, clbk1 ); + opts = { + 'dtype': 'int32' + }; + someBy( x, scalar2ndarray( 1, opts ), value, clbk ); }; } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray, thisArg)', function test( t ) { var values; var opts; var x; @@ -545,7 +947,7 @@ tape( 'the function throws an error if provided an options argument which is not opts = { 'dtype': 'int32' }; - someBy( x, scalar2ndarray( 1, opts ), value, clbk1 ); + someBy( x, scalar2ndarray( 1, opts ), value, clbk, {} ); }; } }); @@ -581,7 +983,7 @@ tape( 'the function throws an error if provided an options argument with invalid opts = { 'dims': value }; - someBy( x, 1, opts, clbk1 ); + someBy( x, 1, opts, clbk ); }; } }); @@ -621,7 +1023,7 @@ tape( 'the function throws an error if provided an options argument with invalid opts2 = { 'dtype': 'int32' }; - someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); }; } }); @@ -652,7 +1054,7 @@ tape( 'the function throws an error if provided an options argument with a `dims opts = { 'dims': value }; - someBy( x, 1, opts, clbk1 ); + someBy( x, 1, opts, clbk ); }; } }); @@ -687,7 +1089,7 @@ tape( 'the function throws an error if provided an options argument with a `dims opts2 = { 'dtype': 'int32' }; - someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); }; } }); @@ -717,7 +1119,7 @@ tape( 'the function throws an error if provided an options argument with `dims` opts = { 'dims': value }; - someBy( x, 1, opts, clbk1 ); + someBy( x, 1, opts, clbk ); }; } }); @@ -751,7 +1153,7 @@ tape( 'the function throws an error if provided an options argument with `dims` opts2 = { 'dtype': 'int32' }; - someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); }; } }); @@ -782,7 +1184,7 @@ tape( 'the function throws an error if provided an options argument with `dims` opts = { 'dims': value }; - someBy( x, 1, opts, clbk1 ); + someBy( x, 1, opts, clbk ); }; } }); @@ -817,7 +1219,7 @@ tape( 'the function throws an error if provided an options argument with `dims` opts2 = { 'dtype': 'int32' }; - someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); }; } }); @@ -853,7 +1255,7 @@ tape( 'the function throws an error if provided an options argument with invalid opts = { 'keepdims': value }; - someBy( x, 1, opts, clbk1 ); + someBy( x, 1, opts, clbk ); }; } }); @@ -893,7 +1295,7 @@ tape( 'the function throws an error if provided an options argument with invalid opts2 = { 'dtype': 'int32' }; - someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); }; } }); @@ -925,7 +1327,39 @@ tape( 'the function throws an error if provided a second argument which is not b function badValue( value ) { return function badValue() { - someBy( x, value, clbk1 ); + someBy( x, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array(thiArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + opts = { + 'dtype': 'int32' + }; + + values = [ + empty( [ 2, 2 ], opts ), + empty( [ 2, 2, 2 ], opts ), + empty( [ 1, 1, 1, 4 ], opts ), + empty( [ 3, 3, 3, 3, 3 ], opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, clbk, {} ); }; } }); @@ -957,7 +1391,39 @@ tape( 'the function throws an error if provided a second argument which is not b function badValue( value ) { return function badValue() { - someBy( x, value, {}, clbk1 ); + someBy( x, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array(options, thisArg)', function test( t ) { + var values; + var opts; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + opts = { + 'dtype': 'int32' + }; + + values = [ + empty( [ 2, 2 ], opts ), + empty( [ 2, 2, 2 ], opts ), + empty( [ 1, 1, 1, 4 ], opts ), + empty( [ 3, 3, 3, 3, 3 ], opts ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + someBy( x, value, {}, clbk, {} ); }; } }); @@ -969,14 +1435,16 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); - actual = someBy( x, 2, clbk1 ); + actual = someBy( x, 2, clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - actual = someBy( x, 3, clbk1 ); + actual = someBy( x, 3, clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); t.end(); @@ -993,14 +1461,16 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'int32' }; - actual = someBy( x, scalar2ndarray( 2, opts ), clbk1 ); + actual = someBy( x, scalar2ndarray( 2, opts ), clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - actual = someBy( x, scalar2ndarray( 3, opts ), clbk1 ); + actual = someBy( x, scalar2ndarray( 3, opts ), clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); t.end(); @@ -1013,14 +1483,16 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); - actual = someBy( x, 2, clbk1 ); + actual = someBy( x, 2, clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - actual = someBy( x, 3, clbk1 ); + actual = someBy( x, 3, clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); t.end(); @@ -1037,14 +1509,16 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra opts = { 'dtype': 'int32' }; - actual = someBy( x, scalar2ndarray( 2, opts ), clbk1 ); + actual = someBy( x, scalar2ndarray( 2, opts ), clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - actual = someBy( x, scalar2ndarray( 3, opts ), clbk1 ); + actual = someBy( x, scalar2ndarray( 3, opts ), clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); t.end(); @@ -1061,17 +1535,69 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=scala opts = { 'dims': [ 0 ] }; - actual = someBy( x, 1, opts, clbk1 ); + actual = someBy( x, 1, opts, clbk ); expected = [ true, false, true, false ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts = { 'dims': [ 0 ], 'keepdims': true }; - actual = someBy( x, 1, opts, clbk1 ); + actual = someBy( x, 1, opts, clbk ); expected = [ [ true, false, true, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ true, false ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true ], [ false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + actual = someBy( x, 1, opts, clbk ); + expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [] + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true, false, true, false ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + opts = { + 'dims': [], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true, false, true, false ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); @@ -1092,17 +1618,69 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=ndarr opts2 = { 'dtype': 'int32' }; - actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); expected = [ true, false, true, false ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts1 = { 'dims': [ 0 ], 'keepdims': true }; - actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk1 ); + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); expected = [ [ true, false, true, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 1 ] + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ true, false ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true ], [ false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0, 1 ] + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [] + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true, false, true, false ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + opts1 = { + 'dims': [], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true, false, true, false ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); @@ -1114,23 +1692,74 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=sc var opts; var x; - x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + + opts = { + 'dims': [ 0 ] + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ true, true, true, true ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true, true, true, true ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts = { 'dims': [ 1 ] }; - actual = someBy( x, 2, opts, clbk1 ); + actual = someBy( x, 1, opts, clbk ); expected = [ true, false ]; - + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts = { 'dims': [ 1 ], 'keepdims': true }; - actual = someBy( x, 2, opts, clbk1 ); + actual = someBy( x, 1, opts, clbk ); expected = [ [ true ], [ false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + actual = someBy( x, 1, opts, clbk ); + expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + opts = { + 'dims': [] + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true, true, true, true ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [], + 'keepdims': true + }; + actual = someBy( x, 1, opts, clbk ); + expected = [ [ true, true, true, true ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); @@ -1143,26 +1772,77 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd var opts2; var x; - x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); opts1 = { - 'dims': [ 1 ] + 'dims': [ 0 ] }; opts2 = { 'dtype': 'int32' }; - actual = someBy( x, scalar2ndarray( 2, opts2 ), opts1, clbk1 ); - expected = [ true, false ]; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ true, true, true, true ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true, true, true, true ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + opts1 = { + 'dims': [ 1 ] + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ true, false ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts1 = { 'dims': [ 1 ], 'keepdims': true }; - actual = someBy( x, scalar2ndarray( 2, opts2 ), opts1, clbk1 ); + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); expected = [ [ true ], [ false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0, 1 ] + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [] + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true, true, true, true ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + opts1 = { + 'dims': [], + 'keepdims': true + }; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, clbk ); + expected = [ [ true, true, true, true ], [ false, false, false, false ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); @@ -1170,32 +1850,64 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd tape( 'the function supports providing a callback execution context(n=scalar)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; var ctx; var x; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); ctx = { 'count': 0 }; - - actual = someBy( x, 2, clbk2, ctx ); + indices = []; + values = []; + arrays = []; + actual = someBy( x, 1, predicate, ctx ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ], + [ 2 ], + [ 3 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); tape( 'the function supports providing a callback execution context(n=ndarray)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; var opts; var ctx; var x; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); ctx = { 'count': 0 @@ -1203,53 +1915,147 @@ tape( 'the function supports providing a callback execution context(n=ndarray)', opts = { 'dtype': 'int32' }; - actual = someBy( x, scalar2ndarray( 2, opts ), clbk2, ctx ); + indices = []; + values = []; + arrays = []; + actual = someBy( x, scalar2ndarray( 1, opts ), predicate, ctx ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ], + [ 2 ], + [ 3 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); tape( 'the function supports providing a callback execution context(n=scalar, options)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; + var opts; var ctx; var x; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); ctx = { 'count': 0 }; + opts = { + 'dims': [ 0 ] + }; + indices = []; + values = []; + arrays = []; + actual = someBy( x, 1, opts, predicate, ctx ); + expected = [ false, true ]; - actual = someBy( x, 2, {}, clbk2, ctx ); - expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ], + [ 0, 1 ], + [ 1, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); - t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); tape( 'the function supports providing a callback execution context(n=ndarray, options)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; - var opts; + var opts1; + var opts2; var ctx; var x; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); ctx = { 'count': 0 }; - opts = { + opts1 = { + 'dims': [ 0 ] + }; + opts2 = { 'dtype': 'int32' }; - actual = someBy( x, scalar2ndarray( 2, opts ), {}, clbk2, ctx ); - expected = true; + indices = []; + values = []; + arrays = []; + actual = someBy( x, scalar2ndarray( 1, opts2 ), opts1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ], + [ 0, 1 ], + [ 1, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); - t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); From 4bd3f8c579bf392c4ea8b79f6ba08a04d05a400a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 23 Sep 2025 15:19:21 +0500 Subject: [PATCH 4/5] refactor: apply suggestions from code review --- 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 --- --- .../ndarray/some-by/test/test.assign.js | 602 ++++++++++++++++-- 1 file changed, 538 insertions(+), 64 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js index 875fadbea09c..1960d90f7a98 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var empty = require( '@stdlib/ndarray/empty' ); @@ -38,19 +39,7 @@ var assign = require( './../lib/assign.js' ); * @param {*} value - array element * @returns {boolean} test result */ -function clbk1( value ) { - return value > 0; -} - -/** -* Callback function. -* -* @private -* @param {*} value - array element -* @returns {boolean} test result -*/ -function clbk2( value ) { - this.count += 1; // eslint-disable-line no-invalid-this +function clbk( value ) { return value > 0; } @@ -92,7 +81,41 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, 1, y, clbk1 ); + assign( value, 1, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=scalar, thisArg)', function test( t ) { + var values; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, 1, y, clbk, {} ); }; } }); @@ -130,7 +153,45 @@ tape( 'the function throws an error if provided a first argument which is not an opts = { 'dtype': 'int32' }; - assign( value, scalar2ndarray( 1, opts ), y, clbk1 ); + assign( value, scalar2ndarray( 1, opts ), y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, thisArg)', function test( t ) { + var values; + var opts; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( value, scalar2ndarray( 1, opts ), y, clbk, {} ); }; } }); @@ -164,7 +225,41 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, 1, y, {}, clbk1 ); + assign( value, 1, y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=scalar, options, thisArg)', function test( t ) { + var values; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, 1, y, {}, clbk, {} ); }; } }); @@ -202,7 +297,45 @@ tape( 'the function throws an error if provided a first argument which is not an opts = { 'dtype': 'int32' }; - assign( value, scalar2ndarray( 1, opts ), y, {}, clbk1 ); + assign( value, scalar2ndarray( 1, opts ), y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, options, thisArg)', function test( t ) { + var values; + var opts; + var y; + var i; + + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( value, scalar2ndarray( 1, opts ), y, {}, clbk, {} ); }; } }); @@ -239,7 +372,118 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - assign( x, value, y, clbk1 ); + assign( x, value, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(thisArg)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options, thisArg)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, {}, clbk, {} ); }; } }); @@ -269,7 +513,37 @@ tape( 'the function throws an error if provided a second argument which is an nd function badValue( value ) { return function badValue() { - assign( x, value, y, clbk1 ); + assign( x, value, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(thisArg)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, clbk, {} ); }; } }); @@ -299,7 +573,37 @@ tape( 'the function throws an error if provided a second argument which is an nd function badValue( value ) { return function badValue() { - assign( x, value, y, {}, clbk1 ); + assign( x, value, y, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options, thisArg)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [], { + 'dtype': 'bool' + }); + + values = [ + new ndarray( 'float64', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ), + new ndarray( 'float32', new Float64Array( [ 1 ] ), [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value, y, {}, clbk, {} ); }; } }); @@ -333,7 +637,41 @@ tape( 'the function throws an error if provided a third argument which is not an function badValue( value ) { return function badValue() { - assign( x, 1, value, clbk1 ); + assign( x, 1, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=scalar, thisArg)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, value, clbk, {} ); }; } }); @@ -371,7 +709,7 @@ tape( 'the function throws an error if provided a third argument which is not an opts = { 'dtype': 'int32' }; - assign( x, scalar2ndarray( 1, opts ), value, clbk1 ); + assign( x, scalar2ndarray( 1, opts ), value, clbk ); }; } }); @@ -405,7 +743,7 @@ tape( 'the function throws an error if provided a third argument which is not an function badValue( value ) { return function badValue() { - assign( x, 1, value, {}, clbk1 ); + assign( x, 1, value, {}, clbk ); }; } }); @@ -443,7 +781,7 @@ tape( 'the function throws an error if provided a third argument which is not an opts = { 'dtype': 'int32' }; - assign( x, scalar2ndarray( 1, opts ), value, {}, clbk1 ); + assign( x, scalar2ndarray( 1, opts ), value, {}, clbk ); }; } }); @@ -713,7 +1051,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - assign( x, 1, y, value, clbk1 ); + assign( x, 1, y, value, clbk ); }; } }); @@ -753,7 +1091,7 @@ tape( 'the function throws an error if provided an options argument which is not opts = { 'dtype': 'int32' }; - assign( x, scalar2ndarray( 1, opts ), y, value, clbk1 ); + assign( x, scalar2ndarray( 1, opts ), y, value, clbk ); }; } }); @@ -792,7 +1130,7 @@ tape( 'the function throws an error if provided an options with invalid `dims` p opts = { 'dims': value }; - assign( x, 1, y, opts, clbk1 ); + assign( x, 1, y, opts, clbk ); }; } }); @@ -835,7 +1173,7 @@ tape( 'the function throws an error if provided an options with invalid `dims` p opts2 = { 'dtype': 'int32' }; - assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk1 ); + assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk ); }; } }); @@ -871,7 +1209,7 @@ tape( 'the function throws an error if provided a second argument which is not b function badValue( value ) { return function badValue() { - assign( x, value, y, clbk1 ); + assign( x, value, y, clbk ); }; } }); @@ -907,7 +1245,7 @@ tape( 'the function throws an error if provided a second argument which is not b function badValue( value ) { return function badValue() { - assign( x, value, y, {}, clbk1 ); + assign( x, value, y, {}, clbk ); }; } }); @@ -923,9 +1261,11 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'bool' }); - actual = assign( x, 2, y, clbk1 ); + actual = assign( x, 2, y, clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -934,9 +1274,11 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'bool' }); - actual = assign( x, 3, y, clbk1 ); + actual = assign( x, 3, y, clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -958,9 +1300,10 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'int32' }; - actual = assign( x, scalar2ndarray( 2, opts ), y, clbk1 ); + actual = assign( x, scalar2ndarray( 2, opts ), y, clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -969,9 +1312,10 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'bool' }); - actual = assign( x, scalar2ndarray( 3, opts ), y, clbk1 ); + actual = assign( x, scalar2ndarray( 3, opts ), y, clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -989,9 +1333,10 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'bool' }); - actual = assign( x, 2, y, clbk1 ); + actual = assign( x, 2, y, clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1000,9 +1345,10 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'bool' }); - actual = assign( x, 3, y, clbk1 ); + actual = assign( x, 3, y, clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1024,9 +1370,10 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'int32' }; - actual = assign( x, scalar2ndarray( 2, opts ), y, clbk1 ); + actual = assign( x, scalar2ndarray( 2, opts ), y, clbk ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1035,9 +1382,10 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra 'dtype': 'bool' }); - actual = assign( x, scalar2ndarray( 3, opts ), y, clbk1 ); + actual = assign( x, scalar2ndarray( 3, opts ), y, clbk ); expected = false; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1059,7 +1407,7 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=scala y = empty( [ 4 ], { 'dtype': 'bool' }); - actual = assign( x, 1, y, opts, clbk1 ); + actual = assign( x, 1, y, opts, clbk ); expected = [ true, false, true, false ]; t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1085,7 +1433,7 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=ndarr y = empty( [ 4 ], { 'dtype': 'bool' }); - actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk1 ); + actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk ); expected = [ true, false, true, false ]; t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1107,7 +1455,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=sc y = empty( [ 2 ], { 'dtype': 'bool' }); - actual = assign( x, 2, y, opts, clbk1 ); + actual = assign( x, 2, y, opts, clbk ); expected = [ true, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1134,7 +1482,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd y = empty( [ 2 ], { 'dtype': 'bool' }); - actual = assign( x, scalar2ndarray( 2, opts2 ), y, opts1, clbk1 ); + actual = assign( x, scalar2ndarray( 2, opts2 ), y, opts1, clbk ); expected = [ true, false ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1144,12 +1492,15 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd tape( 'the function supports providing a callback execution context(n=scalar)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; var ctx; var x; var y; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); y = empty( [], { 'dtype': 'bool' }); @@ -1157,25 +1508,54 @@ tape( 'the function supports providing a callback execution context(n=scalar)', ctx = { 'count': 0 }; - - actual = assign( x, 2, y, clbk2, ctx ); + indices = []; + values = []; + arrays = []; + actual = assign( x, 1, y, predicate, ctx ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ], + [ 2 ], + [ 3 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); tape( 'the function supports providing a callback execution context(n=ndarray)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; var opts; var ctx; var x; var y; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); y = empty( [], { 'dtype': 'bool' }); @@ -1186,64 +1566,158 @@ tape( 'the function supports providing a callback execution context(n=ndarray)', opts = { 'dtype': 'int32' }; - actual = assign( x, scalar2ndarray( 2, opts ), y, clbk2, ctx ); + indices = []; + values = []; + arrays = []; + actual = assign( x, scalar2ndarray( 1, opts ), y, predicate, ctx ); expected = true; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0 ], + [ 1 ], + [ 2 ], + [ 3 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); tape( 'the function supports providing a callback execution context(n=scalar, options)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; + var opts; var ctx; var x; var y; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); - y = empty( [], { + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = empty( [ 2 ], { 'dtype': 'bool' }); ctx = { 'count': 0 }; + opts = { + 'dims': [ 0 ] + }; + indices = []; + values = []; + arrays = []; + actual = assign( x, 1, y, opts, predicate, ctx ); + expected = [ false, true ]; - actual = assign( x, 2, y, {}, clbk2, ctx ); - expected = true; - + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ], + [ 0, 1 ], + [ 1, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); tape( 'the function supports providing a callback execution context(n=ndarray, options)', function test( t ) { var expected; + var indices; + var values; + var arrays; var actual; - var opts; + var opts1; + var opts2; var ctx; var x; var y; - x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); - y = empty( [], { + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = empty( [ 2 ], { 'dtype': 'bool' }); ctx = { 'count': 0 }; - opts = { + opts1 = { + 'dims': [ 0 ] + }; + opts2 = { 'dtype': 'int32' }; - actual = assign( x, scalar2ndarray( 2, opts ), y, {}, clbk2, ctx ); - expected = true; + indices = []; + values = []; + arrays = []; + actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, predicate, ctx ); + expected = [ false, true ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ -1.0, -2.0, -3.0, 4.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0 ], + [ 1, 0 ], + [ 0, 1 ], + [ 1, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function predicate( value, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( value ); + indices.push( idx ); + arrays.push( arr ); + return value > 0.0; + } }); From 42af74f24f018477cdf33941ba1e562eb00a7267 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 24 Sep 2025 23:28:26 -0700 Subject: [PATCH 5/5] test: add tests and clean-up --- 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 --- --- .../ndarray/some-by/test/test.assign.js | 305 +++++++++++++++--- .../@stdlib/ndarray/some-by/test/test.main.js | 98 +++--- 2 files changed, 307 insertions(+), 96 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js index 1960d90f7a98..1cdd01aafdba 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.assign.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var empty = require( '@stdlib/ndarray/empty' ); @@ -36,8 +35,8 @@ var assign = require( './../lib/assign.js' ); * Callback function. * * @private -* @param {*} value - array element -* @returns {boolean} test result +* @param {*} value - input value +* @returns {boolean} result */ function clbk( value ) { return value > 0; @@ -377,7 +376,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object (thisArg)', function test( t ) { var values; var x; var y; @@ -392,6 +391,7 @@ tape( 'the function throws an error if provided a second argument which is not a values = [ '5', + 3.14, NaN, true, false, @@ -414,7 +414,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object (options)', function test( t ) { var values; var x; var y; @@ -429,6 +429,7 @@ tape( 'the function throws an error if provided a second argument which is not a values = [ '5', + 3.14, NaN, true, false, @@ -451,7 +452,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object (options, thisArg)', function test( t ) { var values; var x; var y; @@ -518,7 +519,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type (thisArg)', function test( t ) { var values; var x; var y; @@ -548,7 +549,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type (options)', function test( t ) { var values; var x; var y; @@ -578,7 +579,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type (options, thisArg)', function test( t ) { var values; var x; var y; @@ -608,7 +609,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (n=scalar)', function test( t ) { var values; var x; var i; @@ -642,7 +643,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=scalar, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (n=scalar, thisArg)', function test( t ) { var values; var x; var i; @@ -676,7 +677,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a third argument which is not an ndarray-like object(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (n=ndarray)', function test( t ) { var values; var opts; var x; @@ -786,7 +787,7 @@ tape( 'the function throws an error if provided a third argument which is not an } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar)', function test( t ) { var values; var x; var y; @@ -823,7 +824,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar, options)', function test( t ) { var values; var x; var y; @@ -860,7 +861,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar, options, thisArg)', function test( t ) { var values; var x; var y; @@ -897,7 +898,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray)', function test( t ) { var values; var opts; var x; @@ -938,7 +939,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray, options)', function test( t ) { var values; var opts; var x; @@ -979,7 +980,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray, options, thisArg)', function test( t ) { var values; var opts; var x; @@ -1020,7 +1021,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=scalar)', function test( t ) { var values; var x; var y; @@ -1056,7 +1057,43 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=scalar, thisArg)', function test( t ) { + var values; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, 1, y, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (n=ndarray)', function test( t ) { var values; var opts; var x; @@ -1096,7 +1133,47 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options with invalid `dims` property(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=ndarray, thisArg)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dtype': 'int32' + }; + assign( x, scalar2ndarray( 1, opts ), y, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options with an invalid `dims` property (n=scalar)', function test( t ) { var values; var opts; var x; @@ -1135,7 +1212,7 @@ tape( 'the function throws an error if provided an options with invalid `dims` p } }); -tape( 'the function throws an error if provided an options with invalid `dims` property(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options with an invalid `dims` property (n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -1214,7 +1291,7 @@ tape( 'the function throws an error if provided a second argument which is not b } }); -tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the output array(options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the output array (options)', function test( t ) { var values; var opts; var x; @@ -1264,12 +1341,9 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, 2, y, clbk ); expected = true; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - // Reset output array y = empty( [], { 'dtype': 'bool' }); @@ -1277,8 +1351,6 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, 3, y, clbk ); expected = false; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1303,11 +1375,9 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, scalar2ndarray( 2, opts ), y, clbk ); expected = true; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - // Reset output array y = empty( [], { 'dtype': 'bool' }); @@ -1315,7 +1385,6 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, scalar2ndarray( 3, opts ), y, clbk ); expected = false; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1336,11 +1405,9 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, 2, y, clbk ); expected = true; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - // Reset output array y = empty( [], { 'dtype': 'bool' }); @@ -1348,7 +1415,6 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, 3, y, clbk ); expected = false; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1373,11 +1439,9 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, scalar2ndarray( 2, opts ), y, clbk ); expected = true; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - // Reset output array y = empty( [], { 'dtype': 'bool' }); @@ -1385,7 +1449,6 @@ tape( 'the function tests whether at least `n` elements along one or more ndarra actual = assign( x, scalar2ndarray( 3, opts ), y, clbk ); expected = false; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); @@ -1411,6 +1474,40 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=scala expected = [ true, false, true, false ]; t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + actual = assign( x, 1, y, opts, clbk ); + expected = [ true, false ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + y = empty( [], { + 'dtype': 'bool' + }); + actual = assign( x, 1, y, opts, clbk ); + expected = true; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [] + }; + y = empty( [ 2, 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, 1, y, opts, clbk ); + expected = [ [ true, false, true, false ], [ false, false, false, false ] ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); }); @@ -1424,12 +1521,13 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=ndarr x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, -5.0, 0.0, -7.0, 0.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); - opts1 = { - 'dims': [ 0 ] - }; opts2 = { 'dtype': 'int32' }; + + opts1 = { + 'dims': [ 0 ] + }; y = empty( [ 4 ], { 'dtype': 'bool' }); @@ -1437,6 +1535,40 @@ tape( 'the function supports specifying reduction dimensions (row-major, n=ndarr expected = [ true, false, true, false ]; t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 1 ] + }; + y = empty( [ 2 ], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk ); + expected = [ true, false ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0, 1 ] + }; + y = empty( [], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk ); + expected = true; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts1 = { + 'dims': [] + }; + y = empty( [ 2, 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, clbk ); + expected = [ [ true, false, true, false ], [ false, false, false, false ] ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); }); @@ -1449,6 +1581,18 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=sc x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); + opts = { + 'dims': [ 0 ] + }; + y = empty( [ 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, 2, y, opts, clbk ); + expected = [ false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + opts = { 'dims': [ 1 ] }; @@ -1460,6 +1604,31 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=sc t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + y = empty( [], { + 'dtype': 'bool' + }); + actual = assign( x, 2, y, opts, clbk ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [] + }; + y = empty( [ 2, 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, 2, y, opts, clbk ); + expected = [ [ false, false, false, false ], [ false, false, false, false ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); }); @@ -1473,12 +1642,25 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd x = new ndarray( 'float64', new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ), [ 2, 4 ], [ 1, 2 ], 0, 'column-major' ); - opts1 = { - 'dims': [ 1 ] - }; opts2 = { 'dtype': 'int32' }; + + opts1 = { + 'dims': [ 0 ] + }; + y = empty( [ 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 2, opts2 ), y, opts1, clbk ); + expected = [ false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 1 ] + }; y = empty( [ 2 ], { 'dtype': 'bool' }); @@ -1487,10 +1669,35 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts1 = { + 'dims': [ 0, 1 ] + }; + y = empty( [], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 2, opts2 ), y, opts1, clbk ); + expected = true; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts1 = { + 'dims': [] + }; + y = empty( [ 2, 4 ], { + 'dtype': 'bool' + }); + actual = assign( x, scalar2ndarray( 2, opts2 ), y, opts1, clbk ); + expected = [ [ false, false, false, false ], [ false, false, false, false ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.end(); }); -tape( 'the function supports providing a callback execution context(n=scalar)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=scalar)', function test( t ) { var expected; var indices; var values; @@ -1514,7 +1721,6 @@ tape( 'the function supports providing a callback execution context(n=scalar)', actual = assign( x, 1, y, predicate, ctx ); expected = true; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); @@ -1544,7 +1750,7 @@ tape( 'the function supports providing a callback execution context(n=scalar)', } }); -tape( 'the function supports providing a callback execution context(n=ndarray)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=ndarray)', function test( t ) { var expected; var indices; var values; @@ -1572,7 +1778,6 @@ tape( 'the function supports providing a callback execution context(n=ndarray)', actual = assign( x, scalar2ndarray( 1, opts ), y, predicate, ctx ); expected = true; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); @@ -1602,7 +1807,7 @@ tape( 'the function supports providing a callback execution context(n=ndarray)', } }); -tape( 'the function supports providing a callback execution context(n=scalar, options)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=scalar, options)', function test( t ) { var expected; var indices; var values; @@ -1630,7 +1835,6 @@ tape( 'the function supports providing a callback execution context(n=scalar, op actual = assign( x, 1, y, opts, predicate, ctx ); expected = [ false, true ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); @@ -1660,7 +1864,7 @@ tape( 'the function supports providing a callback execution context(n=scalar, op } }); -tape( 'the function supports providing a callback execution context(n=ndarray, options)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=ndarray, options)', function test( t ) { var expected; var indices; var values; @@ -1692,7 +1896,6 @@ tape( 'the function supports providing a callback execution context(n=ndarray, o actual = assign( x, scalar2ndarray( 1, opts2 ), y, opts1, predicate, ctx ); expected = [ false, true ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual, y, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js index 8268a15cacbd..a0e2c66fe972 100644 --- a/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/some-by/test/test.main.js @@ -36,8 +36,8 @@ var someBy = require( './../lib' ); * Callback function. * * @private -* @param {*} value - array element -* @returns {boolean} test result +* @param {*} value - input value +* @returns {boolean} result */ function clbk( value ) { return value > 0; @@ -52,7 +52,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=scalar)', function test( t ) { var values; var i; @@ -81,7 +81,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=scalar, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=scalar, thisArg)', function test( t ) { var values; var i; @@ -110,7 +110,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=ndarray)', function test( t ) { var values; var opts; var i; @@ -143,7 +143,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=ndarray, thisArg)', function test( t ) { var values; var opts; var i; @@ -234,7 +234,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=ndarray, options)', function test( t ) { var values; var opts; var i; @@ -267,7 +267,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray-like object(n=ndarray, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (n=ndarray, options, thisArg)', function test( t ) { var values; var opts; var i; @@ -311,6 +311,7 @@ tape( 'the function throws an error if provided a second argument which is not a values = [ '5', + 3.14, NaN, true, false, @@ -333,7 +334,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object (thisArg)', function test( t ) { var values; var x; var i; @@ -344,6 +345,7 @@ tape( 'the function throws an error if provided a second argument which is not a values = [ '5', + 3.14, NaN, true, false, @@ -366,7 +368,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object (options)', function test( t ) { var values; var x; var i; @@ -377,6 +379,7 @@ tape( 'the function throws an error if provided a second argument which is not a values = [ '5', + 3.14, NaN, true, false, @@ -399,7 +402,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object(options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an integer or ndarray-like object (options, thisArg)', function test( t ) { var values; var x; var i; @@ -410,6 +413,7 @@ tape( 'the function throws an error if provided a second argument which is not a values = [ '5', + 3.14, NaN, true, false, @@ -458,7 +462,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(thiArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type (thiArg)', function test( t ) { var values; var x; var i; @@ -484,7 +488,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type (options)', function test( t ) { var values; var x; var i; @@ -510,7 +514,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type(options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is an ndarray with a non-integer data type (options, thisArg)', function test( t ) { var values; var x; var i; @@ -536,7 +540,7 @@ tape( 'the function throws an error if provided a second argument which is an nd } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar)', function test( t ) { var values; var x; var i; @@ -569,7 +573,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar, thisArg)', function test( t ) { var values; var x; var i; @@ -602,7 +606,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar, options)', function test( t ) { var values; var x; var i; @@ -635,7 +639,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=scalar, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=scalar, options, thisArg)', function test( t ) { var values; var x; var i; @@ -668,7 +672,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray)', function test( t ) { var values; var opts; var x; @@ -705,7 +709,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray, thisArg)', function test( t ) { var values; var opts; var x; @@ -742,7 +746,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray, options)', function test( t ) { var values; var opts; var x; @@ -779,7 +783,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided a callback argument which is not a function(n=ndarray, options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (n=ndarray, options, thisArg)', function test( t ) { var values; var opts; var x; @@ -816,7 +820,7 @@ tape( 'the function throws an error if provided a callback argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=scalar)', function test( t ) { var values; var x; var i; @@ -848,7 +852,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=scalar, thisArg)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=scalar, thisArg)', function test( t ) { var values; var x; var i; @@ -865,7 +869,8 @@ tape( 'the function throws an error if provided an options argument which is not false, null, void 0, - [] + [], + function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -880,7 +885,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=ndarray)', function test( t ) { var values; var opts; var x; @@ -916,7 +921,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument which is not an object(n=ndarray, thisArg)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (n=ndarray, thisArg)', function test( t ) { var values; var opts; var x; @@ -934,7 +939,8 @@ tape( 'the function throws an error if provided an options argument which is not false, null, void 0, - [] + [], + function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -952,7 +958,7 @@ tape( 'the function throws an error if provided an options argument which is not } }); -tape( 'the function throws an error if provided an options argument with invalid `dims` property(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with an invalid `dims` property (n=scalar)', function test( t ) { var values; var opts; var x; @@ -964,6 +970,7 @@ tape( 'the function throws an error if provided an options argument with invalid values = [ '5', + 3.14, NaN, true, false, @@ -988,7 +995,7 @@ tape( 'the function throws an error if provided an options argument with invalid } }); -tape( 'the function throws an error if provided an options argument with invalid `dims` property(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with an invalid `dims` property (n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -1001,6 +1008,7 @@ tape( 'the function throws an error if provided an options argument with invalid values = [ '5', + 3.14, NaN, true, false, @@ -1028,7 +1036,7 @@ tape( 'the function throws an error if provided an options argument with invalid } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions (n=scalar)', function test( t ) { var values; var opts; var x; @@ -1059,7 +1067,7 @@ tape( 'the function throws an error if provided an options argument with a `dims } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions (n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -1094,7 +1102,7 @@ tape( 'the function throws an error if provided an options argument with a `dims } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions (n=scalar)', function test( t ) { var values; var opts; var x; @@ -1124,7 +1132,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains duplicate dimensions(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions (n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -1158,7 +1166,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains more dimensions than are present in the input ndarray (n=scalar)', function test( t ) { var values; var opts; var x; @@ -1189,7 +1197,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with `dims` property which contains more dimensions than are present in the input ndarray(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains more dimensions than are present in the input ndarray (n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -1224,7 +1232,7 @@ tape( 'the function throws an error if provided an options argument with `dims` } }); -tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n=scalar)', function test( t ) { +tape( 'the function throws an error if provided an options argument with an invalid `keepdims` property (n=scalar)', function test( t ) { var values; var opts; var x; @@ -1260,7 +1268,7 @@ tape( 'the function throws an error if provided an options argument with invalid } }); -tape( 'the function throws an error if provided an options argument with invalid `keepdims` property(n=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an options argument with an invalid `keepdims` property (n=ndarray)', function test( t ) { var values; var opts1; var opts2; @@ -1332,7 +1340,7 @@ tape( 'the function throws an error if provided a second argument which is not b } }); -tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array(thiArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array (thisArg)', function test( t ) { var values; var opts; var x; @@ -1364,7 +1372,7 @@ tape( 'the function throws an error if provided a second argument which is not b } }); -tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array(options)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array (options)', function test( t ) { var values; var opts; var x; @@ -1396,7 +1404,7 @@ tape( 'the function throws an error if provided a second argument which is not b } }); -tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array(options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the non-reduced dimensions of the input array (options, thisArg)', function test( t ) { var values; var opts; var x; @@ -1848,7 +1856,7 @@ tape( 'the function supports specifying reduction dimensions (column-major, n=nd t.end(); }); -tape( 'the function supports providing a callback execution context(n=scalar)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=scalar)', function test( t ) { var expected; var indices; var values; @@ -1897,7 +1905,7 @@ tape( 'the function supports providing a callback execution context(n=scalar)', } }); -tape( 'the function supports providing a callback execution context(n=ndarray)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=ndarray)', function test( t ) { var expected; var indices; var values; @@ -1950,7 +1958,7 @@ tape( 'the function supports providing a callback execution context(n=ndarray)', } }); -tape( 'the function supports providing a callback execution context(n=scalar, options)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=scalar, options)', function test( t ) { var expected; var indices; var values; @@ -2003,7 +2011,7 @@ tape( 'the function supports providing a callback execution context(n=scalar, op } }); -tape( 'the function supports providing a callback execution context(n=ndarray, options)', function test( t ) { +tape( 'the function supports providing a callback execution context (n=ndarray, options)', function test( t ) { var expected; var indices; var values;