From 886fe30d62d214848582325a9b81d6ff613734f7 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Tue, 30 Dec 2025 11:34:34 +0530 Subject: [PATCH] test: add tests for @stdlib/math/tools/unary --- 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/math/tools/unary/test/test.js | 235 +++++++++++++++++- 1 file changed, 234 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/tools/unary/test/test.js b/lib/node_modules/@stdlib/math/tools/unary/test/test.js index 0204b77ec1b0..232270230d3c 100644 --- a/lib/node_modules/@stdlib/math/tools/unary/test/test.js +++ b/lib/node_modules/@stdlib/math/tools/unary/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var unary = require( '@stdlib/ndarray/base/unary' ); var factory = require( './../lib' ); @@ -32,4 +33,236 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -// FIXME: add tests +tape( 'the function throws an error if the first argument is not a function', function test( t ) { + var values; + var i; + + 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() { + factory( value, [ [ 'float64' ] ], [ 'float64' ], { + 'output': 'real_and_generic', + 'casting': 'none' + }); + }; + } +}); + +tape( 'the function throws an error if the second argument is not an array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + unary + ]; + + 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() { + factory( unary, value, [ 'float64' ], { + 'output': 'real_and_generic', + 'casting': 'none' + }); + }; + } +}); + +tape( 'the function throws an error if the second argument does not contain arrays of data types', function test( t ) { + var values; + var i; + + values = [ + [ [] ], + [ [ 'foo' ] ], + [ [ 1, 2, 3 ] ], + [ [ 'float64', 1 ] ], + [ 'float64' ] + ]; + + 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() { + factory( unary, value, [ 'float64' ], { + 'output': 'real_and_generic', + 'casting': 'none' + }); + }; + } +}); + +tape( 'the function throws an error if the third argument is not an array of data types', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + [ 'foo' ], + [ 1, 2, 3 ], + [ 'float64', 1 ], + unary + ]; + + 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() { + factory( unary, [ [ 'float64' ] ], value, { + 'output': 'real_and_generic', + 'casting': 'none' + }); + }; + } +}); + +tape( 'the function throws an error if the fourth argument is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + unary + ]; + + 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() { + factory( unary, [ [ 'float64' ] ], [ 'float64' ], value ); + }; + } +}); + +tape( 'the function throws an error if the fourth argument does not have a valid output data type policy', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + unary + ]; + + 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() { + factory( unary, [ [ 'float64' ] ], [ 'float64' ], { + 'output': value, + 'casting': 'none' + }); + }; + } +}); + +tape( 'the function throws an error if the fourth argument does not have a valid casting policy', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + unary + ]; + + 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() { + factory( unary, [ [ 'float64' ] ], [ 'float64' ], { + 'output': 'real_and_generic', + 'casting': value + }); + }; + } +}); + +tape( 'the function returns a function', function test( t ) { + var fcn = factory( unary, [ [ 'float64' ] ], [ 'float64' ], { + 'output': 'real_and_generic', + 'casting': 'none' + }); + t.strictEqual( typeof fcn, 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the returned function has an `assign` method', function test( t ) { + var fcn = factory( unary, [ [ 'float64' ] ], [ 'float64' ], { + 'output': 'real_and_generic', + 'casting': 'none' + }); + t.strictEqual( typeof fcn.assign, 'function', 'has an assign method' ); + t.end(); +});