From 83c77e56bf6df30f40c41282ba448df0d516e035 Mon Sep 17 00:00:00 2001 From: Uday Kakade Date: Fri, 13 Jun 2025 22:59:13 +0530 Subject: [PATCH 1/2] add assert/has-float16array-support --- .../assert/has-float16array-support/README.md | 123 +++++++++++++ .../benchmark/benchmark.js | 49 ++++++ .../assert/has-float16array-support/bin/cli | 60 +++++++ .../has-float16array-support/docs/repl.txt | 17 ++ .../docs/types/index.d.ts | 35 ++++ .../docs/types/test.ts | 33 ++++ .../has-float16array-support/docs/usage.txt | 8 + .../etc/cli_opts.json | 14 ++ .../examples/index.js | 28 +++ .../lib/float16array.js | 28 +++ .../has-float16array-support/lib/index.js | 40 +++++ .../has-float16array-support/lib/main.js | 65 +++++++ .../has-float16array-support/package.json | 74 ++++++++ .../has-float16array-support/test/test.cli.js | 162 ++++++++++++++++++ .../has-float16array-support/test/test.js | 134 +++++++++++++++ 15 files changed, 870 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/README.md create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/bin/cli create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/docs/usage.txt create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/etc/cli_opts.json create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/lib/float16array.js create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/package.json create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/test/test.cli.js create mode 100644 lib/node_modules/@stdlib/assert/has-float16array-support/test/test.js diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/README.md b/lib/node_modules/@stdlib/assert/has-float16array-support/README.md new file mode 100644 index 000000000000..59de7eb9710f --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/README.md @@ -0,0 +1,123 @@ + + +# Float16Array Support + +> Detect native [`Float16Array`][mdn-float16array] support. + +
+ +## Usage + +```javascript +var hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' ); +``` + +#### hasFloat16ArraySupport() + +Detects if a runtime environment supports [`Float16Array`][mdn-float16array]. + +```javascript +var bool = hasFloat16ArraySupport(); +// returns +``` + +
+ + + +
+ +## Examples + + + +```javascript +var hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' ); + +var bool = hasFloat16ArraySupport(); +if ( bool ) { + console.log( 'Environment has Float16Array support.' ); +} else { + console.log( 'Environment lacks Float16Array support.' ); +} +``` + +
+ + + +* * * + +
+ +## CLI + +
+ +### Usage + +```text +Usage: has-float32array-support [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. +``` + +
+ + + +
+ +### Examples + +```bash +$ has-float16array-support + +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-float16array-support/benchmark/benchmark.js new file mode 100644 index 000000000000..9808661f514b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/benchmark/benchmark.js @@ -0,0 +1,49 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var hasFloat16ArraySupport = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. + bool = hasFloat16ArraySupport(); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/bin/cli b/lib/node_modules/@stdlib/assert/has-float16array-support/bin/cli new file mode 100644 index 000000000000..8520ae55bf89 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/bin/cli @@ -0,0 +1,60 @@ +#!/usr/bin/env node + +/** +* @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 resolve = require( 'path' ).resolve; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var CLI = require( '@stdlib/cli/ctor' ); +var detect = require( './../lib' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var flags; + var cli; + + // Create a command-line interface: + cli = new CLI({ + 'pkg': require( './../package.json' ), + 'options': require( './../etc/cli_opts.json' ), + 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }) + }); + + // Get any provided command-line options: + flags = cli.flags(); + if ( flags.help || flags.version ) { + return; + } + + console.log( detect() ); // eslint-disable-line no-console +} + +main(); diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/repl.txt new file mode 100644 index 000000000000..f1a03da90e60 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/repl.txt @@ -0,0 +1,17 @@ + +{{alias}}() + Tests for native `Float16Array` support. + + Returns + ------- + bool: boolean + Boolean indicating if an environment has `Float16Array` support. + + Examples + -------- + > var bool = {{alias}}() + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/index.d.ts new file mode 100644 index 000000000000..144600c2139f --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/index.d.ts @@ -0,0 +1,35 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/** +* Tests for native `Float16Array` support. +* +* @returns boolean indicating if an environment has `Float16Array` support +* +* @example +* var bool = hasFloat16ArraySupport(); +* // returns +*/ +declare function hasFloat16ArraySupport(): boolean; + + +// EXPORTS // + +export = hasFloat16ArraySupport; diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/test.ts b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/test.ts new file mode 100644 index 000000000000..73e758e17015 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/types/test.ts @@ -0,0 +1,33 @@ +/* +* @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. +*/ + +import hasFloat16ArraySupport = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + hasFloat16ArraySupport(); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided arguments... +{ + hasFloat16ArraySupport( true ); // $ExpectError + hasFloat16ArraySupport( [], 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/docs/usage.txt b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/usage.txt new file mode 100644 index 000000000000..a982ba896460 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/docs/usage.txt @@ -0,0 +1,8 @@ + +Usage: has-float16array-support [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/etc/cli_opts.json b/lib/node_modules/@stdlib/assert/has-float16array-support/etc/cli_opts.json new file mode 100644 index 000000000000..f245a17e6317 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/etc/cli_opts.json @@ -0,0 +1,14 @@ +{ + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ] + } +} diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/examples/index.js b/lib/node_modules/@stdlib/assert/has-float16array-support/examples/index.js new file mode 100644 index 000000000000..b316e6ad9628 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/examples/index.js @@ -0,0 +1,28 @@ +/** +* @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'; + +var hasFloat16ArraySupport = require( './../lib' ); + +var bool = hasFloat16ArraySupport(); +if ( bool ) { + console.log( 'Environment has Float16Array support.' ); +} else { + console.log( 'Environment lacks Float16Array support.' ); +} diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/lib/float16array.js b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/float16array.js new file mode 100644 index 000000000000..3661839e7f33 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/float16array.js @@ -0,0 +1,28 @@ +/** +* @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'; + +// MAIN // + +var main = ( typeof Float16Array === 'function' ) ? Float16Array : null; // eslint-disable-line stdlib/require-globals + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js new file mode 100644 index 000000000000..5683c7d5c597 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js @@ -0,0 +1,40 @@ +/** +* @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'; + +/** +* Test for native `Float16Array` support. +* +* @module @stdlib/assert/has-float16array-support +* +* @example +* var hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' ); +* +* var bool = hasFloat16ArraySupport(); +* // returns +*/ + +// MODULES // + +var hasFloat16ArraySupport = require( './main.js' ); + + +// EXPORTS // + +module.exports = hasFloat16ArraySupport; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/lib/main.js b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/main.js new file mode 100644 index 000000000000..e5d7be81de05 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/main.js @@ -0,0 +1,65 @@ +/** +* @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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var GlobalFloat16Array = require( './float16array.js' ); + + +// MAIN // + +/** +* Tests for native `Float16Array` support. +* +* @returns {boolean} boolean indicating if an environment has `Float16Array` support +* +* @example +* var bool = hasFloat16ArraySupport(); +* // returns +*/ +function hasFloat16ArraySupport() { + var bool; + var arr; + + if ( typeof GlobalFloat16Array !== 'function' ) { + return false; + } + // Test basic support... + try { + arr = new GlobalFloat16Array( [ 1.0, 3.14, -3.14, 5.0e40 ] ); + bool = ( + isFloat16Array( arr ) && + arr[ 0 ] === 1.0 && + arr[ 1 ] !== 3.14 && + arr[ 2 ] !== -3.14 && + arr[ 3 ] === PINF + ); + } catch ( err ) { // eslint-disable-line no-unused-vars + bool = false; + } + return bool; +} + + +// EXPORTS // + +module.exports = hasFloat16ArraySupport; diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/package.json b/lib/node_modules/@stdlib/assert/has-float16array-support/package.json new file mode 100644 index 000000000000..d51f6a8c2485 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/assert/has-float16array-support", + "version": "0.0.0", + "description": "Detect native Float16Array support.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": { + "has-float16array-support": "./bin/cli" + }, + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "detect", + "feature", + "float16array", + "es2022", + "typed array", + "typed-array", + "support", + "has", + "native", + "issupported", + "cli" + ] +} diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/test/test.cli.js b/lib/node_modules/@stdlib/assert/has-float16array-support/test/test.cli.js new file mode 100644 index 000000000000..bbfbb40255b2 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/test/test.cli.js @@ -0,0 +1,162 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var exec = require( 'child_process' ).exec; +var tape = require( 'tape' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); +var EXEC_PATH = require( '@stdlib/process/exec-path' ); +var readFileSync = require( '@stdlib/fs/read-file' ).sync; + + +// VARIABLES // + +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); +var opts = { + 'skip': IS_BROWSER || IS_WINDOWS +}; + + +// FIXTURES // + +var PKG_VERSION = require( './../package.json' ).version; + + +// TESTS // + +tape( 'command-line interface', function test( t ) { + t.ok( true, __filename ); + t.end(); +}); + +tape( 'when invoked with a `--help` flag, the CLI prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '--help' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'prints expected help text' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-h` flag, the CLI prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '-h' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'prints expected help text' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `--version` flag, the CLI prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '--version' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'prints version to `stderr`' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-V` flag, the CLI prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '-V' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'prints version to `stderr`' ); + } + t.end(); + } +}); + +tape( 'the CLI prints either `true` or `false` to `stdout` indicating native `Float16Array` support', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + var out = stdout.toString(); + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( out === 'true\n' || out === 'false\n', true, 'prints either `true` or `false` to `stdout`' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/test/test.js b/lib/node_modules/@stdlib/assert/has-float16array-support/test/test.js new file mode 100644 index 000000000000..a149e1ef8642 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/test/test.js @@ -0,0 +1,134 @@ +/** +* @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 proxyquire = require('proxyquire'); +var Number = require('@stdlib/number/ctor'); +var detect = require('./../lib'); + + +// VARIABLES // + +var hasFloat16Array = (typeof Float16Array === 'function'); + +var opts = { + skip: !hasFloat16Array +}; + + +// TESTS // + +tape('main export is a function', function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof detect, 'function', 'main export is a function'); + t.end(); +}); + +tape('feature detection result is a boolean', function test(t) { + t.strictEqual(typeof detect(), 'boolean', 'detection result is a boolean'); + t.end(); +}); + +tape('if `Float16Array` is supported, detection result is `true`', opts, function test(t) { + t.strictEqual(detect(), true, 'detection result is `true`'); + + var mocked = proxyquire('./../lib/main.js', { + './float16array.js': Mock, + '@stdlib/assert/is-float16array': isArray + }); + t.strictEqual(mocked(), true, 'detection result is `true` (mocked)'); + + t.end(); + + function isArray() { + return true; + } + + function Mock() { + return [ + 1.0, + 0.333251953125, + -0.333251953125, + Number.POSITIVE_INFINITY + ]; + } +}); + +tape('if `Float16Array` is not supported, detection result is `false`', function test(t) { + if (hasFloat16Array) { + t.strictEqual(detect(), true, 'detection result is `true`'); + } else { + t.strictEqual(detect(), false, 'detection result is `false`'); + } + + var mocked = proxyquire('./../lib/main.js', { + './float16array.js': {} + }); + t.strictEqual(mocked(), false, 'detection result is `false`'); + + mocked = proxyquire('./../lib/main.js', { + './float16array.js': Mock1 + }); + t.strictEqual(mocked(), false, 'detection result is `false`'); + + mocked = proxyquire('./../lib/main.js', { + './float16array.js': Mock2, + '@stdlib/assert/is-float16array': isArray + }); + t.strictEqual(mocked(), false, 'detection result is `false`'); + + mocked = proxyquire('./../lib/main.js', { + './float16array.js': Mock3, + '@stdlib/assert/is-float16array': isArray + }); + t.strictEqual(mocked(), false, 'detection result is `false`'); + + mocked = proxyquire('./../lib/main.js', { + './float16array.js': Mock4 + }); + t.strictEqual(mocked(), false, 'detection result is `false`'); + + t.end(); + + function isArray() { + return true; + } + + function Mock1() { + // Not a typed array: + return []; + } + + function Mock2() { + // Does not lose precision... + return [1.0, 3.14, -3.14, Number.POSITIVE_INFINITY]; + } + + function Mock3() { + // Does not overflow... + return [1.0, 0.333251953125, -0.333251953125, 5.0e40]; + } + + function Mock4() { + throw new Error('beep'); + } +}); From a069b91f5b64ab1b982e2ca224be1b117659d36d Mon Sep 17 00:00:00 2001 From: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> Date: Fri, 13 Jun 2025 23:14:21 +0530 Subject: [PATCH 2/2] Removed extra line at the end of code in index.js Signed-off-by: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> --- .../@stdlib/assert/has-float16array-support/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js index 5683c7d5c597..528001f17292 100644 --- a/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js +++ b/lib/node_modules/@stdlib/assert/has-float16array-support/lib/index.js @@ -37,4 +37,4 @@ var hasFloat16ArraySupport = require( './main.js' ); // EXPORTS // -module.exports = hasFloat16ArraySupport; \ No newline at end of file +module.exports = hasFloat16ArraySupport;