From 91e18b435698319cb3a0b1ee490a136c3b7a3043 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 22 Dec 2025 15:17:28 +0500 Subject: [PATCH 1/4] test: add tests for complete test code 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/find/test/test.assign.js | 852 ++++++++++++++++++ .../@stdlib/ndarray/find/test/test.js | 6 +- .../@stdlib/ndarray/find/test/test.main.js | 804 +++++++++++++++++ 3 files changed, 1661 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/ndarray/find/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/find/test/test.main.js diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js new file mode 100644 index 000000000000..7dc8c9967c2b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js @@ -0,0 +1,852 @@ +/** +* @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 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' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var find = require( './../lib/assign.js' ); // eslint-disable-line stdlib/no-redeclare + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} value - input value +* @returns {boolean} result +*/ +function clbk( value ) { + return value > 0.0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, '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', function test( t ) { + var values; + var out; + var i; + + out = empty( [] ); + 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() { + find( value, out, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var out; + var i; + + out = empty( [] ); + 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() { + find( value, out, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = empty( [] ); + 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() { + find( x, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var x; + var i; + + x = empty( [] ); + 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() { + find( x, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + find( x, out, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + find( x, out, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + find( x, out, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + find( x, out, opts, clbk ); + }; + } +}); + +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', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + find( x, out, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + find( x, out, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + find( x, out, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + find( x, out, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + find( x, out, {}, value, {} ); + }; + } +}); + +tape( 'the function finds the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions and assigns results to a provided output ndarray (row-major)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + out = empty( [], { + 'dtype': 'float64' + }); + + actual = find( x, out, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + t.end(); +}); + +tape( 'the function finds the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions and assigns results to a provided output ndarray (column-major)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); + out = empty( [], { + 'dtype': 'float64' + }); + + actual = find( x, out, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major)', function test( t ) { + var expected; + var actual; + var opts; + var out; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts = { + 'dims': [ 0 ] + }; + out = empty( [ 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + out = empty( [ 2 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, 5.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + out = empty( [], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [] + }; + out = empty( [ 2, 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major)', function test( t ) { + var expected; + var actual; + var opts; + var out; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'column-major' ); + + opts = { + 'dims': [ 0 ] + }; + out = empty( [ 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + out = empty( [ 2 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, 5.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + out = empty( [], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [] + }; + out = empty( [ 2, 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the sentinel value (row-major)', function test( t ) { + var expected; + var actual; + var opts; + var out; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts = { + 'dims': [ 0 ], + 'sentinel': -999 + }; + out = empty( [ 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, -999, 3.0, -999 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'sentinel': -999 + }; + out = empty( [ 2 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, 5.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'sentinel': -999 + }; + out = empty( [], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [], + 'sentinel': -999 + }; + out = empty( [ 2, 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var out; + var ctx; + var x; + + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + out = empty( [], { + 'dtype': 'float64' + }); + + ctx = { + 'count': 0 + }; + + indices = []; + values = []; + arrays = []; + actual = find( x, out, predicate, ctx ); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, '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 an execution context (options)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var opts; + var out; + var ctx; + var x; + + x = new ndarray( 'float64', new Float64Array( [ -1.0, 2.0, -3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + out = empty( [ 2 ], { + 'dtype': 'float64' + }); + + ctx = { + 'count': 0 + }; + opts = { + 'dims': [ 0 ] + }; + indices = []; + values = []; + arrays = []; + actual = find( x, out, opts, predicate, ctx ); + expected = [ 2.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, '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; + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.js b/lib/node_modules/@stdlib/ndarray/find/test/test.js index 6bdf82f24c62..9e95c7c2b1ff 100644 --- a/lib/node_modules/@stdlib/ndarray/find/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); var find = require( './../lib' ); // eslint-disable-line stdlib/no-redeclare @@ -32,4 +33,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -// TODO: Add tests +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( find, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.main.js b/lib/node_modules/@stdlib/ndarray/find/test/test.main.js new file mode 100644 index 000000000000..4200fcb60082 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.main.js @@ -0,0 +1,804 @@ +/** +* @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 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' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var find = require( './../lib' ); // eslint-disable-line stdlib/no-redeclare + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} value - input value +* @returns {boolean} result +*/ +function clbk( value ) { + return value > 0.0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof find, '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', 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() { + find( value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (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() { + find( value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', 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() { + find( x, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `dims` property', 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) { + var values; + 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) { + var values; + 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +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', function test( t ) { + var values; + 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `keepdims` property', function test( t ) { + var values; + 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() { + var opts = { + 'keepdims': value + }; + find( x, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function', 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() { + find( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (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() { + find( x, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (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() { + find( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (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() { + find( x, {}, value, {} ); + }; + } +}); + +tape( 'the function returns a new ndarray containing the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions (row-major)', 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 = find( x, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a new ndarray containing the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions (column-major)', 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, 'column-major' ); + + actual = find( x, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major)', 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, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts = { + 'dims': [ 0 ] + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, 5.0 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ], [ 5.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + actual = find( x, opts, clbk ); + expected = 1.0; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [] + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major)', 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, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'column-major' ); + + opts = { + 'dims': [ 0 ] + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, 5.0 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ], [ 5.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + actual = find( x, opts, clbk ); + expected = 1.0; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [] + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the sentinel value (row-major)', 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, 5.0, -6.0, 7.0, -8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + opts = { + 'dims': [ 0 ], + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, -999, 3.0, -999 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ] + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, 5.0 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ], [ 5.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ] + }; + actual = find( x, opts, clbk ); + expected = 1.0; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [] + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [], + 'keepdims': true + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', 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' ); + + ctx = { + 'count': 0 + }; + + indices = []; + values = []; + arrays = []; + actual = find( x, predicate, ctx ); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), 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 ], + [ 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 an execution context (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 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + ctx = { + 'count': 0 + }; + opts = { + 'dims': [ 0 ] + }; + indices = []; + values = []; + arrays = []; + actual = find( x, opts, predicate, ctx ); + expected = [ 2.0, 4.0 ]; + + 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.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 6f1a565b42071969324327a87c96360aca19fab0 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 23 Dec 2025 14:12:47 +0500 Subject: [PATCH 2/4] fix: add missing option --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/find/test/test.assign.js | 72 ++++++++++++ .../@stdlib/ndarray/find/test/test.main.js | 108 ++++++++++++++++-- 2 files changed, 173 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js index 7dc8c9967c2b..4654a6eb630f 100644 --- a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js @@ -738,6 +738,78 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio t.end(); }); +tape( 'the function supports specifying the sentinel value (column-major)', function test( t ) { + var expected; + var actual; + var opts; + var out; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'column-major' ); + + opts = { + 'dims': [ 0 ], + 'sentinel': -999 + }; + out = empty( [ 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, -999, 3.0, -999 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'sentinel': -999 + }; + out = empty( [ 2 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ 1.0, 5.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'sentinel': -999 + }; + out = empty( [], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + opts = { + 'dims': [], + 'sentinel': -999 + }; + out = empty( [ 2, 4 ], { + 'dtype': 'float64' + }); + + actual = find( x, out, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( out, actual, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports providing an execution context', function test( t ) { var expected; var indices; diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.main.js b/lib/node_modules/@stdlib/ndarray/find/test/test.main.js index 4200fcb60082..709a7f00506f 100644 --- a/lib/node_modules/@stdlib/ndarray/find/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.main.js @@ -639,7 +639,8 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio opts = { 'dims': [ 0 ], - 'keepdims': true + 'keepdims': true, + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = [ [ 1.0, -999, 3.0, -999 ] ]; @@ -647,7 +648,8 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts = { - 'dims': [ 1 ] + 'dims': [ 1 ], + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = [ 1.0, 5.0 ]; @@ -656,7 +658,8 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio opts = { 'dims': [ 1 ], - 'keepdims': true + 'keepdims': true, + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = [ [ 1.0 ], [ 5.0 ] ]; @@ -664,7 +667,8 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts = { - 'dims': [ 0, 1 ] + 'dims': [ 0, 1 ], + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = 1.0; @@ -673,7 +677,8 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio opts = { 'dims': [ 0, 1 ], - 'keepdims': true + 'keepdims': true, + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = [ [ 1.0 ] ]; @@ -681,7 +686,8 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); opts = { - 'dims': [] + 'dims': [], + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; @@ -690,7 +696,95 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio opts = { 'dims': [], - 'keepdims': true + 'keepdims': true, + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the sentinel value (column-major)', 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, 5.0, -6.0, 7.0, -8.0 ] ), [ 2, 4 ], [ 4, 1 ], 0, 'column-major' ); + + opts = { + 'dims': [ 0 ], + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, -999, 3.0, -999 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0 ], + 'keepdims': true, + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ 1.0, 5.0 ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 1 ], + 'keepdims': true, + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ], [ 5.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = 1.0; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( actual.get(), expected, 'returns expected value' ); + + opts = { + 'dims': [ 0, 1 ], + 'keepdims': true, + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [], + 'sentinel': -999 + }; + actual = find( x, opts, clbk ); + expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + opts = { + 'dims': [], + 'keepdims': true, + 'sentinel': -999 }; actual = find( x, opts, clbk ); expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; From 9bf7bfbed7af154832b5f3c086333f96b58aa1b3 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 8 Jan 2026 23:16:03 -0800 Subject: [PATCH 3/4] chore: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/find/test/test.assign.js | 419 ++++++++++++------ .../@stdlib/ndarray/find/test/test.main.js | 241 +++++++--- 2 files changed, 468 insertions(+), 192 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js index 4654a6eb630f..03efd0e96746 100644 --- a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -21,12 +21,11 @@ // 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' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var find = require( './../lib/assign.js' ); // eslint-disable-line stdlib/no-redeclare +var assign = require( './../lib/assign.js' ); // FUNCTIONS // @@ -56,7 +55,10 @@ tape( 'the function throws an error if provided a first argument which is not an var out; var i; - out = empty( [] ); + out = empty( [], { + 'dtype': 'float64' + }); + values = [ '5', 5, @@ -77,7 +79,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - find( value, out, clbk ); + assign( value, out, clbk ); }; } }); @@ -87,7 +89,10 @@ tape( 'the function throws an error if provided a first argument which is not an var out; var i; - out = empty( [] ); + out = empty( [], { + 'dtype': 'float64' + }); + values = [ '5', 5, @@ -108,17 +113,20 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - find( value, out, {}, clbk ); + assign( value, out, {}, clbk ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (thisArg)', function test( t ) { var values; - var x; + var out; var i; - x = empty( [] ); + out = empty( [], { + 'dtype': 'float64' + }); + values = [ '5', 5, @@ -139,17 +147,20 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - find( x, value, clbk ); + assign( value, out, clbk, {} ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options, thisArg)', function test( t ) { var values; - var x; + var out; var i; - x = empty( [] ); + out = empty( [], { + 'dtype': 'float64' + }); + values = [ '5', 5, @@ -170,23 +181,54 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - find( x, value, {}, clbk ); + assign( value, out, {}, clbk, {} ); }; } }); -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { var values; - var out; var x; var i; x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - out = empty( [], { + + 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, value, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var x; + var i; + + x = empty( [ 2, 2 ], { 'dtype': 'float64' }); + values = [ '5', 5, @@ -195,7 +237,9 @@ 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++ ) { @@ -205,31 +249,64 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - find( x, out, value, clbk ); + assign( x, value, {}, clbk ); }; } }); -tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) { +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (thisArg)', function test( t ) { var values; - var out; var x; var i; x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - out = empty( [], { + + 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, value, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (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, {}, + [], function noop() {} ]; @@ -240,15 +317,12 @@ tape( 'the function throws an error if provided an options argument with an inva function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, out, opts, clbk ); + assign( x, value, {}, clbk, {} ); }; } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { var values; var out; var x; @@ -260,28 +334,32 @@ tape( 'the function throws an error if provided an options argument with a `dims out = empty( [], { 'dtype': 'float64' }); + values = [ - [ 1, 3 ], - [ 3, 0 ], - [ 0, 2 ] + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, out, opts, clbk ); + assign( x, out, value ); }; } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { var values; var out; var x; @@ -293,27 +371,32 @@ tape( 'the function throws an error if provided an options argument with a `dims out = empty( [], { 'dtype': 'float64' }); + values = [ - [ 0, 0 ], - [ 1, 1 ] + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, out, opts, clbk ); + assign( x, out, {}, value ); }; } }); -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', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { var values; var out; var x; @@ -325,28 +408,32 @@ tape( 'the function throws an error if provided an options argument with a `dims out = empty( [], { 'dtype': 'float64' }); + values = [ - [ 0, 1, 2 ], - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3, 4 ] + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, out, opts, clbk ); + assign( x, out, value, {} ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { var values; var out; var x; @@ -358,6 +445,7 @@ tape( 'the function throws an error if provided a callback argument which is not out = empty( [], { 'dtype': 'float64' }); + values = [ '5', 5, @@ -377,12 +465,12 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, out, value ); + assign( x, out, {}, value, {} ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { var values; var out; var x; @@ -394,6 +482,7 @@ tape( 'the function throws an error if provided a callback argument which is not out = empty( [], { 'dtype': 'float64' }); + values = [ '5', 5, @@ -402,7 +491,6 @@ tape( 'the function throws an error if provided a callback argument which is not false, null, void 0, - {}, [] ]; @@ -413,12 +501,12 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, out, {}, value ); + assign( x, out, value, clbk ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (thisArg)', function test( t ) { var values; var out; var x; @@ -430,6 +518,7 @@ tape( 'the function throws an error if provided a callback argument which is not out = empty( [], { 'dtype': 'float64' }); + values = [ '5', 5, @@ -438,7 +527,6 @@ tape( 'the function throws an error if provided a callback argument which is not false, null, void 0, - {}, [] ]; @@ -449,12 +537,12 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, out, value, {} ); + assign( x, out, value, clbk, {} ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) { var values; var out; var x; @@ -466,16 +554,16 @@ tape( 'the function throws an error if provided a callback argument which is not out = empty( [], { 'dtype': 'float64' }); + values = [ '5', - 5, NaN, true, false, null, void 0, {}, - [] + function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -485,7 +573,108 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, out, {}, value, {} ); + var opts = { + 'dims': value + }; + assign( x, out, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + assign( x, out, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + assign( x, out, opts, clbk ); + }; + } +}); + +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', function test( t ) { + var values; + var out; + var x; + var i; + + x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = empty( [], { + '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() { + var opts = { + 'dims': value + }; + assign( x, out, opts, clbk ); }; } }); @@ -501,12 +690,11 @@ tape( 'the function finds the first elements which pass a test implemented by a 'dtype': 'float64' }); - actual = find( x, out, clbk ); + actual = assign( x, out, clbk ); expected = 1.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.end(); }); @@ -521,12 +709,11 @@ tape( 'the function finds the first elements which pass a test implemented by a 'dtype': 'float64' }); - actual = find( x, out, clbk ); + actual = assign( x, out, clbk ); expected = 1.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.end(); }); @@ -546,12 +733,11 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, 2.0, 3.0, 4.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 1 ] @@ -560,12 +746,11 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, 5.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 0, 1 ] @@ -574,12 +759,11 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = 1.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [] @@ -588,12 +772,11 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.end(); }); @@ -614,12 +797,11 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, 2.0, 3.0, 4.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 1 ] @@ -628,12 +810,11 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, 5.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 0, 1 ] @@ -642,12 +823,11 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = 1.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [] @@ -656,12 +836,11 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.end(); }); @@ -683,12 +862,11 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, -999, 3.0, -999 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 1 ], @@ -698,12 +876,11 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, 5.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 0, 1 ], @@ -713,12 +890,11 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = 1.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [], @@ -728,12 +904,11 @@ tape( 'the function supports specifying the sentinel value (row-major)', functio 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.end(); }); @@ -755,12 +930,11 @@ tape( 'the function supports specifying the sentinel value (column-major)', func 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, -999, 3.0, -999 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 1 ], @@ -770,12 +944,11 @@ tape( 'the function supports specifying the sentinel value (column-major)', func 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ 1.0, 5.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [ 0, 1 ], @@ -785,12 +958,11 @@ tape( 'the function supports specifying the sentinel value (column-major)', func 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = 1.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); opts = { 'dims': [], @@ -800,12 +972,11 @@ tape( 'the function supports specifying the sentinel value (column-major)', func 'dtype': 'float64' }); - actual = find( x, out, opts, clbk ); + actual = assign( x, out, opts, clbk ); expected = [ [ 1.0, -999, 3.0, -999 ], [ 5.0, -999, 7.0, -999 ] ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.end(); }); @@ -832,12 +1003,11 @@ tape( 'the function supports providing an execution context', function test( t ) indices = []; values = []; arrays = []; - actual = find( x, out, predicate, ctx ); + actual = assign( x, out, predicate, ctx ); expected = 4.0; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); expected = [ -1.0, -2.0, -3.0, 4.0 ]; @@ -890,12 +1060,11 @@ tape( 'the function supports providing an execution context (options)', function indices = []; values = []; arrays = []; - actual = find( x, out, opts, predicate, ctx ); + actual = assign( x, out, opts, predicate, ctx ); expected = [ 2.0, 4.0 ]; - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - t.strictEqual( out, actual, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); expected = [ -1.0, 2.0, -3.0, 4.0 ]; diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.main.js b/lib/node_modules/@stdlib/ndarray/find/test/test.main.js index 709a7f00506f..93b24ec5493a 100644 --- a/lib/node_modules/@stdlib/ndarray/find/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -25,6 +25,7 @@ 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' ); +var isnan = require( '@stdlib/assert/is-nan' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var find = require( './../lib' ); // eslint-disable-line stdlib/no-redeclare @@ -109,15 +110,10 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (thisArg)', function test( t ) { var values; - var x; var i; - x = empty( [ 2, 2 ], { - 'dtype': 'float64' - }); - values = [ '5', 5, @@ -126,7 +122,9 @@ 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++ ) { @@ -136,28 +134,25 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - find( x, value, clbk ); + find( value, clbk, {} ); }; } }); -tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (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, {}, + [], function noop() {} ]; @@ -168,15 +163,12 @@ tape( 'the function throws an error if provided an options argument with an inva function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, opts, clbk ); + find( value, {}, clbk, {} ); }; } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { var values; var x; var i; @@ -186,27 +178,30 @@ tape( 'the function throws an error if provided an options argument with a `dims }); values = [ - [ 1, 3 ], - [ 3, 0 ], - [ 0, 2 ] + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, opts, clbk ); + find( x, value ); }; } }); -tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { var values; var x; var i; @@ -216,26 +211,30 @@ tape( 'the function throws an error if provided an options argument with a `dims }); values = [ - [ 0, 0 ], - [ 1, 1 ] + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, opts, clbk ); + find( x, {}, value ); }; } }); -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', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { var values; var x; var i; @@ -245,27 +244,30 @@ tape( 'the function throws an error if provided an options argument with a `dims }); values = [ - [ 0, 1, 2 ], - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3, 4 ] + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); } t.end(); function badValue( value ) { return function badValue() { - var opts = { - 'dims': value - }; - find( x, opts, clbk ); + find( x, value, {} ); }; } }); -tape( 'the function throws an error if provided an options argument with an invalid `keepdims` property', function test( t ) { +tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { var values; var x; var i; @@ -278,11 +280,12 @@ tape( 'the function throws an error if provided an options argument with an inva '5', 5, NaN, + true, + false, null, void 0, {}, - [], - function noop() {} + [] ]; for ( i = 0; i < values.length; i++ ) { @@ -292,15 +295,12 @@ tape( 'the function throws an error if provided an options argument with an inva function badValue( value ) { return function badValue() { - var opts = { - 'keepdims': value - }; - find( x, opts, clbk ); + find( x, {}, value, {} ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { var values; var x; var i; @@ -317,7 +317,6 @@ tape( 'the function throws an error if provided a callback argument which is not false, null, void 0, - {}, [] ]; @@ -328,12 +327,12 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, value ); + find( x, value, clbk ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { +tape( 'the function throws an error if provided an options argument which is not an object (thisArg)', function test( t ) { var values; var x; var i; @@ -350,7 +349,6 @@ tape( 'the function throws an error if provided a callback argument which is not false, null, void 0, - {}, [] ]; @@ -361,12 +359,12 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, {}, value ); + find( x, value, clbk, {} ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { +tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) { var values; var x; var i; @@ -377,14 +375,13 @@ tape( 'the function throws an error if provided a callback argument which is not values = [ '5', - 5, NaN, true, false, null, void 0, {}, - [] + function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -394,12 +391,104 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, value, {} ); + var opts = { + 'dims': value + }; + find( x, opts, clbk ); }; } }); -tape( 'the function throws an error if provided a callback argument which is not a function (options, thisArg)', function test( t ) { +tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) { + var values; + 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) { + var values; + 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +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', function test( t ) { + var values; + 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() { + var opts = { + 'dims': value + }; + find( x, opts, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `keepdims` property', function test( t ) { var values; var x; var i; @@ -412,12 +501,11 @@ tape( 'the function throws an error if provided a callback argument which is not '5', 5, NaN, - true, - false, null, void 0, {}, - [] + [], + function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -427,7 +515,10 @@ tape( 'the function throws an error if provided a callback argument which is not function badValue( value ) { return function badValue() { - find( x, {}, value, {} ); + var opts = { + 'keepdims': value + }; + find( x, opts, clbk ); }; } }); @@ -444,6 +535,14 @@ tape( 'the function returns a new ndarray containing the first elements which pa t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); + + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' ); + + actual = find( x, clbk ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isnan( actual.get() ), true, 'returns expected value' ); + t.end(); }); @@ -459,6 +558,14 @@ tape( 'the function returns a new ndarray containing the first elements which pa t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); + + x = new ndarray( 'float64', new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' ); + + actual = find( x, clbk ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isnan( actual.get() ), true, 'returns expected value' ); + t.end(); }); From 819ea78fd9468e878853c432e87da8422ab209da Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 8 Jan 2026 23:18:30 -0800 Subject: [PATCH 4/4] test: fix variable name --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/find/test/test.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js index 03efd0e96746..26f12b918c7c 100644 --- a/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/find/test/test.assign.js @@ -46,7 +46,7 @@ function clbk( value ) { tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof find, 'function', 'main export is a function' ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); t.end(); });