diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index f756a5e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float16) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 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. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 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. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 44e2d76..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 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. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float16) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 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. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 4584730..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 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. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '9 21 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 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. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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 main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/polyfill/test.at.js b/test/polyfill/test.at.js deleted file mode 100644 index 2cd65c2..0000000 --- a/test/polyfill/test.at.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `at` method for returning an array element', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'at' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.at ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.at.call( value, 0 ); - }; - } -}); - -tape( 'the method throws an error if provided an index argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.at( value ); - }; - } -}); - -tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) { - var arr; - var v; - var i; - - arr = new Float16Array( 10 ); - for ( i = -arr.length; i < arr.length; i++ ) { - if ( i < 0 ) { - v = arr.at( i-arr.length ); - t.strictEqual( v, void 0, 'returns expected value for index '+(i-arr.length) ); - } else { - v = arr.at( arr.length+i ); - t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) ); - } - } - t.end(); -}); - -tape( 'the method returns an array element', function test( t ) { - var arr; - var v; - var i; - - arr = []; - for ( i = 0; i < 10; i++ ) { - arr.push( i+0.05 ); - } - - arr = new Float16Array( arr ); - - for ( i = -arr.length; i < arr.length; i++ ) { - v = arr.at( i ); - if ( i < 0 ) { - t.strictEqual( v, float64ToFloat16( arr.length + i + 0.05 ), 'returns expected value for index '+i ); - } else { - t.strictEqual( v, float64ToFloat16( i + 0.05 ), 'returns expected value for index '+i ); - } - } - t.end(); -}); diff --git a/test/polyfill/test.copy_within.js b/test/polyfill/test.copy_within.js deleted file mode 100644 index 0a8eb57..0000000 --- a/test/polyfill/test.copy_within.js +++ /dev/null @@ -1,281 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `copyWithin` method for copying a sequence of array elements within a floating-point number array', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'copyWithin' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.copyWithin.call( value, 3, 0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.copyWithin.call( value, 3, 0, 5 ); - }; - } -}); - -tape( 'the method copies a sequence of elements within an array', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 0, 3 ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( -arr.length, 3 ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 0, -2 ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 0, 3, arr.length ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 2, 0, 2 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - - // Overwritten: - t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 2, 0, -3 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - - // Overwritten: - t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( arr.length, 3 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 2, 0 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - - // Overwritten: - t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 2.05 ), 'returns expected value' ); - - t.end(); -}); diff --git a/test/polyfill/test.entries.js b/test/polyfill/test.entries.js deleted file mode 100644 index 4cea4d1..0000000 --- a/test/polyfill/test.entries.js +++ /dev/null @@ -1,238 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isNumber = require( '@stdlib/assert-is-number' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'entries' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.entries ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.entries.call( value ); - }; - } -}); - -tape( 'the method returns an iterator protocol-compliant object', function test( t ) { - var buf; - var arr; - var it; - var v; - var i; - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.entries(); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < arr.length; i++ ) { - v = it.next(); - t.strictEqual( isArray( v.value ), true, 'returns expected value' ); - t.strictEqual( v.value[ 0 ], i, 'returns expected value' ); - t.strictEqual( isNumber( v.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ i ] ), 'returns expected value' ); - t.strictEqual( typeof v.done, 'boolean', 'returns expected value' ); - } - t.end(); -}); - -tape( 'the method returns an iterator which has a `return` method for closing an iterator (no argument)', function test( t ) { - var buf; - var arr; - var it; - var v; - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.entries(); - - v = it.next(); - t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.return(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method returns an iterator which has a `return` method for closing an iterator (argument)', function test( t ) { - var buf; - var arr; - var it; - var v; - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.entries(); - - v = it.next(); - t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.return( 'finished' ); - t.strictEqual( v.value, 'finished', 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { - var Float16Array; - var arr; - var buf; - var it1; - var it2; - var v1; - var v2; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it1 = arr.entries(); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns expected value' ); - t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); - t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); - - for ( i = 0; i < arr.length; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.strictEqual( v1[ 0 ], v2[ 0 ], 'returns expected value' ); - t.strictEqual( v1[ 1 ], v2[ 1 ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { - var Float16Array; - var arr; - var buf; - var it; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/symbol-iterator': false - }); - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.entries(); - t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/polyfill/test.every.js b/test/polyfill/test.every.js deleted file mode 100644 index 384adc4..0000000 --- a/test/polyfill/test.every.js +++ /dev/null @@ -1,174 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'every' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.every ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.every.call( value, predicate ); - }; - } - - function predicate( v ) { - return v === 0.0; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.every( value ); - }; - } -}); - -tape( 'the method returns `true` if operating on an empty floating-point number array', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 0 ); - bool = arr.every( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns `true` if all elements pass a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - bool = arr.every( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 1.05 ); - } -}); - -tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 1.05, 0.05, 1.05 ] ); - bool = arr.every( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 1.05 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - bool = arr.every( predicate, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v === float64ToFloat16( 1.05 ); - } -}); diff --git a/test/polyfill/test.fill.js b/test/polyfill/test.fill.js deleted file mode 100644 index 197e33f..0000000 --- a/test/polyfill/test.fill.js +++ /dev/null @@ -1,305 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `fill` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'fill' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.fill ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.fill.call( value, 1.0 ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a floating-point number', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - values = [ - '5', - 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() { - return arr.fill( value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.fill( 1.0, value ); - }; - } -}); - -tape( 'the method throws an error if provided a third argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.fill( 1.0, 0, value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.fill( 1.05 ); - - t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.fill( 1.05 ); - - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'if called with one argument, the method sets each array element to the provided value', function test( t ) { - var arr; - var buf; - var i; - - arr = new Float16Array( 3 ); - arr.fill( 1.05 ); - - buf = new Uint16Array( arr.buffer ); - - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); - } - - t.end(); -}); - -tape( 'if called with two arguments, the method sets each array element to the provided value starting from a start index (inclusive)', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, 1 ); - - t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 1.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'if called with three arguments, the method sets each array element to the provided value starting from a start index (inclusive) until a specified end index (exclusive)', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, 0, 2 ); - - t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method supports negative indices', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, -3, -1 ); - - t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'if a provided start index resolves to a negative index, the method fills an array starting from the first element', function test( t ) { - var arr; - var buf; - var i; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, -10 ); - - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); - } - - t.end(); -}); - -tape( 'if a provided end index resolves to an index exceeding the last array element index, the method fills an array until the last element (inclusive)', function test( t ) { - var arr; - var buf; - var i; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, 1, 10 ); - - t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); - for ( i = 1; i < arr.length; i++ ) { - t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); - } - - t.end(); -}); - -tape( 'if a provided start index resolves to an index which is greater than or equal to a resolved end index, the method does not fill an array', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.0, 2, 1 ); - - t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 0.0 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); - - t.end(); -}); diff --git a/test/polyfill/test.filter.js b/test/polyfill/test.filter.js deleted file mode 100644 index c5be66b..0000000 --- a/test/polyfill/test.filter.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `filter` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'filter' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.filter ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.filter.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.filter( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.filter( predicate ); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method returns a new floating-point number array containing only those elements which satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 1.05, 2.05 ] ); - expected = new Uint16Array( [ toWord( 1.05 ), toWord( 1.05 ) ] ); - actual = arr.filter( predicate ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v === float64ToFloat16( 1.05 ) ); - } -}); - -tape( 'the method copies all elements to a new array if all elements satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.filter( predicate ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v > 1.0 ); - } -}); - -tape( 'the method returns an empty array if no elements satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.filter( predicate ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 1.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var expected; - var actual; - var arr; - var buf; - var ctx; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 1.05 ) - ]); - ctx = { - 'count': 0 - }; - actual = arr.filter( predicate, ctx ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v === float64ToFloat16( 1.05 ) ); - } -}); diff --git a/test/polyfill/test.find.js b/test/polyfill/test.find.js deleted file mode 100644 index 64dffd0..0000000 --- a/test/polyfill/test.find.js +++ /dev/null @@ -1,174 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `find` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'find' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.find ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.find.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.find( value ); - }; - } -}); - -tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.find( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the first element which passes a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - v = arr.find( predicate ); - - t.strictEqual( v, float64ToFloat16( -2.05 ), 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - v = arr.find( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var v; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - v = arr.find( predicate, ctx ); - - t.strictEqual( v, float64ToFloat16( 3.05 ), 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/polyfill/test.find_index.js b/test/polyfill/test.find_index.js deleted file mode 100644 index e1516da..0000000 --- a/test/polyfill/test.find_index.js +++ /dev/null @@ -1,173 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `findIndex` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'findIndex' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.findIndex ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.findIndex.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.findIndex( value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( 0 ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the index of the first element which passes a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, 1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0); - } -}); - -tape( 'the method returns `-1` if all elements fail a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var idx; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - idx = arr.findIndex( predicate, ctx ); - - t.strictEqual( idx, 2, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/polyfill/test.find_last.js b/test/polyfill/test.find_last.js deleted file mode 100644 index 091e5a7..0000000 --- a/test/polyfill/test.find_last.js +++ /dev/null @@ -1,174 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `findLast` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'findLast' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.findLast ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.findLast.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 0.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.findLast( value ); - }; - } -}); - -tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.findLast( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the last element which passes a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - v = arr.findLast( predicate ); - - t.strictEqual( v, float64ToFloat16( -4.05 ), 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - v = arr.findLast( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var v; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - v = arr.findLast( predicate, ctx ); - - t.strictEqual( v, float64ToFloat16( 5.05 ), 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/polyfill/test.find_last_index.js b/test/polyfill/test.find_last_index.js deleted file mode 100644 index 1b7b8df..0000000 --- a/test/polyfill/test.find_last_index.js +++ /dev/null @@ -1,173 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `findLastIndex` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'findLastIndex' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.findLastIndex ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.findLastIndex.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.findLastIndex( value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( 0 ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the index of the last element which passes a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, 3, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method returns `-1` if all elements fail a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var idx; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - idx = arr.findLastIndex( predicate, ctx ); - - t.strictEqual( idx, 4, 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/polyfill/test.for_each.js b/test/polyfill/test.for_each.js deleted file mode 100644 index 98e75c2..0000000 --- a/test/polyfill/test.for_each.js +++ /dev/null @@ -1,196 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `forEach` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'forEach' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.forEach ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.forEach.call( value, fcn ); - }; - } - - function fcn( v ) { - if ( !isNumber( v ) ) { - t.fail( 'should be a number' ); - } - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.forEach( value ); - }; - } -}); - -tape( 'the method should not invoke a provided callback function if operating on an empty floating-point array', function test( t ) { - var arr; - - arr = new Float16Array( 0 ); - arr.forEach( fcn ); - - t.end(); - - function fcn() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns `undefined`', function test( t ) { - var arr; - var out; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - out = arr.forEach( fcn ); - - t.strictEqual( out, void 0, 'returns expected value' ); - t.end(); - - function fcn( v ) { - if ( !isNumber( v ) ) { - t.fail( 'should be a number' ); - } - } -}); - -tape( 'the method invokes a provided function for each element in an array', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var arr; - - indices = []; - values = []; - arrays = []; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - arr.forEach( fcn ); - - expected = [ - float64ToFloat16( 1.05 ), - float64ToFloat16( 2.05 ), - float64ToFloat16( 3.05 ), - float64ToFloat16( 4.05 ) - ]; - - t.deepEqual( values, expected, 'returns expected value' ); - t.deepEqual( indices, [ 0, 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( arrays[ 0 ], arr, 'returns expected value' ); - t.strictEqual( arrays[ 1 ], arr, 'returns expected value' ); - t.strictEqual( arrays[ 2 ], arr, 'returns expected value' ); - t.strictEqual( arrays[ 3 ], arr, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - values.push( v ); - indices.push( i ); - arrays.push( arr ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - arr.forEach( fcn, ctx ); - - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn() { - this.count += 1; // eslint-disable-line no-invalid-this - } -}); diff --git a/test/polyfill/test.from.js b/test/polyfill/test.from.js deleted file mode 100644 index d9cfc1a..0000000 --- a/test/polyfill/test.from.js +++ /dev/null @@ -1,654 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 Uint16Array = require( '@stdlib/array-uint16' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `from` method for creating a 16-bit floating-point number array from an array-like object or an iterable', function test( t ) { - var arr; - - t.strictEqual( hasOwnProp( Float16Array, 'from' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.from ), true, 'has method' ); - - arr = Float16Array.from( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a constructor', 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() { - return Float16Array.from.call( value, [] ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array constructor', function test( t ) { - var values; - var i; - - values = [ - {}, - null, - 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() { - return Float16Array.from.call( value, [] ); - }; - } -}); - -tape( 'the method throws an error if not provided an iterable or array-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() { - return Float16Array.from( value ); - }; - } -}); - -tape( 'the method throws an error if not provided an iterable or array-like object (callback)', 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() { - return Float16Array.from( value, clbk ); - }; - } - - function clbk() { - return 1.0; - } -}); - -tape( 'the method throws an error if not provided an iterable or array-like object (callback, thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return Float16Array.from( value, clbk, {} ); - }; - } - - function clbk() { - return 1.0; - } -}); - -tape( 'the method throws an error if provided a second argument which 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() { - return Float16Array.from( [], value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not a function (thisArg)', 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() { - return Float16Array.from( [], value, {} ); - }; - } -}); - -tape( 'the method returns a floating-point number array', function test( t ) { - var arr; - var v; - - // Generic array: - arr = Float16Array.from( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Generic array containing non-numeric values: - arr = Float16Array.from( [ 'beep' ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Float16Array.from( [ null, 4 ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - arr = Float16Array.from( [ true, {}, '' ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 3, 'returns expected value' ); - - // Typed array: - arr = Float16Array.from( new Uint16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Floating-point number typed array: - arr = Float16Array.from( new Float16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Float16Array( [ 1.0, 2.0 ] ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method returns a floating-point number array (iterable)', function test( t ) { - var Float16Array; - var iter; - var arr; - var v; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter = { - 'next': next, - 'i': 0, - 'N': 4 - }; - arr = Float16Array.from( createIterable( iter ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, iter.N, 'returns expected value' ); - - t.end(); - - function hasSupport() { - return true; - } - - function createIterable( iterator ) { - var it = {}; - it[ '__SYMBOL_ITERATOR__' ] = iterable; - return it; - - function iterable() { - return iterator; - } - } - - function next() { - iter.i += 1; - if ( iter.i <= iter.N ) { - return { - 'value': 1.0 - }; - } - return { - 'done': true - }; - } -}); - -tape( 'the method supports providing a "map" function which is invoked for each source element', function test( t ) { - var arr; - var v; - - // Generic array: - arr = Float16Array.from( [], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Generic array containing non-numeric values: - arr = Float16Array.from( [ 'beep' ], clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Float16Array.from( [ null ], clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Float16Array.from( [ [], {} ], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - arr = Float16Array.from( [ 4, 5 ], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Typed array: - arr = Float16Array.from( new Uint16Array( 0 ), clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ), clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Floating-point number typed array: - arr = Float16Array.from( new Float16Array( 0 ), clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Float16Array( [ true, true ] ), clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); - - function clbk1( v ) { - return v; - } - - function clbk2() { - return true; - } -}); - -tape( 'the method supports providing a "map" function which is invoked for each iterated value', function test( t ) { - var Float16Array; - var iter; - var arr; - var v; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter = { - 'next': next, - 'i': 0, - 'N': 4 - }; - arr = Float16Array.from( createIterable( iter ), clbk ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, iter.N, 'returns expected value' ); - - t.end(); - - function hasSupport() { - return true; - } - - function createIterable( iterator ) { - var it = {}; - it[ '__SYMBOL_ITERATOR__' ] = iterable; - return it; - - function iterable() { - return iterator; - } - } - - function next() { - iter.i += 1; - if ( iter.i <= iter.N ) { - return { - 'value': 1.0 - }; - } - return { - 'done': true - }; - } - - function clbk( v ) { - return !v; - } -}); - -tape( 'the method supports providing a `this` context for a provided map function', function test( t ) { - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1, ctx ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function clbk1( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v; - } -}); - -tape( 'the method supports providing a `this` context for a provided map function (iterable)', function test( t ) { - var Float16Array; - var iter; - var ctx; - var arr; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter = { - 'next': next, - 'i': 0, - 'N': 4 - }; - ctx = { - 'count': 0 - }; - - arr = Float16Array.from( createIterable( iter ), clbk, ctx ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function hasSupport() { - return true; - } - - function createIterable( iterator ) { - var it = {}; - it[ '__SYMBOL_ITERATOR__' ] = iterable; - return it; - - function iterable() { - return iterator; - } - } - - function next() { - iter.i += 1; - if ( iter.i <= iter.N ) { - return { - 'value': 1.0 - }; - } - return { - 'done': true - }; - } - - function clbk( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v; - } -}); - -tape( 'the method throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { - var Float16Array; - var values; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - {}, - { - '0': 1, - '1': 2, - '2': 3 - } - ]; - 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() { - return Float16Array.from( value ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the method throws an error if provided a non-iterable object (ES2015+)', function test( t ) { - var Float16Array; - var values; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - {}, - { - '0': 1, - '1': 2, - '2': 3 - }, - { - '__SYMBOL_ITERATOR__': null - }, - { - '__SYMBOL_ITERATOR__': 'beep' - }, - { - '__SYMBOL_ITERATOR__': nonIterable1 - }, - { - '__SYMBOL_ITERATOR__': nonIterable2 - } - ]; - 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() { - return Float16Array.from( value ); - }; - } - - function hasSupport() { - return true; - } - - function nonIterable1() { - return null; - } - - function nonIterable2() { - return {}; - } -}); diff --git a/test/polyfill/test.includes.js b/test/polyfill/test.includes.js deleted file mode 100644 index 8bb9850..0000000 --- a/test/polyfill/test.includes.js +++ /dev/null @@ -1,222 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `includes` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'includes' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.includes ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.includes.call( value, true ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a numeric value', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - values = [ - '5', - 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() { - return arr.includes( value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.includes( true, value ); - }; - } -}); - -tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 0 ); - bool = arr.includes( 1.0 ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `false` if a floating-point number is not found', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 10 ); - bool = arr.includes( 1.0 ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `true` if an array contains a specified floating-point number', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05] ); - bool = arr.includes( float64ToFloat16( 1.05 ) ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `false` if provided a second argument which exceeds the input array length', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 10 ); - bool = arr.includes( 0.0, 20 ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); - - bool = arr.includes( float64ToFloat16( 1.05 ), 0 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), 1 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), 3 ); - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index (negative)', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); - - bool = arr.includes( float64ToFloat16( 1.05 ), -5 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), -2 ); - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); - - bool = arr.includes( float64ToFloat16( 1.05 ), -10 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), -10 ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.index_of.js b/test/polyfill/test.index_of.js deleted file mode 100644 index b432c6d..0000000 --- a/test/polyfill/test.index_of.js +++ /dev/null @@ -1,222 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `indexOf` method for returning the index of an array element', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'indexOf' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.indexOf ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.indexOf.call( value, 1.0 ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a numeric value', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - values = [ - '5', - 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() { - return arr.indexOf( value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.indexOf( 1.0, value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array(); - idx = arr.indexOf( 1.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( 10 ); - idx = arr.indexOf( 1.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns the index of the first match if a numeric value is found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - idx = arr.indexOf( float64ToFloat16( 2.05 ) ); - - t.strictEqual( idx, 1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if provided a second argument which exceeds the input array length', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( 10 ); - idx = arr.indexOf( 1.0, 20 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), 0 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), 2 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), 4 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index (negative)', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), -5 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), -1 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), -10 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 1.05 ), -10 ); - t.strictEqual( idx, 0, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.join.js b/test/polyfill/test.join.js deleted file mode 100644 index 007f1cb..0000000 --- a/test/polyfill/test.join.js +++ /dev/null @@ -1,173 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `join` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'join' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.join ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.join.call( value ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `separator` argument which is not a string', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.join( value ); - }; - } -}); - -tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { - var str; - var arr; - - arr = new Float16Array( 0 ); - str = arr.join(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator', function test( t ) { - var expected; - var str; - var arr; - var i; - - arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); - - expected = float64ToFloat16( 0.05 ); - for ( i = 1; i < arr.length; i++ ) { - expected += '@' + float64ToFloat16( i + 0.05 ); - } - - str = arr.join( '@' ); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator (single element)', function test( t ) { - var expected; - var str; - var arr; - - arr = new Float16Array( [ 1.05 ] ); - expected = '' + float64ToFloat16( 1.05 ); - - str = arr.join(); - - t.strictEqual( str, expected, 'returns expected value' ); - - arr = new Float16Array( [ 1.05 ] ); - expected = '' + float64ToFloat16( 1.05 ); - - str = arr.join( '@' ); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if the method is invoked without a separator argument, the method returns a string representation of a floating-point number array with elements separated by a comma', function test( t ) { - var expected; - var str; - var arr; - var i; - - arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); - - expected = float64ToFloat16( 0.05 ); - for ( i = 1; i < arr.length; i++ ) { - expected += ',' + float64ToFloat16( i + 0.05 ); - } - - str = arr.join(); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.js b/test/polyfill/test.js deleted file mode 100644 index 6e254ad..0000000 --- a/test/polyfill/test.js +++ /dev/null @@ -1,740 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var arr = new Float16Array( 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (no argument)', function test( t ) { - var arr = new Float16Array(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (no argument, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (length)', function test( t ) { - var arr = new Float16Array( 10 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (length, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( 10 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (array)', function test( t ) { - var arr = new Float16Array( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (array, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (typed array)', function test( t ) { - var arr = new Float16Array( new Uint16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (typed array, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( new Uint16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (iterable)', function test( t ) { - var Float16Array; - var arr; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - arr = new Float16Array( createIterable() ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); - - function hasSupport() { - return true; - } - - function createIterable() { - var it = {}; - it[ '__SYMBOL_ITERATOR__' ] = iterable; - return it; - - function iterable() { - return { - 'next': next - }; - } - - function next() { - return { - 'done': true - }; - } - } -}); - -tape( 'the constructor returns a 16-bit floating-point number array (iterable, no new)', function test( t ) { - var ctor; - var arr; - - ctor = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - arr = ctor( createIterable() ); - t.strictEqual( arr instanceof ctor, true, 'returns expected value' ); - - t.end(); - - function hasSupport() { - return true; - } - - function createIterable() { - var it = {}; - it[ '__SYMBOL_ITERATOR__' ] = iterable; - return it; - - function iterable() { - return { - 'next': next - }; - } - - function next() { - return { - 'done': true - }; - } - } -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer)', function test( t ) { - var arr = new Float16Array( new ArrayBuffer( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( new ArrayBuffer( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset)', function test( t ) { - var arr = new Float16Array( new ArrayBuffer( 8 ), 8 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( new ArrayBuffer( 8 ), 8 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, length)', function test( t ) { - var arr = new Float16Array( new ArrayBuffer( 8 ), 8, 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, length, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Float16Array; - - arr = ctor( new ArrayBuffer( 8 ), 8, 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( Float16Array.BYTES_PER_ELEMENT, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array, 'name' ), true, 'has property' ); - t.strictEqual( Float16Array.name, 'Float16Array', 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns an instance having a `BYTES_PER_ELEMENT` property returning the number of bytes per array element', function test( t ) { - var arr; - - t.strictEqual( hasOwnProp( Float16Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( Float16Array.prototype.BYTES_PER_ELEMENT, 2, 'returns expected value' ); - - arr = new Float16Array( 0 ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `buffer` property for returning the underlying memory (i.e., ArrayBuffer)', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 0 ); - buf = arr.buffer; - t.strictEqual( isArrayBuffer( buf ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns an instance having a `byteLength` property for returning the number of bytes belonging to the array view', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.byteLength; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 8 ); - v = arr.byteLength; - t.strictEqual( v, 56, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); - v = arr.byteLength; - t.strictEqual( v, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `byteOffset` property for returning the byte offset pointing to the first array element in the underlying memory', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.byteOffset; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); - v = arr.byteOffset; - t.strictEqual( v, 32, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); - v = arr.byteOffset; - t.strictEqual( v, 64, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `length` property for returning the number of array elements', function test( t ) { - var arr; - var v; - - // No arguments: - arr = new Float16Array(); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - // Explicit array length: - arr = new Float16Array( 0 ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( 10 ); - v = arr.length; - t.strictEqual( v, 10, 'returns expected value' ); - - // Generic array: - arr = new Float16Array( [] ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Typed array: - arr = new Float16Array( new Uint16Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new Uint16Array( [ 1.0, 1.0 ] ) ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Float16 typed array: - arr = new Float16Array( new Float16Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new Float16Array( [ 1.0, 2.0 ] ) ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // ArrayBuffer: - arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); - v = arr.length; - t.strictEqual( v, 16, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 32, 2 ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `length` property for returning the number of array elements (iterable)', function test( t ) { - var Float16Array; - var iter; - var arr; - var v; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter = { - 'next': next, - 'i': 0, - 'N': 4 - }; - arr = new Float16Array( createIterable( iter ) ); - v = arr.length; - t.strictEqual( v, iter.N, 'returns expected value' ); - - t.end(); - - function hasSupport() { - return true; - } - - function createIterable( iterator ) { - var it = {}; - it[ '__SYMBOL_ITERATOR__' ] = iterable; - return it; - - function iterable() { - return iterator; - } - } - - function next() { - iter.i += 1; - if ( iter.i <= iter.N ) { - return { - 'value': 1.0 - }; - } - return { - 'done': true - }; - } -}); - -tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 2', function test( t ) { - var values; - var i; - - values = [ - 1, - 3, - 5, - 7, - 9, - 11, - 101, - 1001 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an ArrayBuffer having a byte length equal to '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return new Float16Array( new ArrayBuffer( value ) ); - }; - } -}); - -tape( 'the constructor throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { - var Float16Array; - var values; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - {}, - { - '0': 1, - '1': 2, - '2': 3 - } - ]; - 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() { - return new Float16Array( value ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the constructor throws an error if provided a non-iterable object (ES2015+)', function test( t ) { - var Float16Array; - var values; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - {}, - { - '0': 1, - '1': 2, - '2': 3 - }, - { - '__SYMBOL_ITERATOR__': null - }, - { - '__SYMBOL_ITERATOR__': 'beep' - }, - { - '__SYMBOL_ITERATOR__': nonIterable1 - }, - { - '__SYMBOL_ITERATOR__': nonIterable2 - } - ]; - 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() { - return new Float16Array( value ); - }; - } - - function hasSupport() { - return true; - } - - function nonIterable1() { - return null; - } - - function nonIterable2() { - return {}; - } -}); - -tape( 'the constructor throws an error if not provided a length, iterable, array-like object, or ArrayBuffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - -1, - 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() { - return new Float16Array( value ); - }; - } -}); - -tape( 'the constructor throws an error if provided more than one argument and the first argument is not an ArrayBuffer', 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() { - return new Float16Array( value, 0 ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - 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() { - return new Float16Array( new ArrayBuffer( 64 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 2', function test( t ) { - var values; - var i; - - values = [ - 1, - 3, - 5, - 7, - 9, - 11, - 101, - 1001 - ]; - 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() { - return new Float16Array( new ArrayBuffer( 1e3 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 8', function test( t ) { - var values; - var i; - - values = [ - 2, - 4, - 6, - 8, - 10, - 12, - 14, - 16, - 18, - 20 - ]; - 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() { - return new Float16Array( new ArrayBuffer( 101 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a length argument which is not a nonnegative integer (ArrayBuffer)', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - 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() { - return new Float16Array( new ArrayBuffer( 64 ), 0, value ); - }; - } -}); - -tape( 'the constructor throws an error if provided insufficient memory to accommodate byte offset and length arguments', function test( t ) { - var values; - var i; - - values = [ - 8, - 16, - 24, - 32 - ]; - 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() { - return new Float16Array( new ArrayBuffer( 100 ), value, 1e3 ); - }; - } -}); diff --git a/test/polyfill/test.keys.js b/test/polyfill/test.keys.js deleted file mode 100644 index 59c6210..0000000 --- a/test/polyfill/test.keys.js +++ /dev/null @@ -1,261 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `keys` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'keys' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.keys ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.keys.call( value ); - }; - } -}); - -tape( 'the method returns an iterator protocol-compliant object', function test( t ) { - var expected; - var arr; - var it; - var i; - var r; - var e; - - arr = new Float16Array( [ 1.05, 2.05 ] ); - expected = [ - { - 'value': 0, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - it = arr.keys(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - - t.end(); -}); - -tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var arr; - var it; - var i; - var v; - - arr = new Float16Array( [] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - it = arr.keys(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - v = it.next(); - t.deepEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var arr; - var it; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - it = arr.keys(); - - v = it.next(); - t.strictEqual( v.value, 0, 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, 1, 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.return(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var arr; - var it; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - it = arr.keys(); - - v = it.next(); - t.strictEqual( v.value, 0, 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, 1, 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.return( 'beep' ); - t.strictEqual( v.value, 'beep', 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { - var Float16Array; - var arr; - var buf; - var it1; - var it2; - var v1; - var v2; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it1 = arr.keys(); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns expected value' ); - t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); - t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); - - for ( i = 0; i < arr.length; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.strictEqual( v1, v2, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { - var Float16Array; - var arr; - var buf; - var it; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/symbol-iterator': false - }); - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.keys(); - t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/polyfill/test.last_index_of.js b/test/polyfill/test.last_index_of.js deleted file mode 100644 index 6a2fe99..0000000 --- a/test/polyfill/test.last_index_of.js +++ /dev/null @@ -1,211 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `lastIndexOf` method for returning the index of an array element', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'lastIndexOf' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.lastIndexOf ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.lastIndexOf.call( value, true ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a numeric value', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - values = [ - '5', - 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() { - return arr.lastIndexOf( value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.lastIndexOf( true, value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( 0 ); - idx = arr.lastIndexOf( 0.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( 10 ); - idx = arr.lastIndexOf( 1.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns the index of the first match when searching from the end of the array if a search element is found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 2.05 ] ); - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ) ); - - t.strictEqual( idx, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); - - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 4 ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 2 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 0 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index (negative)', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); - - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), -3 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), -1 ); - t.strictEqual( idx, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); - - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 10 ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 10 ); - t.strictEqual( idx, 2, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.map.js b/test/polyfill/test.map.js deleted file mode 100644 index 233d1d8..0000000 --- a/test/polyfill/test.map.js +++ /dev/null @@ -1,178 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var identity = require( '@stdlib/utils-identity-function' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `map` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'map' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.map ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.map.call( value, identity ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.map( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.map( identity ); - - t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.end(); -}); - -tape( 'the method returns a new floating-point number array containing elements which are the result of a provided callback function', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( -1.05 ), - toWord( -2.05 ), - toWord( -3.05 ), - toWord( -4.05 ) - ]); - actual = arr.map( invert ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function invert( v ) { - return -v; - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var expected; - var actual; - var arr; - var buf; - var ctx; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( -1.05 ), - toWord( -2.05 ), - toWord( -3.05 ), - toWord( -4.05 ) - ]); - ctx = { - 'count': 0 - }; - actual = arr.map( invert, ctx ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.strictEqual( ctx.count, 6, 'returns expected value' ); - t.end(); - - function invert( v, i ) { - this.count += i; // eslint-disable-line no-invalid-this - return -v; - } -}); diff --git a/test/polyfill/test.of.js b/test/polyfill/test.of.js deleted file mode 100644 index 5031bb5..0000000 --- a/test/polyfill/test.of.js +++ /dev/null @@ -1,130 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `of` method for creating a 16-bit floating-point number array from a variable number of arguments', function test( t ) { - var arr; - - t.strictEqual( hasOwnProp( Float16Array, 'of' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.of ), true, 'has method' ); - - arr = Float16Array.of(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a constructor', 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() { - return Float16Array.of.call( value, true, true ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point array constructor', function test( t ) { - var values; - var i; - - values = [ - {}, - null, - 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() { - return Float16Array.of.call( value, true, true ); - }; - } -}); - -tape( 'the method returns a floating-point number array', function test( t ) { - var arr; - var v; - - // No arguments: - arr = Float16Array.of(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - // Numeric arguments: - arr = Float16Array.of( 1.0, 2.0, 3.0, 4.0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Non-numeric arguments: - arr = Float16Array.of( 1, {}, 0, null, 'beep' ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 5, 'returns expected value' ); - - // Mixed arguments: - arr = Float16Array.of( true, 1, false, 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - t.end(); -}); diff --git a/test/polyfill/test.reduce.js b/test/polyfill/test.reduce.js deleted file mode 100644 index 7d9cbc0..0000000 --- a/test/polyfill/test.reduce.js +++ /dev/null @@ -1,189 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `reduce` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'reduce' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.reduce ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.reduce.call( value, reducer ); - }; - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.reduce( value ); - }; - } -}); - -tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { - var arr; - - arr = new Float16Array( 0 ); - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - arr.reduce( reducer ); - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method uses the first element of the array as the initial value when an initial value is not provided', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - var ind; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - accArray = [ 1.0, 3.0 ]; - valueArray = [ 2.0, 3.0 ]; - expected = float64ToFloat16( 6.0 ); - actual = arr.reduce( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); - - function reducer( acc, value, index ) { - ind = index-1; - t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method supports providing an initial value as the second argument', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - accArray = [ 2.0, 3.0, 5.0 ]; - valueArray = [ 1.0, 2.0, 3.0 ]; - expected = 8.0; - actual = arr.reduce( reducer, 2.0 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value, index ) { - t.strictEqual( acc, float64ToFloat16( accArray[ index ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ index ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method returns the accumulated result', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = float64ToFloat16( 10.20 ); - actual = arr.reduce( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); diff --git a/test/polyfill/test.reduce_right.js b/test/polyfill/test.reduce_right.js deleted file mode 100644 index 0d27e43..0000000 --- a/test/polyfill/test.reduce_right.js +++ /dev/null @@ -1,192 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `reduceRight` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'reduceRight' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.reduceRight ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.reduceRight.call( value, reducer ); - }; - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.reduceRight( value ); - }; - } -}); - -tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { - var arr; - - arr = new Float16Array( 0 ); - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - arr.reduceRight( reducer ); - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method uses the last element of the array as the initial value when an initial value is not provided', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - var len; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - len = arr.length; - accArray = [ 3.0, 5.0 ]; - valueArray = [ 2.0, 1.0 ]; - expected = float64ToFloat16( 6.0 ); - actual = arr.reduceRight( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value, index ) { - var ind = (len-index-2); - t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method supports providing an initial value as the second argument', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - var len; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - len = arr.length; - accArray = [ 2.0, 5.0, 7.0 ]; - valueArray = [ 3.0, 2.0, 1.0 ]; - expected = 8.0; - actual = arr.reduceRight( reducer, 2.0 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value, index ) { - var ind = (len-index-1); - t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method returns the accumulated result', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = float64ToFloat16( 10.20 ); - actual = arr.reduceRight( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); diff --git a/test/polyfill/test.reverse.js b/test/polyfill/test.reverse.js deleted file mode 100644 index 080a4c3..0000000 --- a/test/polyfill/test.reverse.js +++ /dev/null @@ -1,122 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `reverse` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'reverse' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.reverse ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.reverse.call( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.reverse(); - - t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method reverses elements of a floating-point number array in-place', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); - expected = new Uint16Array([ - toWord( 5.05 ), - toWord( 4.05 ), - toWord( 3.05 ), - toWord( 2.05 ), - toWord( 1.05 ) - ]); - out = arr.reverse(); - buf = new Uint16Array( arr.buffer ); - - t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.reverse(); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.set.js b/test/polyfill/test.set.js deleted file mode 100644 index d5e0ebb..0000000 --- a/test/polyfill/test.set.js +++ /dev/null @@ -1,259 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `set` method for setting one or more array elements', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.set ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.set.call( value, 0 ); - }; - } -}); - -tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - -5, - 3.14, - 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() { - return arr.set( [ 1.0 ], value ); - }; - } -}); - -tape( 'the method throws an error if provided an index argument which is out-of-bounds', function test( t ) { - var values; - var arr1; - var arr2; - var i; - - arr1 = new Float16Array( 10 ); - arr2 = []; - for ( i = 0; i < arr1.length; i++ ) { - arr2.push( 1.0 ); - } - - values = [ - 1, - 2, - 3, - 4, - 5 - ]; - 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() { - return arr1.set( arr2, value ); - }; - } -}); - -tape( 'the method sets one or more array elements', function test( t ) { - var arr; - var v; - var i; - - arr = new Float16Array( 10 ); - - v = arr[ 0 ]; - t.strictEqual( v, 0.0, 'returns expected value' ); - - // No index argument: - arr.set( [ 1.0 ] ); - - v = arr[ 0 ]; - t.strictEqual( v, 1.0, 'returns expected value' ); - - arr.set( [ 0.0 ] ); - - // Index argument: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - t.strictEqual( v, 0.0, 'returns expected value' ); - - arr.set( [ 1.05 ], i ); - - v = arr[ i ]; - t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); - } - - // Multiple values, no index argument: - arr.set( [ 1.05, 2.05 ] ); - - v = arr[ 0 ]; - t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); - - v = arr[ 1 ]; - t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); - - // Multiple values, index argument: - arr.set( [ 1.05, 2.05 ], 2 ); - - v = arr[ 2 ]; - t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); - - v = arr[ 3 ]; - t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method sets an array element (floating-point number array; shared buffer)', function test( t ) { - var byteOffset; - var arr; - var src; - var buf; - var ab; - var v; - var i; - - byteOffset = 112; - - ab = new ArrayBuffer( 240 ); - arr = new Float16Array( ab, byteOffset, 10 ); - - // Overlapping (requires copy), multiple values, no index argument: - buf = [ 1.05, 2.05 ]; - src = new Float16Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src ); - - v = arr[ 0 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 1 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - // Overlapping (requires copy), multiple values, index argument: - buf = [ -1.05, -2.05 ]; - src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src, 2 ); - - v = arr[ 2 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 3 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - // Overlapping (no copy), multiple values, no index argument: - buf = [ 3.05, 4.05 ]; - src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src ); - - v = arr[ 0 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 1 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - // Overlapping (no copy), multiple values, index argument: - buf = [ -3.05, -4.05 ]; - src = new Float16Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src, 2 ); - - v = arr[ 2 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 3 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - t.end(); -}); diff --git a/test/polyfill/test.slice.js b/test/polyfill/test.slice.js deleted file mode 100644 index f6743cb..0000000 --- a/test/polyfill/test.slice.js +++ /dev/null @@ -1,311 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `slice` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'slice' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.slice ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.slice.call( value ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.slice( value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.slice( 0, value ); - }; - } -}); - -tape( 'the method returns an empty typed array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.slice(); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if called without arguments, the method returns a typed array containing the same elements as the original array', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.slice(); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if called with one argument, the method returns a typed array containing elements starting from a specified beginning index (inclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.slice( 1 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided two arguments, the method returns a typed array containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.slice( 1, 3 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.slice( 1, 30 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method resolves negative indices relative to the last element', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.slice( -3, -1 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.slice( -30, -2 ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty typed array if a resolved beginning index exceeds a resolved ending index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.slice( 2, 0 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty typed array if a resolved beginning index exceeds the maximum array index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.slice( 5 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty typed array if a resolved ending index is less than or equal to zero', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Uint16Array( [] ); - actual = arr.slice( 2, -8 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - actual = arr.slice( 1, 0 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.some.js b/test/polyfill/test.some.js deleted file mode 100644 index dfa9cda..0000000 --- a/test/polyfill/test.some.js +++ /dev/null @@ -1,196 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `some` method for returning boolean indicating whether at least one element passes a test', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'some' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.some ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.some.call( value, predicate ); - }; - } - - function predicate( v ) { - return v === 1.0; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.some( value ); - }; - } -}); - -tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 0 ); - bool = arr.some( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns `true` if at least one element passes a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 1.05 ); - } -}); - -tape( 'the method returns `false` if all elements fail a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 5.05 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v === float64ToFloat16( 4.05 ); - } -}); - -tape( 'the method stops executing upon encountering the first element which passes a test', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v === float64ToFloat16( 1.05 ); - } -}); diff --git a/test/polyfill/test.sort.js b/test/polyfill/test.sort.js deleted file mode 100644 index 1ebbfd6..0000000 --- a/test/polyfill/test.sort.js +++ /dev/null @@ -1,189 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// FUNCTIONS // - -/** -* Comparison function. -* -* @private -* @param {boolean} a - first value for comparison -* @param {boolean} b - second value for comparison -* @returns {number} comparison result -*/ -function compareFcn( a, b ) { - if ( a < b ) { - return -1; - } - if ( a > b ) { - return 1; - } - return 0; -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `sort` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'sort' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.sort ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.sort.call( value, compareFcn ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.sort( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.sort( compareFcn ); - - t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method sorts elements of a floating-point number array in-place', function test( t ) { - var expected; - var arr; - var out; - var buf; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ), - toWord( 5.05 ) - ]); - out = arr.sort( compareFcn ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - arr = new Float16Array( [ 2.05, 1.05, -1.05, 0.05, -2.05 ] ); - expected = new Uint16Array([ - toWord( -2.05 ), - toWord( -1.05 ), - toWord( 0.05 ), - toWord( 1.05 ), - toWord( 2.05 ) - ]); - out = arr.sort( compareFcn ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - out = arr.sort( compareFcn ); - - t.strictEqual( out.length, arr.length, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.subarray.js b/test/polyfill/test.subarray.js deleted file mode 100644 index c6d42d1..0000000 --- a/test/polyfill/test.subarray.js +++ /dev/null @@ -1,308 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `subarray` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'subarray' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.subarray ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.subarray.call( value ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.subarray( value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.subarray( 0, value ); - }; - } -}); - -tape( 'the method returns empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.subarray(); - - t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if called without arguments, the method returns a view containing the same elements as the original array', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.subarray(); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if called with one argument, the method returns a view containing elements starting from a specified beginning index (inclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.subarray( 1 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided two arguments, the method returns a view containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.subarray( 1, 3 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method resolves negative indices relative to the last element', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.subarray( -3, -1 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ) - ]); - actual = arr.subarray( -30, -2 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty view if a resolved beginning index exceeds a resolved ending index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.subarray( 2, 0 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty view if a resolved beginning index exceeds the maximum array index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.subarray( 5 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty view if a resolved ending index is less than or equal to zero', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.subarray( 2, -8 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - actual = arr.subarray( 1, 0 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.to_locale_string.js b/test/polyfill/test.to_locale_string.js deleted file mode 100644 index 96fb9b0..0000000 --- a/test/polyfill/test.to_locale_string.js +++ /dev/null @@ -1,187 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toLocaleString` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'toLocaleString' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.toLocaleString ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toLocaleString.call( value ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a string or an array of strings', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 0 ); - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, 2, 3 ], - 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() { - return arr.toLocaleString( value ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a string or an array of strings (options)', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 0 ); - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, 2, 3 ], - 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() { - return arr.toLocaleString( value, {} ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array(); - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - 'beep', - [], - 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() { - return arr.toLocaleString( 'en-GB', value ); - }; - } -}); - -tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { - var str; - var arr; - - arr = new Float16Array( 0 ); - str = arr.toLocaleString(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array', function test( t ) { - var expected; - var str; - var arr; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - expected = '1,2,3'; - - str = arr.toLocaleString(); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.to_reversed.js b/test/polyfill/test.to_reversed.js deleted file mode 100644 index a3f8da5..0000000 --- a/test/polyfill/test.to_reversed.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toReversed` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'toReversed' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.toReversed ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toReversed.call( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.toReversed(); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new typed array containing elements in reverse order', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); - expected = new Uint16Array([ - toWord( 5.05 ), - toWord( 4.05 ), - toWord( 3.05 ), - toWord( 2.05 ), - toWord( 1.05 ) - ]); - out = arr.toReversed(); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.toReversed(); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.to_sorted.js b/test/polyfill/test.to_sorted.js deleted file mode 100644 index e011bef..0000000 --- a/test/polyfill/test.to_sorted.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// FUNCTIONS // - -/** -* Comparison function. -* -* @private -* @param {boolean} a - first value for comparison -* @param {boolean} b - second value for comparison -* @returns {number} comparison result -*/ -function compareFcn( a, b ) { - if ( a < b ) { - return -1; - } - if ( a > b ) { - return 1; - } - return 0; -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toSorted` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'toSorted' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.toSorted ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toSorted.call( value, compareFcn ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.toSorted( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.toSorted( compareFcn ); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new typed array containing elements in sorted order', function test( t ) { - var expected; - var arr; - var out; - var buf; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ), - toWord( 5.05 ) - ]); - out = arr.toSorted( compareFcn ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - out = arr.toSorted( compareFcn ); - - t.strictEqual( out.length, arr.length, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.to_string.js b/test/polyfill/test.to_string.js deleted file mode 100644 index b0c098b..0000000 --- a/test/polyfill/test.to_string.js +++ /dev/null @@ -1,97 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toString` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.toString ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toString.call( value ); - }; - } -}); - -tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { - var str; - var arr; - - arr = new Float16Array( 0 ); - str = arr.toString(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array', function test( t ) { - var expected; - var str; - var arr; - - arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - expected = '1,2,3,4'; - - str = arr.toString(); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/polyfill/test.values.js b/test/polyfill/test.values.js deleted file mode 100644 index ce5fc09..0000000 --- a/test/polyfill/test.values.js +++ /dev/null @@ -1,264 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var isNumber = require( '@stdlib/assert-is-number' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `values` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'values' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.values ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.values.call( value ); - }; - } -}); - -tape( 'the method returns an iterator protocol-compliant object', function test( t ) { - var expected; - var arr; - var it; - var i; - var r; - var e; - - arr = new Float16Array( [ 1.05, 2.05 ] ); - expected = [ - { - 'value': float64ToFloat16( 1.05 ), - 'done': false - }, - { - 'value': float64ToFloat16( 2.05 ), - 'done': false - }, - { - 'done': true - } - ]; - it = arr.values(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( isNumber( r.value ), true, 'returns expected value' ); - t.strictEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - - t.end(); -}); - -tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var arr; - var it; - var i; - var v; - - arr = new Float16Array( [] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - it = arr.values(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - v = it.next(); - t.deepEqual( v, expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var arr; - var it; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05 ] ); - it = arr.values(); - - v = it.next(); - t.strictEqual( v.value, float64ToFloat16( 1.05 ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, float64ToFloat16( 2.05 ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.return(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var arr; - var it; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05 ] ); - it = arr.values(); - - v = it.next(); - t.strictEqual( v.value, float64ToFloat16( 1.05 ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, float64ToFloat16( 2.05 ), 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.return( 'beep' ); - t.strictEqual( v.value, 'beep', 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - v = it.next(); - t.strictEqual( v.value, void 0, 'returns expected value' ); - t.strictEqual( v.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { - var Float16Array; - var arr; - var buf; - var it1; - var it2; - var v1; - var v2; - var i; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it1 = arr.values(); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns expected value' ); - t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); - t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); - - for ( i = 0; i < arr.length; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.strictEqual( v1, v2, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { - var Float16Array; - var arr; - var buf; - var it; - - Float16Array = proxyquire( './../../lib/polyfill', { - '@stdlib/symbol-iterator': false - }); - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.values(); - t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/polyfill/test.with.js b/test/polyfill/test.with.js deleted file mode 100644 index 0b6eda1..0000000 --- a/test/polyfill/test.with.js +++ /dev/null @@ -1,213 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../../lib/polyfill' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `with` method', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array.prototype, 'with' ), true, 'has property' ); - t.strictEqual( isFunction( Float16Array.prototype.with ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.with.call( value, 0, true ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - values = [ - '5', - 3.14, - 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() { - return arr.with( value, true ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not in bounds', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - -11, - -12, - 11, - 12 - ]; - 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() { - return arr.with( value, 1.0 ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not a numeric value', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 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() { - return arr.with( 0, value ); - }; - } -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.with( 5, 1.0 ); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new floating-point number array with the element at a provided index replaced with a provided value', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 2.05 ) - ]); - out = arr.with( 3, 2.05 ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.notEqual( out, arr, 'returns new instance' ); - t.end(); -}); - -tape( 'the method supports negative indices', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 2.05 ) - ]); - out = arr.with( -1, 2.05 ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.at.js b/test/test.at.js deleted file mode 100644 index 19df3bd..0000000 --- a/test/test.at.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `at` method for returning an array element', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.at ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.at.call( value, 0 ); - }; - } -}); - -tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) { - var arr; - var v; - var i; - - arr = new Float16Array( 10 ); - for ( i = -arr.length; i < arr.length; i++ ) { - if ( i < 0 ) { - v = arr.at( i-arr.length ); - t.strictEqual( v, void 0, 'returns expected value for index '+(i-arr.length) ); - } else { - v = arr.at( arr.length+i ); - t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) ); - } - } - t.end(); -}); - -tape( 'the method returns an array element', function test( t ) { - var arr; - var v; - var i; - - arr = []; - for ( i = 0; i < 10; i++ ) { - arr.push( i+0.05 ); - } - - arr = new Float16Array( arr ); - - for ( i = -arr.length; i < arr.length; i++ ) { - v = arr.at( i ); - if ( i < 0 ) { - t.strictEqual( v, float64ToFloat16( arr.length + i + 0.05 ), 'returns expected value for index '+i ); - } else { - t.strictEqual( v, float64ToFloat16( i + 0.05 ), 'returns expected value for index '+i ); - } - } - t.end(); -}); diff --git a/test/test.copy_within.js b/test/test.copy_within.js deleted file mode 100644 index d286509..0000000 --- a/test/test.copy_within.js +++ /dev/null @@ -1,279 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `copyWithin` method for copying a sequence of array elements within a floating-point number array', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.copyWithin.call( value, 3, 0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.copyWithin.call( value, 3, 0, 5 ); - }; - } -}); - -tape( 'the method copies a sequence of elements within an array', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 0, 3 ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( -arr.length, 3 ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 0, -2 ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 0, 3, arr.length ); - buf = new Uint16Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 2, 0, 2 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - - // Overwritten: - t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 2, 0, -3 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - - // Overwritten: - t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( arr.length, 3 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { - var arr; - var buf; - - arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( arr ); - - arr.copyWithin( 2, 0 ); - buf = new Uint16Array( arr.buffer ); - - // Remain the same: - t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - - // Overwritten: - t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); - t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 4 ], toWord( 2.05 ), 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.entries.js b/test/test.entries.js deleted file mode 100644 index 396dd8e..0000000 --- a/test/test.entries.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isNumber = require( '@stdlib/assert-is-number' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.entries ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.entries.call( value ); - }; - } -}); - -tape( 'the method returns an iterator protocol-compliant object', function test( t ) { - var buf; - var arr; - var it; - var v; - var i; - - buf = [ 1.05, 2.05, 3.05, 4.05 ]; - arr = new Float16Array( buf ); - - it = arr.entries(); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < arr.length; i++ ) { - v = it.next(); - t.strictEqual( isArray( v.value ), true, 'returns expected value' ); - t.strictEqual( v.value[ 0 ], i, 'returns expected value' ); - t.strictEqual( isNumber( v.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ i ] ), 'returns expected value' ); - t.strictEqual( typeof v.done, 'boolean', 'returns expected value' ); - } - t.end(); -}); diff --git a/test/test.every.js b/test/test.every.js deleted file mode 100644 index 0742d6a..0000000 --- a/test/test.every.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.every ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.every.call( value, predicate ); - }; - } - - function predicate( v ) { - return v === 0.0; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.every( value ); - }; - } -}); - -tape( 'the method returns `true` if operating on an empty floating-point number array', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 0 ); - bool = arr.every( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns `true` if all elements pass a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - bool = arr.every( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 1.05 ); - } -}); - -tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 1.05, 0.05, 1.05 ] ); - bool = arr.every( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 1.05 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - bool = arr.every( predicate, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v === float64ToFloat16( 1.05 ); - } -}); diff --git a/test/test.fill.js b/test/test.fill.js deleted file mode 100644 index d434060..0000000 --- a/test/test.fill.js +++ /dev/null @@ -1,212 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `fill` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.fill ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.fill.call( value, 1.0 ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.fill( 1.05 ); - - t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.fill( 1.05 ); - - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'if called with one argument, the method sets each array element to the provided value', function test( t ) { - var arr; - var buf; - var i; - - arr = new Float16Array( 3 ); - arr.fill( 1.05 ); - - buf = new Uint16Array( arr.buffer ); - - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); - } - - t.end(); -}); - -tape( 'if called with two arguments, the method sets each array element to the provided value starting from a start index (inclusive)', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, 1 ); - - t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 1.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'if called with three arguments, the method sets each array element to the provided value starting from a start index (inclusive) until a specified end index (exclusive)', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, 0, 2 ); - - t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method supports negative indices', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, -3, -1 ); - - t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'if a provided start index resolves to a negative index, the method fills an array starting from the first element', function test( t ) { - var arr; - var buf; - var i; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, -10 ); - - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); - } - - t.end(); -}); - -tape( 'if a provided end index resolves to an index exceeding the last array element index, the method fills an array until the last element (inclusive)', function test( t ) { - var arr; - var buf; - var i; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.05, 1, 10 ); - - t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); - for ( i = 1; i < arr.length; i++ ) { - t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); - } - - t.end(); -}); - -tape( 'if a provided start index resolves to an index which is greater than or equal to a resolved end index, the method does not fill an array', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 3 ); - buf = new Uint16Array( arr.buffer ); - - arr.fill( 1.0, 2, 1 ); - - t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); - t.strictEqual( buf[ 1 ], toWord( 0.0 ), 'returns expected value' ); - t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.filter.js b/test/test.filter.js deleted file mode 100644 index 1b77a61..0000000 --- a/test/test.filter.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `filter` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.filter ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.filter.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.filter( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.filter( predicate ); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method returns a new floating-point number array containing only those elements which satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 1.05, 2.05 ] ); - expected = new Uint16Array( [ toWord( 1.05 ), toWord( 1.05 ) ] ); - actual = arr.filter( predicate ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v === float64ToFloat16( 1.05 ) ); - } -}); - -tape( 'the method copies all elements to a new array if all elements satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.filter( predicate ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v > 1.0 ); - } -}); - -tape( 'the method returns an empty array if no elements satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.filter( predicate ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 1.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var expected; - var actual; - var arr; - var buf; - var ctx; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 1.05 ) - ]); - ctx = { - 'count': 0 - }; - actual = arr.filter( predicate, ctx ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v === float64ToFloat16( 1.05 ) ); - } -}); diff --git a/test/test.find.js b/test/test.find.js deleted file mode 100644 index 1836dc3..0000000 --- a/test/test.find.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `find` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.find ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.find.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.find( value ); - }; - } -}); - -tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.find( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the first element which passes a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - v = arr.find( predicate ); - - t.strictEqual( v, float64ToFloat16( -2.05 ), 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - v = arr.find( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var v; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - v = arr.find( predicate, ctx ); - - t.strictEqual( v, float64ToFloat16( 3.05 ), 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/test.find_index.js b/test/test.find_index.js deleted file mode 100644 index b3e9023..0000000 --- a/test/test.find_index.js +++ /dev/null @@ -1,171 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `findIndex` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.findIndex ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.findIndex.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.findIndex( value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( 0 ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the index of the first element which passes a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, 1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0); - } -}); - -tape( 'the method returns `-1` if all elements fail a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var idx; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - idx = arr.findIndex( predicate, ctx ); - - t.strictEqual( idx, 2, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/test.find_last.js b/test/test.find_last.js deleted file mode 100644 index 4451b22..0000000 --- a/test/test.find_last.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `findLast` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.findLast ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.findLast.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 0.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.findLast( value ); - }; - } -}); - -tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.findLast( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the last element which passes a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - v = arr.findLast( predicate ); - - t.strictEqual( v, float64ToFloat16( -4.05 ), 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { - var arr; - var v; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - v = arr.findLast( predicate ); - - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var v; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - v = arr.findLast( predicate, ctx ); - - t.strictEqual( v, float64ToFloat16( 5.05 ), 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/test.find_last_index.js b/test/test.find_last_index.js deleted file mode 100644 index c303468..0000000 --- a/test/test.find_last_index.js +++ /dev/null @@ -1,171 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `findLastIndex` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.findLastIndex ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.findLastIndex.call( value, predicate ); - }; - } - - function predicate( v ) { - return ( v === 1.0 ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.findLastIndex( value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( 0 ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns the index of the last element which passes a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, 3, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method returns `-1` if all elements fail a test', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( v < 0.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var idx; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); - idx = arr.findLastIndex( predicate, ctx ); - - t.strictEqual( idx, 4, 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v > 0.0 ); - } -}); diff --git a/test/test.for_each.js b/test/test.for_each.js deleted file mode 100644 index af6afda..0000000 --- a/test/test.for_each.js +++ /dev/null @@ -1,194 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `forEach` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.forEach ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.forEach.call( value, fcn ); - }; - } - - function fcn( v ) { - if ( !isNumber( v ) ) { - t.fail( 'should be a number' ); - } - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.forEach( value ); - }; - } -}); - -tape( 'the method should not invoke a provided callback function if operating on an empty floating-point array', function test( t ) { - var arr; - - arr = new Float16Array( 0 ); - arr.forEach( fcn ); - - t.end(); - - function fcn() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns `undefined`', function test( t ) { - var arr; - var out; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - out = arr.forEach( fcn ); - - t.strictEqual( out, void 0, 'returns expected value' ); - t.end(); - - function fcn( v ) { - if ( !isNumber( v ) ) { - t.fail( 'should be a number' ); - } - } -}); - -tape( 'the method invokes a provided function for each element in an array', function test( t ) { - var expected; - var indices; - var values; - var arrays; - var arr; - - indices = []; - values = []; - arrays = []; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - arr.forEach( fcn ); - - expected = [ - float64ToFloat16( 1.05 ), - float64ToFloat16( 2.05 ), - float64ToFloat16( 3.05 ), - float64ToFloat16( 4.05 ) - ]; - - t.deepEqual( values, expected, 'returns expected value' ); - t.deepEqual( indices, [ 0, 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( arrays[ 0 ], arr, 'returns expected value' ); - t.strictEqual( arrays[ 1 ], arr, 'returns expected value' ); - t.strictEqual( arrays[ 2 ], arr, 'returns expected value' ); - t.strictEqual( arrays[ 3 ], arr, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - values.push( v ); - indices.push( i ); - arrays.push( arr ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - arr.forEach( fcn, ctx ); - - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function fcn() { - this.count += 1; // eslint-disable-line no-invalid-this - } -}); diff --git a/test/test.from.js b/test/test.from.js deleted file mode 100644 index 15a43a2..0000000 --- a/test/test.from.js +++ /dev/null @@ -1,309 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 Uint16Array = require( '@stdlib/array-uint16' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `from` method for creating a 16-bit floating-point number array from an array-like object or an iterable', function test( t ) { - var arr; - - t.strictEqual( isFunction( Float16Array.from ), true, 'has method' ); - - arr = Float16Array.from( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a constructor', 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() { - return Float16Array.from.call( value, [] ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array constructor', function test( t ) { - var values; - var i; - - values = [ - {}, - null, - 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() { - return Float16Array.from.call( value, [] ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - {}, - [] - ]; - 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() { - return Float16Array.from( [], value ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not a function (thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - {}, - [] - ]; - 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() { - return Float16Array.from( [], value, {} ); - }; - } -}); - -tape( 'the method returns a floating-point number array', function test( t ) { - var arr; - var v; - - // Generic array: - arr = Float16Array.from( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Generic array containing non-numeric values: - arr = Float16Array.from( [ 'beep' ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Float16Array.from( [ null, 4 ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - arr = Float16Array.from( [ true, {}, '' ] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 3, 'returns expected value' ); - - // Typed array: - arr = Float16Array.from( new Uint16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Floating-point number typed array: - arr = Float16Array.from( new Float16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Float16Array( [ 1.0, 2.0 ] ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method supports providing a "map" function which is invoked for each source element', function test( t ) { - var arr; - var v; - - // Generic array: - arr = Float16Array.from( [], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Generic array containing non-numeric values: - arr = Float16Array.from( [ 'beep' ], clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Float16Array.from( [ null ], clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Float16Array.from( [ [], {} ], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - arr = Float16Array.from( [ 4, 5 ], clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Typed array: - arr = Float16Array.from( new Uint16Array( 0 ), clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ), clbk1 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Floating-point number typed array: - arr = Float16Array.from( new Float16Array( 0 ), clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Float16Array.from( new Float16Array( [ true, true ] ), clbk2 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); - - function clbk1( v ) { - return v; - } - - function clbk2() { - return true; - } -}); - -tape( 'the method supports providing a `this` context for a provided map function', function test( t ) { - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1, ctx ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function clbk1( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v; - } -}); diff --git a/test/test.includes.js b/test/test.includes.js deleted file mode 100644 index a367b40..0000000 --- a/test/test.includes.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `includes` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.includes ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.includes.call( value, true ); - }; - } -}); - -tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 0 ); - bool = arr.includes( 1.0 ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `false` if a floating-point number is not found', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 10 ); - bool = arr.includes( 1.0 ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `true` if an array contains a specified floating-point number', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05] ); - bool = arr.includes( float64ToFloat16( 1.05 ) ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `false` if provided a second argument which exceeds the input array length', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 10 ); - bool = arr.includes( 0.0, 20 ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); - - bool = arr.includes( float64ToFloat16( 1.05 ), 0 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), 1 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), 3 ); - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index (negative)', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); - - bool = arr.includes( float64ToFloat16( 1.05 ), -5 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), -2 ); - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); - - bool = arr.includes( float64ToFloat16( 1.05 ), -10 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( float64ToFloat16( 2.05 ), -10 ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.index_of.js b/test/test.index_of.js deleted file mode 100644 index 2a684aa..0000000 --- a/test/test.index_of.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `indexOf` method for returning the index of an array element', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.indexOf ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.indexOf.call( value, 1.0 ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array(); - idx = arr.indexOf( 1.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( 10 ); - idx = arr.indexOf( 1.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns the index of the first match if a numeric value is found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - idx = arr.indexOf( float64ToFloat16( 2.05 ) ); - - t.strictEqual( idx, 1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if provided a second argument which exceeds the input array length', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( 10 ); - idx = arr.indexOf( 1.0, 20 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), 0 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), 2 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), 4 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index (negative)', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), -5 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), -1 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); - - idx = arr.indexOf( float64ToFloat16( 2.05 ), -10 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( float64ToFloat16( 1.05 ), -10 ); - t.strictEqual( idx, 0, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.join.js b/test/test.join.js deleted file mode 100644 index 800bb1f..0000000 --- a/test/test.join.js +++ /dev/null @@ -1,141 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `join` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.join ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.join.call( value ); - }; - } -}); - -tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { - var str; - var arr; - - arr = new Float16Array( 0 ); - str = arr.join(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator', function test( t ) { - var expected; - var str; - var arr; - var i; - - arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); - - expected = float64ToFloat16( 0.05 ); - for ( i = 1; i < arr.length; i++ ) { - expected += '@' + float64ToFloat16( i + 0.05 ); - } - - str = arr.join( '@' ); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator (single element)', function test( t ) { - var expected; - var str; - var arr; - - arr = new Float16Array( [ 1.05 ] ); - expected = '' + float64ToFloat16( 1.05 ); - - str = arr.join(); - - t.strictEqual( str, expected, 'returns expected value' ); - - arr = new Float16Array( [ 1.05 ] ); - expected = '' + float64ToFloat16( 1.05 ); - - str = arr.join( '@' ); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if the method is invoked without a separator argument, the method returns a string representation of a floating-point number array with elements separated by a comma', function test( t ) { - var expected; - var str; - var arr; - var i; - - arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); - - expected = float64ToFloat16( 0.05 ); - for ( i = 1; i < arr.length; i++ ) { - expected += ',' + float64ToFloat16( i + 0.05 ); - } - - str = arr.join(); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 930feef..0000000 --- a/test/test.js +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var arr = new Float16Array( 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (no argument)', function test( t ) { - var arr = new Float16Array(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (length)', function test( t ) { - var arr = new Float16Array( 10 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (array)', function test( t ) { - var arr = new Float16Array( [] ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (typed array)', function test( t ) { - var arr = new Float16Array( new Uint16Array( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer)', function test( t ) { - var arr = new Float16Array( new ArrayBuffer( 0 ) ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset)', function test( t ) { - var arr = new Float16Array( new ArrayBuffer( 8 ), 8 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, length)', function test( t ) { - var arr = new Float16Array( new ArrayBuffer( 8 ), 8, 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( Float16Array.BYTES_PER_ELEMENT, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { - t.strictEqual( hasOwnProp( Float16Array, 'name' ), true, 'has property' ); - t.strictEqual( Float16Array.name, 'Float16Array', 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns an instance having a `BYTES_PER_ELEMENT` property returning the number of bytes per array element', function test( t ) { - var arr; - - t.strictEqual( hasOwnProp( Float16Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( Float16Array.prototype.BYTES_PER_ELEMENT, 2, 'returns expected value' ); - - arr = new Float16Array( 0 ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `buffer` property for returning the underlying memory (i.e., ArrayBuffer)', function test( t ) { - var arr; - var buf; - - arr = new Float16Array( 0 ); - buf = arr.buffer; - t.strictEqual( isArrayBuffer( buf ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns an instance having a `byteLength` property for returning the number of bytes belonging to the array view', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.byteLength; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 8 ); - v = arr.byteLength; - t.strictEqual( v, 56, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); - v = arr.byteLength; - t.strictEqual( v, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `byteOffset` property for returning the byte offset pointing to the first array element in the underlying memory', function test( t ) { - var arr; - var v; - - arr = new Float16Array( 0 ); - v = arr.byteOffset; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); - v = arr.byteOffset; - t.strictEqual( v, 32, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); - v = arr.byteOffset; - t.strictEqual( v, 64, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor returns an instance having a `length` property for returning the number of array elements', function test( t ) { - var arr; - var v; - - // No arguments: - arr = new Float16Array(); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - // Explicit array length: - arr = new Float16Array( 0 ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( 10 ); - v = arr.length; - t.strictEqual( v, 10, 'returns expected value' ); - - // Generic array: - arr = new Float16Array( [] ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Typed array: - arr = new Float16Array( new Uint16Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new Uint16Array( [ 1.0, 1.0 ] ) ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Float16 typed array: - arr = new Float16Array( new Float16Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new Float16Array( [ 1.0, 2.0 ] ) ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // ArrayBuffer: - arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); - v = arr.length; - t.strictEqual( v, 16, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Float16Array( new ArrayBuffer( 64 ), 32, 2 ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 2', function test( t ) { - var values; - var i; - - values = [ - 1, - 3, - 5, - 7, - 9, - 11, - 101, - 1001 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an ArrayBuffer having a byte length equal to '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return new Float16Array( new ArrayBuffer( value ) ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 2', function test( t ) { - var values; - var i; - - values = [ - 1, - 3, - 5, - 7, - 9, - 11, - 101, - 1001 - ]; - 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() { - return new Float16Array( new ArrayBuffer( 1e3 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 8', function test( t ) { - var values; - var i; - - values = [ - 2, - 4, - 6, - 8, - 10, - 12, - 14, - 16, - 18, - 20 - ]; - 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() { - return new Float16Array( new ArrayBuffer( 101 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided insufficient memory to accommodate byte offset and length arguments', function test( t ) { - var values; - var i; - - values = [ - 8, - 16, - 24, - 32 - ]; - 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() { - return new Float16Array( new ArrayBuffer( 100 ), value, 1e3 ); - }; - } -}); diff --git a/test/test.keys.js b/test/test.keys.js deleted file mode 100644 index 283d682..0000000 --- a/test/test.keys.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `keys` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.keys ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.keys.call( value ); - }; - } -}); - -tape( 'the method returns an iterator protocol-compliant object', function test( t ) { - var expected; - var arr; - var it; - var i; - var r; - var e; - - arr = new Float16Array( [ 1.05, 2.05 ] ); - expected = [ - { - 'value': 0, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - it = arr.keys(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.strictEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } else { - t.strictEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - - t.end(); -}); - -tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var arr; - var it; - var i; - var v; - - arr = new Float16Array( [] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - it = arr.keys(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - v = it.next(); - t.strictEqual( v.value, expected[ i ].value, 'returns expected value' ); - t.strictEqual( v.done, expected[ i ].done, 'returns expected value' ); - } - t.end(); -}); diff --git a/test/test.last_index_of.js b/test/test.last_index_of.js deleted file mode 100644 index 5a42168..0000000 --- a/test/test.last_index_of.js +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `lastIndexOf` method for returning the index of an array element', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.lastIndexOf ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.lastIndexOf.call( value, true ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { - var arr; - var idx; - - arr = new Float16Array( 0 ); - idx = arr.lastIndexOf( 0.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( 10 ); - idx = arr.lastIndexOf( 1.0 ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns the index of the first match when searching from the end of the array if a search element is found', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 1.05, 2.05 ] ); - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ) ); - - t.strictEqual( idx, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); - - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 4 ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 2 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 0 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index (negative)', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); - - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), -3 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), -1 ); - t.strictEqual( idx, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) { - var idx; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); - - idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 10 ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 10 ); - t.strictEqual( idx, 2, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.map.js b/test/test.map.js deleted file mode 100644 index f7e5594..0000000 --- a/test/test.map.js +++ /dev/null @@ -1,176 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var identity = require( '@stdlib/utils-identity-function' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `map` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.map ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.map.call( value, identity ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.map( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.map( identity ); - - t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.end(); -}); - -tape( 'the method returns a new floating-point number array containing elements which are the result of a provided callback function', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( -1.05 ), - toWord( -2.05 ), - toWord( -3.05 ), - toWord( -4.05 ) - ]); - actual = arr.map( invert ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); - - function invert( v ) { - return -v; - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var expected; - var actual; - var arr; - var buf; - var ctx; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( -1.05 ), - toWord( -2.05 ), - toWord( -3.05 ), - toWord( -4.05 ) - ]); - ctx = { - 'count': 0 - }; - actual = arr.map( invert, ctx ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.strictEqual( ctx.count, 6, 'returns expected value' ); - t.end(); - - function invert( v, i ) { - this.count += i; // eslint-disable-line no-invalid-this - return -v; - } -}); diff --git a/test/test.of.js b/test/test.of.js deleted file mode 100644 index 6486686..0000000 --- a/test/test.of.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `of` method for creating a 16-bit floating-point number array from a variable number of arguments', function test( t ) { - var arr; - - t.strictEqual( isFunction( Float16Array.of ), true, 'has method' ); - - arr = Float16Array.of(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a constructor', 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() { - return Float16Array.of.call( value, true, true ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point array constructor', function test( t ) { - var values; - var i; - - values = [ - {}, - null, - 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() { - return Float16Array.of.call( value, true, true ); - }; - } -}); - -tape( 'the method returns a floating-point number array', function test( t ) { - var arr; - var v; - - // No arguments: - arr = Float16Array.of(); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - // Numeric arguments: - arr = Float16Array.of( 1.0, 2.0, 3.0, 4.0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - // Non-numeric arguments: - arr = Float16Array.of( 1, {}, 0, null, 'beep' ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 5, 'returns expected value' ); - - // Mixed arguments: - arr = Float16Array.of( true, 1, false, 0 ); - t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index 2010bde..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 hasFloat16ArraySupport = require( '@stdlib/assert-has-float16array-support' ); -var polyfill = require( './../lib/polyfill' ); -var ctor = require( './../lib' ); - - -// VARIABLES // - -var hasFloat16Arrays = hasFloat16ArraySupport(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment supports `Float16Array`, the export is an alias for `Float16Array`', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert-has-float16array-support': isTrue, - './main.js': Mock - }); - t.strictEqual( Foo, Mock, 'returns builtin' ); - - if ( hasFloat16Arrays ) { - t.strictEqual( ctor, Float16Array, 'is alias' ); // eslint-disable-line stdlib/require-globals, no-undef - } - - t.end(); - - function Mock() { - return this; - } - - function isTrue() { - return true; - } -}); - -tape( 'if an environment does not support `Float16Array`, the export is a polyfill', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert-has-float16array-support': isFalse - }); - - t.strictEqual( Foo, polyfill, 'returns polyfill' ); - t.end(); - - function isFalse() { - return false; - } -}); diff --git a/test/test.reduce.js b/test/test.reduce.js deleted file mode 100644 index 34786fc..0000000 --- a/test/test.reduce.js +++ /dev/null @@ -1,187 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `reduce` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.reduce ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.reduce.call( value, reducer ); - }; - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.reduce( value ); - }; - } -}); - -tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { - var arr; - - arr = new Float16Array( 0 ); - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - arr.reduce( reducer ); - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method uses the first element of the array as the initial value when an initial value is not provided', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - var ind; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - accArray = [ 1.0, 3.0 ]; - valueArray = [ 2.0, 3.0 ]; - expected = float64ToFloat16( 6.0 ); - actual = arr.reduce( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); - - function reducer( acc, value, index ) { - ind = index-1; - t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method supports providing an initial value as the second argument', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - accArray = [ 2.0, 3.0, 5.0 ]; - valueArray = [ 1.0, 2.0, 3.0 ]; - expected = 8.0; - actual = arr.reduce( reducer, 2.0 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value, index ) { - t.strictEqual( acc, float64ToFloat16( accArray[ index ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ index ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method returns the accumulated result', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = float64ToFloat16( 10.20 ); - actual = arr.reduce( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index 313b948..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,190 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `reduceRight` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.reduceRight ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.reduceRight.call( value, reducer ); - }; - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.reduceRight( value ); - }; - } -}); - -tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { - var arr; - - arr = new Float16Array( 0 ); - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - arr.reduceRight( reducer ); - } - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method uses the last element of the array as the initial value when an initial value is not provided', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - var len; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - len = arr.length; - accArray = [ 3.0, 5.0 ]; - valueArray = [ 2.0, 1.0 ]; - expected = float64ToFloat16( 6.0 ); - actual = arr.reduceRight( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value, index ) { - var ind = (len-index-2); - t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method supports providing an initial value as the second argument', function test( t ) { - var valueArray; - var accArray; - var expected; - var actual; - var arr; - var len; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - len = arr.length; - accArray = [ 2.0, 5.0, 7.0 ]; - valueArray = [ 3.0, 2.0, 1.0 ]; - expected = 8.0; - actual = arr.reduceRight( reducer, 2.0 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value, index ) { - var ind = (len-index-1); - t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); - t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); - return float64ToFloat16( acc + value ); - } -}); - -tape( 'the method returns the accumulated result', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = float64ToFloat16( 10.20 ); - actual = arr.reduceRight( reducer ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value ) { - return float64ToFloat16( acc + value ); - } -}); diff --git a/test/test.reverse.js b/test/test.reverse.js deleted file mode 100644 index 147a4a0..0000000 --- a/test/test.reverse.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `reverse` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.reverse ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.reverse.call( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.reverse(); - - t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method reverses elements of a floating-point number array in-place', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); - expected = new Uint16Array([ - toWord( 5.05 ), - toWord( 4.05 ), - toWord( 3.05 ), - toWord( 2.05 ), - toWord( 1.05 ) - ]); - out = arr.reverse(); - buf = new Uint16Array( arr.buffer ); - - t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.reverse(); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.set.js b/test/test.set.js deleted file mode 100644 index 559efab..0000000 --- a/test/test.set.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `set` method for setting one or more array elements', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.set ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.set.call( value, 0 ); - }; - } -}); - -tape( 'the method throws an error if provided an index argument which is out-of-bounds', function test( t ) { - var values; - var arr1; - var arr2; - var i; - - arr1 = new Float16Array( 10 ); - arr2 = []; - for ( i = 0; i < arr1.length; i++ ) { - arr2.push( 1.0 ); - } - - values = [ - 1, - 2, - 3, - 4, - 5 - ]; - 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() { - return arr1.set( arr2, value ); - }; - } -}); - -tape( 'the method sets one or more array elements', function test( t ) { - var arr; - var v; - var i; - - arr = new Float16Array( 10 ); - - v = arr[ 0 ]; - t.strictEqual( v, 0.0, 'returns expected value' ); - - // No index argument: - arr.set( [ 1.0 ] ); - - v = arr[ 0 ]; - t.strictEqual( v, 1.0, 'returns expected value' ); - - arr.set( [ 0.0 ] ); - - // Index argument: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - t.strictEqual( v, 0.0, 'returns expected value' ); - - arr.set( [ 1.05 ], i ); - - v = arr[ i ]; - t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); - } - - // Multiple values, no index argument: - arr.set( [ 1.05, 2.05 ] ); - - v = arr[ 0 ]; - t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); - - v = arr[ 1 ]; - t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); - - // Multiple values, index argument: - arr.set( [ 1.05, 2.05 ], 2 ); - - v = arr[ 2 ]; - t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); - - v = arr[ 3 ]; - t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); - - t.end(); -}); - -tape( 'the method sets an array element (floating-point number array; shared buffer)', function test( t ) { - var byteOffset; - var arr; - var src; - var buf; - var ab; - var v; - var i; - - byteOffset = 112; - - ab = new ArrayBuffer( 240 ); - arr = new Float16Array( ab, byteOffset, 10 ); - - // Overlapping (requires copy), multiple values, no index argument: - buf = [ 1.05, 2.05 ]; - src = new Float16Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src ); - - v = arr[ 0 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 1 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - // Overlapping (requires copy), multiple values, index argument: - buf = [ -1.05, -2.05 ]; - src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src, 2 ); - - v = arr[ 2 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 3 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - // Overlapping (no copy), multiple values, no index argument: - buf = [ 3.05, 4.05 ]; - src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src ); - - v = arr[ 0 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 1 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - // Overlapping (no copy), multiple values, index argument: - buf = [ -3.05, -4.05 ]; - src = new Float16Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 2 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src, 2 ); - - v = arr[ 2 ]; - t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); - - v = arr[ 3 ]; - t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.slice.js b/test/test.slice.js deleted file mode 100644 index a9f9e04..0000000 --- a/test/test.slice.js +++ /dev/null @@ -1,249 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `slice` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.slice ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.slice.call( value ); - }; - } -}); - -tape( 'the method returns an empty typed array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.slice(); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if called without arguments, the method returns a typed array containing the same elements as the original array', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.slice(); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if called with one argument, the method returns a typed array containing elements starting from a specified beginning index (inclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.slice( 1 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided two arguments, the method returns a typed array containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.slice( 1, 3 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.slice( 1, 30 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method resolves negative indices relative to the last element', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.slice( -3, -1 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.slice( -30, -2 ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty typed array if a resolved beginning index exceeds a resolved ending index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.slice( 2, 0 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty typed array if a resolved beginning index exceeds the maximum array index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.slice( 5 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty typed array if a resolved ending index is less than or equal to zero', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Uint16Array( [] ); - actual = arr.slice( 2, -8 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - actual = arr.slice( 1, 0 ); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.some.js b/test/test.some.js deleted file mode 100644 index 238d1d9..0000000 --- a/test/test.some.js +++ /dev/null @@ -1,194 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `some` method for returning boolean indicating whether at least one element passes a test', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.some ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.some.call( value, predicate ); - }; - } - - function predicate( v ) { - return v === 1.0; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - 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() { - return arr.some( value ); - }; - } -}); - -tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( 0 ); - bool = arr.some( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the method returns `true` if at least one element passes a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 1.05 ); - } -}); - -tape( 'the method returns `false` if all elements fail a test', function test( t ) { - var bool; - var arr; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return v === float64ToFloat16( 5.05 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v === float64ToFloat16( 4.05 ); - } -}); - -tape( 'the method stops executing upon encountering the first element which passes a test', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - bool = arr.some( predicate, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.count, 1, 'returns expected value' ); - - t.end(); - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v === float64ToFloat16( 1.05 ); - } -}); diff --git a/test/test.sort.js b/test/test.sort.js deleted file mode 100644 index e976a68..0000000 --- a/test/test.sort.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Comparison function. -* -* @private -* @param {boolean} a - first value for comparison -* @param {boolean} b - second value for comparison -* @returns {number} comparison result -*/ -function compareFcn( a, b ) { - if ( a < b ) { - return -1; - } - if ( a > b ) { - return 1; - } - return 0; -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `sort` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.sort ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.sort.call( value, compareFcn ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - {}, - [] - ]; - 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() { - return arr.sort( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.sort( compareFcn ); - - t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method sorts elements of a floating-point number array in-place', function test( t ) { - var expected; - var arr; - var out; - var buf; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ), - toWord( 5.05 ) - ]); - out = arr.sort( compareFcn ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - arr = new Float16Array( [ 2.05, 1.05, -1.05, 0.05, -2.05 ] ); - expected = new Uint16Array([ - toWord( -2.05 ), - toWord( -1.05 ), - toWord( 0.05 ), - toWord( 1.05 ), - toWord( 2.05 ) - ]); - out = arr.sort( compareFcn ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - out = arr.sort( compareFcn ); - - t.strictEqual( out.length, arr.length, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.subarray.js b/test/test.subarray.js deleted file mode 100644 index 6684448..0000000 --- a/test/test.subarray.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `subarray` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.subarray ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.subarray.call( value ); - }; - } -}); - -tape( 'the method returns empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.subarray(); - - t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if called without arguments, the method returns a view containing the same elements as the original array', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.subarray(); - buf = new Uint16Array( actual.buffer ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if called with one argument, the method returns a view containing elements starting from a specified beginning index (inclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ) - ]); - actual = arr.subarray( 1 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided two arguments, the method returns a view containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.subarray( 1, 3 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method resolves negative indices relative to the last element', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array([ - toWord( 2.05 ), - toWord( 3.05 ) - ]); - actual = arr.subarray( -3, -1 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ) - ]); - actual = arr.subarray( -30, -2 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty view if a resolved beginning index exceeds a resolved ending index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.subarray( 2, 0 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty view if a resolved beginning index exceeds the maximum array index', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.subarray( 5 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns an empty view if a resolved ending index is less than or equal to zero', function test( t ) { - var expected; - var actual; - var arr; - var buf; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); - expected = new Uint16Array( [] ); - actual = arr.subarray( 2, -8 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - - actual = arr.subarray( 1, 0 ); - buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.to_locale_string.js b/test/test.to_locale_string.js deleted file mode 100644 index 6359a2c..0000000 --- a/test/test.to_locale_string.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toLocaleString` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.toLocaleString ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toLocaleString.call( value ); - }; - } -}); - -tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { - var str; - var arr; - - arr = new Float16Array( 0 ); - str = arr.toLocaleString(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array', function test( t ) { - var expected; - var str; - var arr; - - arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); - expected = '1,2,3'; - - str = arr.toLocaleString(); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.to_reversed.js b/test/test.to_reversed.js deleted file mode 100644 index a82ad13..0000000 --- a/test/test.to_reversed.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toReversed` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.toReversed ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toReversed.call( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.toReversed(); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new typed array containing elements in reverse order', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); - expected = new Uint16Array([ - toWord( 5.05 ), - toWord( 4.05 ), - toWord( 3.05 ), - toWord( 2.05 ), - toWord( 1.05 ) - ]); - out = arr.toReversed(); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.toReversed(); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.to_sorted.js b/test/test.to_sorted.js deleted file mode 100644 index 77508b5..0000000 --- a/test/test.to_sorted.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Comparison function. -* -* @private -* @param {boolean} a - first value for comparison -* @param {boolean} b - second value for comparison -* @returns {number} comparison result -*/ -function compareFcn( a, b ) { - if ( a < b ) { - return -1; - } - if ( a > b ) { - return 1; - } - return 0; -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toSorted` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.toSorted ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.toSorted.call( value, compareFcn ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - {}, - [] - ]; - 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() { - return arr.toSorted( value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 0 ); - out = arr.toSorted( compareFcn ); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new typed array containing elements in sorted order', function test( t ) { - var expected; - var arr; - var out; - var buf; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 2.05 ), - toWord( 3.05 ), - toWord( 4.05 ), - toWord( 5.05 ) - ]); - out = arr.toSorted( compareFcn ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); - out = arr.toSorted( compareFcn ); - - t.strictEqual( out.length, arr.length, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.to_string.js b/test/test.to_string.js deleted file mode 100644 index a2bb9e3..0000000 --- a/test/test.to_string.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `toString` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.toString ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with an invalid `this` context', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - values = [ - 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() { - return arr.toString.call( value ); - }; - } -}); - -tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { - var str; - var arr; - - arr = new Float16Array( 0 ); - str = arr.toString(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a floating-point number array', function test( t ) { - var expected; - var str; - var arr; - - arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - expected = '1,2,3,4'; - - str = arr.toString(); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.values.js b/test/test.values.js deleted file mode 100644 index 225b3fe..0000000 --- a/test/test.values.js +++ /dev/null @@ -1,147 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var float64ToFloat16 = require( '@stdlib/number-float64-base-to-float16' ); -var isNumber = require( '@stdlib/assert-is-number' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `values` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.values ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.values.call( value ); - }; - } -}); - -tape( 'the method returns an iterator protocol-compliant object', function test( t ) { - var expected; - var arr; - var it; - var i; - var r; - var e; - - arr = new Float16Array( [ 1.05, 2.05 ] ); - expected = [ - { - 'value': float64ToFloat16( 1.05 ), - 'done': false - }, - { - 'value': float64ToFloat16( 2.05 ), - 'done': false - }, - { - 'done': true - } - ]; - it = arr.values(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.strictEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } else { - t.strictEqual( isNumber( r.value ), true, 'returns expected value' ); - t.strictEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - - t.end(); -}); - -tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var arr; - var it; - var i; - var v; - - arr = new Float16Array( [] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - it = arr.values(); - - t.strictEqual( typeof it, 'object', 'returns expected value' ); - t.strictEqual( typeof it.next, 'function', 'has next method' ); - - for ( i = 0; i < expected.length; i++ ) { - v = it.next(); - t.strictEqual( v.value, expected[ i ].value, 'returns expected value' ); - t.strictEqual( v.done, expected[ i ].done, 'returns expected value' ); - } - t.end(); -}); diff --git a/test/test.with.js b/test/test.with.js deleted file mode 100644 index de134c8..0000000 --- a/test/test.with.js +++ /dev/null @@ -1,151 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 isFunction = require( '@stdlib/assert-is-function' ); -var toWord = require( '@stdlib/number-float16-base-to-word' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Float16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `with` method', function test( t ) { - t.strictEqual( isFunction( Float16Array.prototype.with ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 5 ); - - 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() { - return arr.with.call( value, 0, true ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not in bounds', function test( t ) { - var values; - var arr; - var i; - - arr = new Float16Array( 10 ); - - values = [ - -11, - -12, - 11, - 12 - ]; - 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() { - return arr.with( value, 1.0 ); - }; - } -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Float16Array( 10 ); - out = arr.with( 5, 1.0 ); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new floating-point number array with the element at a provided index replaced with a provided value', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 2.05 ) - ]); - out = arr.with( 3, 2.05 ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.notEqual( out, arr, 'returns new instance' ); - t.end(); -}); - -tape( 'the method supports negative indices', function test( t ) { - var expected; - var arr; - var buf; - var out; - - arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); - expected = new Uint16Array([ - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 1.05 ), - toWord( 2.05 ) - ]); - out = arr.with( -1, 2.05 ); - buf = new Uint16Array( out.buffer ); - - t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - t.end(); -});