diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +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 - -# 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 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +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 diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0321c09..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-31T00:41:06.204Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3f3fe2b..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/complex128) 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 12e2893..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/complex128) 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 23bcee7..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: '20 8 * * 5' - - # 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 f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +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 status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # 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/test.at.js b/test/test.at.js deleted file mode 100644 index a7f8991..0000000 --- a/test/test.at.js +++ /dev/null @@ -1,147 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'at' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.at ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 Complex128Array( 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( new Complex128( i, -i ) ); - } - arr = new Complex128Array( arr ); - - for ( i = -arr.length; i < arr.length; i++ ) { - v = arr.at( i ); - if ( i < 0 ) { - t.strictEqual( real( v ), arr.length + i, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), -arr.length - i, 'returns expected imaginary component for index '+i ); - } else { - t.strictEqual( real( v ), i, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), -i, 'returns expected imaginary component for index '+i ); - } - } - t.end(); -}); diff --git a/test/test.copy_within.js b/test/test.copy_within.js deleted file mode 100644 index 4463cb7..0000000 --- a/test/test.copy_within.js +++ /dev/null @@ -1,379 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isPositiveZero = require( '@stdlib/assert-is-positive-zero' ).isPrimitive; -var isNegativeZero = require( '@stdlib/assert-is-negative-zero' ).isPrimitive; -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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 complex number array', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array.prototype, 'copyWithin' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 complex number array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( 0, 3 ); - - buf = new Float64Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], 3.0, 'returns expected real for complex number 0' ); - t.strictEqual( buf[ 1 ], -3.0, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 4.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -4.0, 'returns expected imag for complex number 1' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], 2.0, 'returns expected real for complex number 2' ); - t.strictEqual( buf[ 5 ], -2.0, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 3.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -3.0, 'returns expected imag for complex number 3' ); - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( -arr.length, 3 ); - - buf = new Float64Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], 3.0, 'returns expected real for complex number 0' ); - t.strictEqual( buf[ 1 ], -3.0, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 4.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -4.0, 'returns expected imag for complex number 1' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], 2.0, 'returns expected real for complex number 2' ); - t.strictEqual( buf[ 5 ], -2.0, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 3.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -3.0, 'returns expected imag for complex number 3' ); - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( 0, -2 ); - - buf = new Float64Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], 3.0, 'returns expected real for complex number 0' ); - t.strictEqual( buf[ 1 ], -3.0, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 4.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -4.0, 'returns expected imag for complex number 1' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], 2.0, 'returns expected real for complex number 2' ); - t.strictEqual( buf[ 5 ], -2.0, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 3.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -3.0, 'returns expected imag for complex number 3' ); - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( 0, 3, arr.length ); - - buf = new Float64Array( arr.buffer ); - - // Overwritten: - t.strictEqual( buf[ 0 ], 3.0, 'returns expected real for complex number 0' ); - t.strictEqual( buf[ 1 ], -3.0, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 4.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -4.0, 'returns expected imag for complex number 1' ); - - // Remain the same: - t.strictEqual( buf[ 4 ], 2.0, 'returns expected real for complex number 2' ); - t.strictEqual( buf[ 5 ], -2.0, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 3.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -3.0, 'returns expected imag for complex number 3' ); - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( 2, 0, 2 ); - - buf = new Float64Array( arr.buffer ); - - // Remain the same: - t.strictEqual( isPositiveZero( buf[ 0 ] ), true, 'returns expected real for complex number 0' ); - t.strictEqual( isNegativeZero( buf[ 1 ] ), true, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 1.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -1.0, 'returns expected imag for complex number 1' ); - - // Overwritten: - t.strictEqual( isPositiveZero( buf[ 4 ] ), true, 'returns expected real for complex number 2' ); - t.strictEqual( isNegativeZero( buf[ 5 ] ), true, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 1.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -1.0, 'returns expected imag for complex number 3' ); - - // Remain the same: - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( 2, 0, -3 ); - - buf = new Float64Array( arr.buffer ); - - // Remain the same: - t.strictEqual( isPositiveZero( buf[ 0 ] ), true, 'returns expected real for complex number 0' ); - t.strictEqual( isNegativeZero( buf[ 1 ] ), true, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 1.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -1.0, 'returns expected imag for complex number 1' ); - - // Overwritten: - t.strictEqual( isPositiveZero( buf[ 4 ] ), true, 'returns expected real for complex number 2' ); - t.strictEqual( isNegativeZero( buf[ 5 ] ), true, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 1.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -1.0, 'returns expected imag for complex number 3' ); - - // Remain the same: - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( arr.length, 3 ); - - buf = new Float64Array( arr.buffer ); - - // Remain the same: - t.strictEqual( isPositiveZero( buf[ 0 ] ), true, 'returns expected real for complex number 0' ); - t.strictEqual( isNegativeZero( buf[ 1 ] ), true, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 1.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -1.0, 'returns expected imag for complex number 1' ); - t.strictEqual( buf[ 4 ], 2.0, 'returns expected real for complex number 2' ); - t.strictEqual( buf[ 5 ], -2.0, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 3.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -3.0, 'returns expected imag for complex number 3' ); - t.strictEqual( buf[ 8 ], 4.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -4.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { - var arr; - var buf; - - arr = [ - new Complex128( 0.0, -0.0 ), - new Complex128( 1.0, -1.0 ), - new Complex128( 2.0, -2.0 ), - new Complex128( 3.0, -3.0 ), - new Complex128( 4.0, -4.0 ) - ]; - arr = new Complex128Array( arr ); - - arr.copyWithin( 2, 0 ); - - buf = new Float64Array( arr.buffer ); - - // Remain the same: - t.strictEqual( isPositiveZero( buf[ 0 ] ), true, 'returns expected real for complex number 0' ); - t.strictEqual( isNegativeZero( buf[ 1 ] ), true, 'returns expected imag for complex number 0' ); - t.strictEqual( buf[ 2 ], 1.0, 'returns expected real for complex number 1' ); - t.strictEqual( buf[ 3 ], -1.0, 'returns expected imag for complex number 1' ); - - // Overwritten: - t.strictEqual( isPositiveZero( buf[ 4 ] ), true, 'returns expected real for complex number 2' ); - t.strictEqual( isNegativeZero( buf[ 5 ] ), true, 'returns expected imag for complex number 2' ); - t.strictEqual( buf[ 6 ], 1.0, 'returns expected real for complex number 3' ); - t.strictEqual( buf[ 7 ], -1.0, 'returns expected imag for complex number 3' ); - t.strictEqual( buf[ 8 ], 2.0, 'returns expected real for complex number 4' ); - t.strictEqual( buf[ 9 ], -2.0, 'returns expected imag for complex number 4' ); - - t.end(); -}); diff --git a/test/test.entries.js b/test/test.entries.js deleted file mode 100644 index 3a3320a..0000000 --- a/test/test.entries.js +++ /dev/null @@ -1,249 +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. -*/ - -'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 isComplex128 = require( '@stdlib/assert-is-complex128' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'entries' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.entries ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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; - var j; - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( buf ); - - it = arr.entries(); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - j = 0; - for ( i = 0; i < arr.length; i++ ) { - v = it.next(); - t.strictEqual( isArray( v.value ), true, 'returns an array' ); - t.strictEqual( v.value[ 0 ], i, 'returns an index' ); - t.strictEqual( isComplex128( v.value[ 1 ] ), true, 'returns a complex number' ); - t.strictEqual( real( v.value[ 1 ] ), buf[ j ], 'returns expected real component' ); - t.strictEqual( imag( v.value[ 1 ] ), buf[ j+1 ], 'returns expected imaginary component' ); - t.strictEqual( typeof v.done, 'boolean', 'returns a boolean' ); - - j += 2; // stride - } - 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.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( buf ); - - it = arr.entries(); - - v = it.next(); - t.strictEqual( real( v.value[ 1 ] ), buf[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v.value[ 1 ] ), buf[ 1 ], 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( real( v.value[ 1 ] ), buf[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v.value[ 1 ] ), buf[ 3 ], '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.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( buf ); - - it = arr.entries(); - - v = it.next(); - t.strictEqual( real( v.value[ 1 ] ), buf[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v.value[ 1 ] ), buf[ 1 ], 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( real( v.value[ 1 ] ), buf[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v.value[ 1 ] ), buf[ 3 ], '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 Complex128Array; - var arr; - var buf; - var it1; - var it2; - var v1; - var v2; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( 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 an object' ); - 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( real( v1[ 1 ] ), real( v2[ 1 ] ), 'returns expected value' ); - t.strictEqual( imag( v1[ 1 ] ), imag( 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 Complex128Array; - var arr; - var buf; - var it; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( buf ); - - it = arr.entries(); - t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/test.every.js b/test/test.every.js deleted file mode 100644 index 73d6691..0000000 --- a/test/test.every.js +++ /dev/null @@ -1,175 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'every' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.every ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array(); - 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 Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - bool = arr.every( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - bool = arr.every( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - bool = arr.every( predicate, ctx ); - - t.strictEqual( bool, true, '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 ( imag( v ) === real( v ) ); - } -}); diff --git a/test/test.fill.js b/test/test.fill.js deleted file mode 100644 index 720d737..0000000 --- a/test/test.fill.js +++ /dev/null @@ -1,283 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float64Array = require( '@stdlib/array-float64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'fill' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.fill ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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, new Complex128( 1.0, 1.0 ) ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a complex number', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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( 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 Complex128Array( 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( new Complex128( 1.0, 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 Complex128Array( 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( new Complex128( 1.0, 1.0 ), 0, value ); - }; - } -}); - -tape( 'the method returns an empty array if operating on an empty complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - out = arr.fill( new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( out instanceof Complex128Array, 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 Complex128Array( 10 ); - out = arr.fill( new Complex128( 1.0, 1.0 ) ); - - 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 expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ) ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, '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 expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ), 1 ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, '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 expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ), 0, 2 ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports negative indices', function test( t ) { - var expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ), -3, -1 ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, '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 expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ), -10 ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, '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 expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ), 1, 10 ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, '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 expected; - var arr; - - arr = new Complex128Array( 3 ); - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr.fill( new Complex128( 1.0, 1.0 ), 2, 1 ); - - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.filter.js b/test/test.filter.js deleted file mode 100644 index 2aa34fe..0000000 --- a/test/test.filter.js +++ /dev/null @@ -1,190 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'filter' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.filter ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - out = arr.filter( predicate ); - - t.strictEqual( out.length, 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) > 0 && imag( v ) < 0 ); - } -}); - -tape( 'the method returns a new complex number array containing only those elements which satisfy a test condition', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, 2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 3.0, -3.0 ] ); - actual = arr.filter( predicate ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) > 0 && imag( v ) < 0 ); - } -}); - -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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.filter( predicate ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) > 0 && imag( v ) < 0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var expected; - var actual; - var arr; - var ctx; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, 2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 3.0, -3.0 ] ); - ctx = { - 'count': 0 - }; - actual = arr.filter( predicate, ctx ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, '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 ( real( v ) > 0 && imag( v ) < 0 ); - } -}); diff --git a/test/test.find.js b/test/test.find.js deleted file mode 100644 index 3800d5c..0000000 --- a/test/test.find.js +++ /dev/null @@ -1,177 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'find' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.find ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var z; - - arr = new Complex128Array(); - z = arr.find( predicate ); - - t.strictEqual( z, 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 z; - - arr = new Complex128Array( [ 1.0, 1.0, 2.0, -2.0 ] ); - z = arr.find( predicate ); - - t.strictEqual( real( z ), 2.0, 'returns expected value' ); - t.strictEqual( imag( z ), -2.0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === -imag( v ) ); - } -}); - -tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { - var arr; - var z; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - z = arr.find( predicate ); - - t.strictEqual( z, void 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var z; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, 3.0 ] ); - z = arr.find( predicate, ctx ); - - t.strictEqual( real( z ), 3.0, 'returns expected value' ); - t.strictEqual( imag( z ), 3.0, '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 ( imag( v ) === real( v ) ); - } -}); diff --git a/test/test.find_index.js b/test/test.find_index.js deleted file mode 100644 index daf42da..0000000 --- a/test/test.find_index.js +++ /dev/null @@ -1,175 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'findIndex' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.findIndex ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var idx; - - arr = new Complex128Array(); - 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 Complex128Array( [ 1.0, 1.0, 2.0, -2.0 ] ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, 1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === -imag( v ) ); - } -}); - -tape( 'the method returns `-1` if all elements fail a test', function test( t ) { - var arr; - var idx; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - idx = arr.findIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var idx; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, 3.0 ] ); - 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 ( imag( v ) === real( v ) ); - } -}); diff --git a/test/test.find_last.js b/test/test.find_last.js deleted file mode 100644 index 1426ea4..0000000 --- a/test/test.find_last.js +++ /dev/null @@ -1,177 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'findLast' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.findLast ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var z; - - arr = new Complex128Array(); - z = arr.findLast( predicate ); - - t.strictEqual( z, 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 z; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - z = arr.findLast( predicate ); - - t.strictEqual( real( z ), 2.0, 'returns expected value' ); - t.strictEqual( imag( z ), -2.0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === -imag( v ) ); - } -}); - -tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { - var arr; - var z; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - z = arr.findLast( predicate ); - - t.strictEqual( z, void 0, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var z; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, 3.0 ] ); - z = arr.findLast( predicate, ctx ); - - t.strictEqual( real( z ), 3.0, 'returns expected value' ); - t.strictEqual( imag( z ), 3.0, '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 ( imag( v ) === real( v ) ); - } -}); diff --git a/test/test.find_last_index.js b/test/test.find_last_index.js deleted file mode 100644 index 982565e..0000000 --- a/test/test.find_last_index.js +++ /dev/null @@ -1,175 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'findLastIndex' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.findLastIndex ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var idx; - - arr = new Complex128Array(); - 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, 1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === -imag( v ) ); - } -}); - -tape( 'the method returns `-1` if all elements fail a test', function test( t ) { - var arr; - var idx; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - idx = arr.findLastIndex( predicate ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - var idx; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, -1.0, 2.0, 2.0, 3.0, 3.0 ] ); - idx = arr.findLastIndex( predicate, ctx ); - - t.strictEqual( idx, 2, '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 ( imag( v ) === real( v ) ); - } -}); diff --git a/test/test.for_each.js b/test/test.for_each.js deleted file mode 100644 index db22551..0000000 --- a/test/test.for_each.js +++ /dev/null @@ -1,176 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var isComplex128 = require( '@stdlib/assert-is-complex128' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'forEach' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.forEach ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( !isComplex128( v ) ) { - t.fail( 'should be a complex 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - - arr = new Complex128Array(); - 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 Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = arr.forEach( fcn ); - - t.strictEqual( out, void 0, 'returns expected value' ); - t.end(); - - function fcn( v ) { - if ( !isComplex128( v ) ) { - t.fail( 'should be a complex number' ); - } - } -}); - -tape( 'the method invokes a provided function for each element in an array', function test( t ) { - var expected; - var arr; - - expected = []; - arr = new Complex128Array( [ 1.0, 1.0, 2.0, -2.0 ] ); - arr.forEach( fcn ); - expected = new Complex128Array( expected ); - - t.deepEqual( reinterpret128( expected, 0 ), reinterpret128( arr, 0 ), 'returns expected value' ); - t.end(); - - function fcn( v ) { - expected.push( v ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, 3.0 ] ); - arr.forEach( fcn, ctx ); - - t.strictEqual( ctx.count, 3, '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 35f4b6f..0000000 --- a/test/test.from.js +++ /dev/null @@ -1,1254 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `from` method for creating a complex number array from an array-like object or iterable', function test( t ) { - var arr; - - t.strictEqual( hasOwnProp( Complex128Array, 'from' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.from ), true, 'has method' ); - - arr = Complex128Array.from( [] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - 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 Complex128Array.from.call( value, [] ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex array constructor', function test( t ) { - var values; - var i; - - values = [ - Complex128, - 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 Complex128Array.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 Complex128Array.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 Complex128Array.from( value, clbk ); - }; - } - - function clbk() { - return [ 1.0, 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 Complex128Array.from( value, clbk, {} ); - }; - } - - function clbk() { - return [ 1.0, 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 Complex128Array.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 Complex128Array.from( [], value, {} ); - }; - } -}); - -tape( 'the method returns a complex number array', function test( t ) { - var arr; - var z; - var v; - - // Generic array: - arr = Complex128Array.from( [] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Generic array containing complex numbers: - arr = Complex128Array.from( [ new Complex128( 1.0, 1.0 ) ] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = Complex128Array.from( [ z, 1.0 ] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = Complex128Array.from( [ 1.0, z ] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // Typed array: - arr = Complex128Array.from( new Float64Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Float64Array( [ 1.0, 1.0 ] ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // Complex typed array: - arr = Complex128Array.from( new Complex64Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Complex64Array( [ 1.0, 1.0 ] ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Complex128Array.from( new Complex128Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Complex128Array( [ 1.0, 1.0 ] ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - t.end(); - - function valueOf( z ) { - return function valueOf() { - return realf( z ); - }; - } -}); - -tape( 'the method returns a complex number array (iterable)', function test( t ) { - var Complex128Array; - var iter1; - var iter2; - var arr; - var v; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter1 = { - 'next': next1, - 'i': 0, - 'N': 4 - }; - arr = Complex128Array.from( createIterable( iter1 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, iter1.N, 'returns expected value' ); - - iter2 = { - 'next': next2, - 'i': 0, - 'N': 4 - }; - arr = Complex128Array.from( createIterable( iter2 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, iter2.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 next1() { - iter1.i += 1; - if ( iter1.i <= iter1.N ) { - return { - 'value': [ 1.0, 1.0 ] - }; - } - return { - 'done': true - }; - } - - function next2() { - iter2.i += 1; - if ( iter2.i <= iter2.N ) { - return { - 'value': new Complex128( 1.0, 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 z; - var v; - - // Generic array: - arr = Complex128Array.from( [], clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Generic array containing complex numbers: - arr = Complex128Array.from( [ new Complex128( 1.0, 1.0 ) ], clbk2 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Complex128Array.from( [ new Complex128( 1.0, 1.0 ) ], clbk3a ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = Complex128Array.from( [ z, 1.0 ], clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = Complex128Array.from( [ 1.0, z ], clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // Typed array: - arr = Complex128Array.from( new Float64Array( 0 ), clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Float64Array( [ 1.0, 1.0 ] ), clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // Complex typed array: - arr = Complex128Array.from( new Complex64Array( 0 ), clbk3a ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Complex64Array( [ 1.0, 1.0 ] ), clbk3a ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Complex128Array.from( new Complex64Array( 0 ), clbk3b ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Complex64Array( [ 1.0, 1.0 ] ), clbk3b ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Complex128Array.from( new Complex128Array( 0 ), clbk4a ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Complex128Array( [ 1.0, 1.0 ] ), clbk4a ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = Complex128Array.from( new Complex128Array( 0 ), clbk4b ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = Complex128Array.from( new Complex128Array( [ 1.0, 1.0 ] ), clbk4b ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - t.end(); - - function valueOf( z ) { - return function valueOf() { - return realf( z ); - }; - } - - function clbk1( v ) { - return v; - } - - function clbk2() { - return [ 1.0, 1.0 ]; - } - - function clbk3a( v ) { - return new Complex128( realf(v)*2.0, imagf(v)*2.0 ); - } - - function clbk3b( v ) { - return [ realf(v)*2.0, imagf(v)*2.0 ]; - } - - function clbk4a( v ) { - return new Complex128( real(v)*2.0, imag(v)*2.0 ); - } - - function clbk4b( v ) { - return [ real(v)*2.0, imag(v)*2.0 ]; - } -}); - -tape( 'the method supports providing a "map" function which is invoked for each iterated value', function test( t ) { - var Complex128Array; - var iter1; - var iter2; - var arr; - var v; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter1 = { - 'next': next1, - 'i': 0, - 'N': 4 - }; - arr = Complex128Array.from( createIterable( iter1 ), clbk1 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, iter1.N, 'returns expected value' ); - - iter2 = { - 'next': next2, - 'i': 0, - 'N': 4 - }; - arr = Complex128Array.from( createIterable( iter2 ), clbk2 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, iter2.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 next1() { - iter1.i += 1; - if ( iter1.i <= iter1.N ) { - return { - 'value': [ 1.0, 1.0 ] - }; - } - return { - 'done': true - }; - } - - function clbk1( v ) { - v[ 0 ] += 1.0; - v[ 1 ] += 1.0; - return v; - } - - function next2() { - iter2.i += 1; - if ( iter2.i <= iter2.N ) { - return { - 'value': new Complex128( 1.0, 1.0 ) - }; - } - return { - 'done': true - }; - } - - function clbk2( v ) { - return new Complex128( real(v)*2.0, imag(v)*2.0 ); - } -}); - -tape( 'the method supports providing a `this` context for a provided map function', function test( t ) { - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - arr = Complex128Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1, ctx ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - t.strictEqual( ctx.count, 4, 'returns expected value' ); - - ctx = { - 'count': 0 - }; - arr = [ new Complex128( 1.0, 1.0 ), new Complex128( -1.0, -1.0 ) ]; - arr = Complex128Array.from( arr, clbk2, ctx ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - t.strictEqual( ctx.count, 2, 'returns expected value' ); - - t.end(); - - function clbk1( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v; - } - - function clbk2( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return new Complex128( real(v)*2.0, imag(v)*2.0 ); - } -}); - -tape( 'the method supports providing a `this` context for a provided map function (iterable)', function test( t ) { - var Complex128Array; - var iter; - var ctx; - var arr; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter = { - 'next': next, - 'i': 0, - 'N': 4 - }; - ctx = { - 'count': 0 - }; - - arr = Complex128Array.from( createIterable( iter ), clbk, ctx ); - t.strictEqual( arr instanceof Complex128Array, 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, 1.0 ] - }; - } - return { - 'done': true - }; - } - - function clbk( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - v[ 0 ] += 1.0; - v[ 1 ] += 1.0; - return v; - } -}); - -tape( 'the method throws an error if provided a generic array-like object having an odd length', function test( t ) { - var values; - var i; - - values = [ - [ 1, 2, 3 ], - new Float64Array( [ 1, 2, 3 ] ), - { - 'length': 3, - '0': 1, - '1': 2, - '2': 3 - }, - [ new Complex128( 1.0, 1.0 ), 1.0, 1.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an array-like object having a length equal to '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return Complex128Array.from( value ); - }; - } -}); - -tape( 'the method throws an error if provided a generic array-like object having an odd length (clbk)', function test( t ) { - var values; - var i; - - values = [ - [ 1, 2, 3 ], - new Float64Array( [ 1, 2, 3 ] ), - { - 'length': 3, - '0': 1, - '1': 2, - '2': 3 - }, - [ new Complex128( 1.0, 1.0 ), 1.0, 1.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an array-like object having a length equal to '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function clbk() { - return [ 1.0, 1.0 ]; - } -}); - -tape( 'the method throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@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 Complex128Array.from( value ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the method throws an error if provided a non-iterable object (ES2015+)', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@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 Complex128Array.from( value ); - }; - } - - function hasSupport() { - return true; - } - - function nonIterable1() { - return null; - } - - function nonIterable2() { - return {}; - } -}); - -tape( 'the method throws an error if provided an iterable object which does not return complex numbers or arrays of real and imaginary components', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - { - '__SYMBOL_ITERATOR__': createIterable( next1 ) - }, - { - '__SYMBOL_ITERATOR__': createIterable( next2 ) - } - ]; - 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 Complex128Array.from( value ); - }; - } - - function hasSupport() { - return true; - } - - function createIterable( next ) { - return iterable; - - function iterable() { - return { - 'next': next - }; - } - } - - function next1() { - return { - 'value': 1.0 - }; - } - - function next2() { - return { - 'value': '1.0 + 1.0i' - }; - } -}); - -tape( 'the method throws an error if provided an iterable object which does not return an array-like object containing at least two elements', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - { - '__SYMBOL_ITERATOR__': createIterable( next1 ) - }, - { - '__SYMBOL_ITERATOR__': createIterable( next2 ) - } - ]; - 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 Complex128Array.from( value ); - }; - } - - function hasSupport() { - return true; - } - - function createIterable( next ) { - return iterable; - - function iterable() { - return { - 'next': next - }; - } - } - - function next1() { - return { - 'value': [] - }; - } - - function next2() { - return { - 'value': [ 1.0 ] - }; - } -}); - -tape( 'the method throws an error if provided a complex number source array and a "map" function which does not return complex numbers or arrays of real and imaginary components (collection)', function test( t ) { - var values; - var clbks; - var i; - - values = [ - [ new Complex128( 1.0, 1.0 ) ], - [ new Complex128( 1.0, 1.0 ), new Complex128( -1.0, -1.0 ) ] - ]; - clbks = [ - clbk1, - clbk2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( value, clbk ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function clbk1() { - return 1.0; - } - - function clbk2() { - return {}; - } -}); - -tape( 'the method throws an error if provided a complex number source array and a "map" function which does not return an array containing at least two elements (collection)', function test( t ) { - var values; - var clbks; - var i; - - values = [ - [ new Complex128( 1.0, 1.0 ) ], - [ new Complex128( 1.0, 1.0 ), new Complex128( -1.0, -1.0 ) ] - ]; - clbks = [ - clbk1, - clbk2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( value, clbk ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function clbk1() { - return []; - } - - function clbk2() { - return [ 1.0 ]; - } -}); - -tape( 'the method throws an error if provided a complex number source array and a "map" function which does not return complex numbers or arrays of real and imaginary components (complex array)', function test( t ) { - var values; - var clbks; - var i; - - values = [ - new Complex128Array( [ 1.0, 1.0 ] ), - new Complex128Array( [ 1.0, 1.0, -1.0, -1.0 ] ) - ]; - clbks = [ - clbk1, - clbk2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( value, clbk ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function clbk1() { - return 1.0; - } - - function clbk2() { - return {}; - } -}); - -tape( 'the method throws an error if provided a complex number source array and a "map" function which does not return an array containing at least two elements (complex array)', function test( t ) { - var values; - var clbks; - var i; - - values = [ - new Complex128Array( [ 1.0, 1.0 ] ), - new Complex128Array( [ 1.0, 1.0, -1.0, -1.0 ] ) - ]; - clbks = [ - clbk1, - clbk2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( value, clbk ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function clbk1() { - return []; - } - - function clbk2() { - return [ 1.0 ]; - } -}); - -tape( 'the method throws an error if provided a "map" function which does not return complex numbers or arrays of real and imaginary components (iterable)', function test( t ) { - var Complex128Array; - var values; - var clbks; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - { - '__SYMBOL_ITERATOR__': createIterable( next1 ) - }, - { - '__SYMBOL_ITERATOR__': createIterable( next2 ) - } - ]; - clbks = [ - clbk1, - clbk2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( value, clbk ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function hasSupport() { - return true; - } - - function createIterable( next ) { - return iterable; - - function iterable() { - return { - 'next': next - }; - } - } - - function next1() { - return { - 'value': [ 1.0, 1.0 ] - }; - } - - function clbk1() { - return 1.0; - } - - function next2() { - return { - 'value': new Complex128( 1.0, 1.0 ) - }; - } - - function clbk2() { - return '1.0 - 1.0j'; - } -}); - -tape( 'the method throws an error if provided a "map" function which does not return an array containing at least two elements (iterable)', function test( t ) { - var Complex128Array; - var values; - var clbks; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - { - '__SYMBOL_ITERATOR__': createIterable( next1 ) - }, - { - '__SYMBOL_ITERATOR__': createIterable( next2 ) - } - ]; - clbks = [ - clbk1, - clbk2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( value, clbk ) { - return function badValue() { - return Complex128Array.from( value, clbk ); - }; - } - - function hasSupport() { - return true; - } - - function createIterable( next ) { - return iterable; - - function iterable() { - return { - 'next': next - }; - } - } - - function next1() { - return { - 'value': [ 1.0, 1.0 ] - }; - } - - function clbk1() { - return []; - } - - function next2() { - return { - 'value': new Complex128( 1.0, 1.0 ) - }; - } - - function clbk2() { - return [ 1.0 ]; - } -}); diff --git a/test/test.get.js b/test/test.get.js deleted file mode 100644 index dabbfd3..0000000 --- a/test/test.get.js +++ /dev/null @@ -1,138 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float32-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `get` method for returning an array element', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array.prototype, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.get ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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.get.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 Complex128Array( 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.get( 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 Complex128Array( 10 ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( 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( new Complex128( i, -i ) ); - } - arr = new Complex128Array( arr ); - - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), i, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), -i, 'returns expected imaginary component for index '+i ); - } - t.end(); -}); diff --git a/test/test.includes.js b/test/test.includes.js deleted file mode 100644 index d797297..0000000 --- a/test/test.includes.js +++ /dev/null @@ -1,242 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'includes' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.includes ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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, new Complex128( 10.0, 10.0 ) ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a complex number', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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( 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 Complex128Array( 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( new Complex128( 1.0, 1.0 ), value ); - }; - } -}); - -tape( 'the method returns `false` if operating on an empty complex number array', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array(); - bool = arr.includes( new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `false` if a complex number is not found', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array( 10 ); - bool = arr.includes( new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `true` if an array contains a specified complex number', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array( 10 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - bool = arr.includes( new Complex128( 2.0, 2.0 ) ); - - 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 Complex128Array( 10 ); - bool = arr.includes( new Complex128( 1.0, 1.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 Complex128Array( 10 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - - bool = arr.includes( new Complex128( 2.0, 2.0 ), 0 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( new Complex128( 2.0, 2.0 ), 2 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( new Complex128( 3.0, 3.0 ), 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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 2.0, 2.0 ], 4 ); - - bool = arr.includes( new Complex128( 2.0, 2.0 ), -5 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( new Complex128( 4.0, 4.0 ), -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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 2.0, 2.0 ], 4 ); - - bool = arr.includes( new Complex128( 2.0, 2.0 ), -10 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = arr.includes( new Complex128( 4.0, 4.0 ), -10 ); - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.index_of.js b/test/test.index_of.js deleted file mode 100644 index 4addb27..0000000 --- a/test/test.index_of.js +++ /dev/null @@ -1,244 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is an `indexOf` method', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array.prototype, 'indexOf' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.indexOf ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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, new Complex128( 1.0, 1.0 ) ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a complex number', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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( 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 Complex128Array( 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( new Complex128( 1.0, 1.0 ), value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty complex number array', function test( t ) { - var arr; - var idx; - - arr = new Complex128Array(); - idx = arr.indexOf( new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if a complex number is not found', function test( t ) { - var idx; - var arr; - - arr = new Complex128Array( 10 ); - idx = arr.indexOf( new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns the index of the first match if a complex number is found', function test( t ) { - var idx; - var arr; - - arr = new Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 5.0, 5.0 ], 4 ); - idx = arr.indexOf( new Complex128( 2.0, 2.0 ) ); - - 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 Complex128Array( 10 ); - idx = arr.indexOf( new Complex128( 1.0, 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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 4.0, 4.0 ], 4 ); - - idx = arr.indexOf( new Complex128( 2.0, 2.0 ), 0 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( new Complex128( 2.0, 2.0 ), 2 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = arr.indexOf( new Complex128( 3.0, 3.0 ), 3 ); - 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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 2.0, 2.0 ], 4 ); - - idx = arr.indexOf( new Complex128( 2.0, 2.0 ), -5 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( new Complex128( 4.0, 4.0 ), -2 ); - 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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 2.0, 2.0 ], 4 ); - - idx = arr.indexOf( new Complex128( 2.0, 2.0 ), -10 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.indexOf( new Complex128( 4.0, 4.0 ), -10 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.join.js b/test/test.join.js deleted file mode 100644 index 27ea18c..0000000 --- a/test/test.join.js +++ /dev/null @@ -1,162 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'join' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.join ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 Complex128Array(); - str = arr.join(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a complex number array with elements separated by a separator', function test( t ) { - var expected; - var str; - var arr; - - arr = new Complex128Array( [ 1, 2, -3, -4 ] ); - expected = '1 + 2i@-3 - 4i'; - - str = arr.join( '@' ); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a complex number array with elements separated by a separator (single element)', function test( t ) { - var expected; - var str; - var arr; - - arr = new Complex128Array( [ 1, 2 ] ); - expected = '1 + 2i'; - - str = arr.join(); - - t.strictEqual( str, expected, 'returns expected value' ); - - arr = new Complex128Array( [ 1, 2 ] ); - expected = '1 + 2i'; - - str = arr.join( '@' ); - - t.strictEqual( str, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if method invoked without a separator argument, the method returns a string representation of a complex number array with elements separated by a comma', function test( t ) { - var expected; - var str; - var arr; - - arr = new Complex128Array( [ 1, 2, -3, -4 ] ); - expected = '1 + 2i,-3 - 4i'; - - 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 4fefd4e..0000000 --- a/test/test.js +++ /dev/null @@ -1,961 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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 Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var arr = new Complex128Array( 0 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( 0 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (no argument)', function test( t ) { - var arr = new Complex128Array(); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (no argument, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor(); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (length)', function test( t ) { - var arr = new Complex128Array( 10 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (length, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( 10 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (array)', function test( t ) { - var arr = new Complex128Array( [] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (array, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( [] ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (typed array)', function test( t ) { - var arr = new Complex128Array( new Float64Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (typed array, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( new Float64Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (complex typed array)', function test( t ) { - var arr = new Complex128Array( new Complex128Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (complex typed array, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( new Complex128Array( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (iterable)', function test( t ) { - var Complex128Array; - var arr; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - arr = new Complex128Array( createIterable() ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - 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 128-bit complex number array (iterable, no new)', function test( t ) { - var ctor; - var arr; - - ctor = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - arr = ctor( createIterable() ); - t.strictEqual( arr instanceof ctor, true, 'returns an instance' ); - - 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 128-bit complex number array (ArrayBuffer)', function test( t ) { - var arr = new Complex128Array( new ArrayBuffer( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (ArrayBuffer, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( new ArrayBuffer( 0 ) ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (ArrayBuffer, byte offset)', function test( t ) { - var arr = new Complex128Array( new ArrayBuffer( 16 ), 16 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (ArrayBuffer, byte offset, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( new ArrayBuffer( 16 ), 16 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (ArrayBuffer, byte offset, length)', function test( t ) { - var arr = new Complex128Array( new ArrayBuffer( 16 ), 16, 0 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor returns a 128-bit complex number array (ArrayBuffer, byte offset, length, no new)', function test( t ) { - var ctor; - var arr; - - ctor = Complex128Array; - - arr = ctor( new ArrayBuffer( 16 ), 16, 0 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - t.end(); -}); - -tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( Complex128Array.BYTES_PER_ELEMENT, 16, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array, 'name' ), true, 'has property' ); - t.strictEqual( Complex128Array.name, 'Complex128Array', '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( Complex128Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( Complex128Array.prototype.BYTES_PER_ELEMENT, 16, 'returns expected value' ); - - arr = new Complex128Array( 0 ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 16, '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 Complex128Array( 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 Complex128Array( 0 ); - v = arr.byteLength; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( new ArrayBuffer( 128 ), 16 ); - v = arr.byteLength; - t.strictEqual( v, 112, 'returns expected value' ); - - arr = new Complex128Array( new ArrayBuffer( 128 ), 128 ); - 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 Complex128Array( 0 ); - v = arr.byteOffset; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( new ArrayBuffer( 128 ), 64 ); - v = arr.byteOffset; - t.strictEqual( v, 64, 'returns expected value' ); - - arr = new Complex128Array( new ArrayBuffer( 128 ), 128 ); - v = arr.byteOffset; - t.strictEqual( v, 128, '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 z; - var v; - - // No arguments: - arr = new Complex128Array(); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - // Explicit array length: - arr = new Complex128Array( 0 ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( 10 ); - v = arr.length; - t.strictEqual( v, 10, 'returns expected value' ); - - // Generic array: - arr = new Complex128Array( [] ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Generic array containing complex numbers: - arr = new Complex128Array( [ new Complex128( 1.0, 1.0 ) ] ); - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = new Complex128Array( [ z, 1.0 ] ); - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = new Complex128Array( [ 1.0, z ] ); - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // Typed array: - arr = new Complex128Array( new Float64Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( new Float64Array( [ 1.0, 1.0 ] ) ); - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // Complex typed array: - arr = new Complex128Array( new Complex64Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( new Complex64Array( [ 1.0, 1.0 ] ) ); - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - arr = new Complex128Array( new Complex128Array( 0 ) ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( new Complex128Array( [ 1.0, 1.0 ] ) ); - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - // ArrayBuffer: - arr = new Complex128Array( new ArrayBuffer( 128 ), 64 ); - v = arr.length; - t.strictEqual( v, 4, 'returns expected value' ); - - arr = new Complex128Array( new ArrayBuffer( 128 ), 128 ); - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - arr = new Complex128Array( new ArrayBuffer( 128 ), 64, 2 ); - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - t.end(); - - function valueOf( z ) { - return function valueOf() { - return real( z ); - }; - } -}); - -tape( 'the constructor returns an instance having a `length` property for returning the number of array elements (iterable)', function test( t ) { - var Complex128Array; - var iter1; - var iter2; - var arr; - var v; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - iter1 = { - 'next': next1, - 'i': 0, - 'N': 4 - }; - arr = new Complex128Array( createIterable( iter1 ) ); - v = arr.length; - t.strictEqual( v, iter1.N, 'returns expected value' ); - - iter2 = { - 'next': next2, - 'i': 0, - 'N': 4 - }; - arr = new Complex128Array( createIterable( iter2 ) ); - v = arr.length; - t.strictEqual( v, iter2.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 next1() { - iter1.i += 1; - if ( iter1.i <= iter1.N ) { - return { - 'value': [ 1.0, 1.0 ] - }; - } - return { - 'done': true - }; - } - - function next2() { - iter2.i += 1; - if ( iter2.i <= iter2.N ) { - return { - 'value': new Complex128( 1.0, 1.0 ) - }; - } - return { - 'done': true - }; - } -}); - -tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 16', function test( t ) { - var values; - var i; - - values = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 9, - 24, - 74, - 801 - ]; - 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 Complex128Array( new ArrayBuffer( value ) ); - }; - } -}); - -tape( 'the constructor throws an error if provided an array-like object having an odd length', function test( t ) { - var values; - var i; - - values = [ - [ 1, 2, 3 ], - new Float64Array( [ 1, 2, 3 ] ), - { - 'length': 3, - '0': 1, - '1': 2, - '2': 3 - }, - [ new Complex128( 1.0, 1.0 ), 1.0, 1.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an array-like object having a length equal to '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return new Complex128Array( value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@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 Complex128Array( value ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the constructor throws an error if provided a non-iterable object (ES2015+)', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@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 Complex128Array( value ); - }; - } - - function hasSupport() { - return true; - } - - function nonIterable1() { - return null; - } - - function nonIterable2() { - return {}; - } -}); - -tape( 'the constructor throws an error if provided an iterable object which does not return complex numbers or arrays of real and imaginary components', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - { - '__SYMBOL_ITERATOR__': createIterable( next1 ) - }, - { - '__SYMBOL_ITERATOR__': createIterable( next2 ) - } - ]; - 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 Complex128Array( value ); - }; - } - - function hasSupport() { - return true; - } - - function createIterable( next ) { - return iterable; - - function iterable() { - return { - 'next': next - }; - } - } - - function next1() { - return { - 'value': 1.0 - }; - } - - function next2() { - return { - 'value': '1.0 + 1.0i' - }; - } -}); - -tape( 'the constructor throws an error if provided an iterable object which does not return array containing at least two elements', function test( t ) { - var Complex128Array; - var values; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__SYMBOL_ITERATOR__' - }); - - values = [ - { - '__SYMBOL_ITERATOR__': createIterable( next1 ) - }, - { - '__SYMBOL_ITERATOR__': createIterable( next2 ) - } - ]; - 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 Complex128Array( value ); - }; - } - - function hasSupport() { - return true; - } - - function createIterable( next ) { - return iterable; - - function iterable() { - return { - 'next': next - }; - } - } - - function next1() { - return { - 'value': [] - }; - } - - function next2() { - return { - 'value': [ 1.0 ] - }; - } -}); - -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 Complex128Array( 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 Complex128Array( 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 Complex128Array( new ArrayBuffer( 128 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 16', function test( t ) { - var values; - var i; - - values = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 9, - 24, - 65, - 78, - 801 - ]; - 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 Complex128Array( new ArrayBuffer( 1024 ), value ); - }; - } -}); - -tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 16', function test( t ) { - var values; - var i; - - values = [ - 8, - 16, - 24, - 32, - 48, - 56, - 64, - 72, - 80, - 88 - ]; - 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 Complex128Array( new ArrayBuffer( 102 ), 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 Complex128Array( new ArrayBuffer( 128 ), 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 = [ - 16, - 24, - 32, - 48 - ]; - 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 Complex128Array( new ArrayBuffer( 100 ), value, 1e3 ); - }; - } -}); diff --git a/test/test.keys.js b/test/test.keys.js deleted file mode 100644 index 6c0df8a..0000000 --- a/test/test.keys.js +++ /dev/null @@ -1,261 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'keys' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.keys ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - expected = [ - { - 'value': 0, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - it = arr.keys(); - - t.strictEqual( typeof it, 'object', 'returns an object' ); - 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 Complex128Array( [] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - it = arr.keys(); - - t.strictEqual( typeof it, 'object', 'returns an object' ); - 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - 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 Complex128Array; - var arr; - var buf; - var it1; - var it2; - var v1; - var v2; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( 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 an object' ); - 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 Complex128Array; - var arr; - var buf; - var it; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( buf ); - - it = arr.keys(); - t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/test.last_index_of.js b/test/test.last_index_of.js deleted file mode 100644 index 31b8f89..0000000 --- a/test/test.last_index_of.js +++ /dev/null @@ -1,232 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `lastIndexOf` method', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array.prototype, 'lastIndexOf' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.lastIndexOf ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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, new Complex128( 1.0, 1.0 ) ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a complex number', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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( 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 Complex128Array( 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( new Complex128( 1.0, 1.0 ), value ); - }; - } -}); - -tape( 'the method returns `-1` if operating on an empty complex number array', function test( t ) { - var arr; - var idx; - - arr = new Complex128Array(); - idx = arr.lastIndexOf( new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns `-1` if a complex number is not found', function test( t ) { - var idx; - var arr; - - arr = new Complex128Array( 10 ); - idx = arr.lastIndexOf( new Complex128( 1.0, 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 Complex128Array( 10 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - idx = arr.lastIndexOf( new Complex128( 2.0, 2.0 ) ); - - t.strictEqual( idx, 3, 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports specifying a starting search index', function test( t ) { - var idx; - var arr; - - arr = new Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 3.0, 3.0 ], 4 ); - - idx = arr.lastIndexOf( new Complex128( 2.0, 2.0 ), 4 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = arr.lastIndexOf( new Complex128( 2.0, 2.0 ), 2 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.lastIndexOf( new Complex128( 3.0, 3.0 ), 1 ); - 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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 2.0, 2.0 ], 4 ); - - idx = arr.lastIndexOf( new Complex128( 2.0, 2.0 ), -3 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = arr.lastIndexOf( new Complex128( 3.0, 3.0 ), -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 Complex128Array( 5 ); - arr.set( [ 1.0, 1.0 ], 0 ); - arr.set( [ 2.0, 2.0 ], 1 ); - arr.set( [ 3.0, 3.0 ], 2 ); - arr.set( [ 2.0, 2.0 ], 3 ); - arr.set( [ 2.0, 2.0 ], 4 ); - - idx = arr.lastIndexOf( new Complex128( 2.0, 2.0 ), 10 ); - t.strictEqual( idx, 4, 'returns expected value' ); - - idx = arr.lastIndexOf( new Complex128( 4.0, 4.0 ), 10 ); - t.strictEqual( idx, -1, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.map.js b/test/test.map.js deleted file mode 100644 index 4607d04..0000000 --- a/test/test.map.js +++ /dev/null @@ -1,231 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var identity = require( '@stdlib/utils-identity-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'map' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.map ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - out = arr.map( identity ); - - t.strictEqual( instanceOf( out, Complex128Array ), 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 complex number array containing elements which are the result of a callback function', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0 ] ); - actual = arr.map( scale ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - t.end(); - - function scale( v ) { - return new Complex128( real( v )*2.0, imag( v )*2.0 ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var expected; - var actual; - var arr; - var ctx; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 3.0, -3.0, 6.0, -6.0, 9.0, -9.0 ] ); - ctx = { - 'count': 0 - }; - actual = arr.map( scale, ctx ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - t.end(); - - function scale( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return new Complex128( real( v )*3.0, imag( v )*3.0 ); - } -}); - -tape( 'the method supports a map function which returns a two-element array containing a real and an imaginary component', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0 ] ); - actual = arr.map( scale ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - t.end(); - - function scale( v ) { - return [ real( v )*2.0, imag( v )*2.0 ]; - } -}); - -tape( 'the method throws an error if provided a map function which does not return a complex number or an array of length 2 containing real and imaginary components', function test( t ) { - var clbks; - var arr; - var i; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - clbks = [ - clbk1, - clbk2, - clbk3, - clbk4, - clbk5 - ]; - for ( i = 0; i < clbks.length; i++ ) { - t.throws( badValue( clbks[i] ), TypeError, 'throws an error when provided callback '+i ); - } - t.end(); - - function badValue( clbk ) { - return function badValue() { - return arr.map( clbk ); - }; - } - - function clbk1() { - return 1.0; - } - - function clbk2() { - return {}; - } - - function clbk3() { - return [ 1.0, 2.0, 3.0 ]; - } - - function clbk4() { - return []; - } - - function clbk5() { - return [ 1.0 ]; - } -}); diff --git a/test/test.of.js b/test/test.of.js deleted file mode 100644 index 60c3d69..0000000 --- a/test/test.of.js +++ /dev/null @@ -1,149 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `of` method for creating a complex number array from a variable number of arguments', function test( t ) { - var arr; - - t.strictEqual( hasOwnProp( Complex128Array, 'of' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.of ), true, 'has method' ); - - arr = Complex128Array.of(); - t.strictEqual( arr instanceof Complex128Array, true, 'returns an instance' ); - - 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 Complex128Array.of.call( value, 1.0, 1.0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex array constructor', function test( t ) { - var values; - var i; - - values = [ - Complex128, - 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 Complex128Array.of.call( value, 1.0, 1.0 ); - }; - } -}); - -tape( 'the method returns a complex number array', function test( t ) { - var arr; - var z; - var v; - - // No arguments: - arr = Complex128Array.of(); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 0, 'returns expected value' ); - - // Interleaved real and imaginary components: - arr = Complex128Array.of( 1.0, 2.0, 3.0, 4.0 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 2, 'returns expected value' ); - - // Complex numbers: - z = new Complex128( 1.0, 1.0 ); - arr = Complex128Array.of( z, z, z, z, z ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 5, 'returns expected value' ); - - // Mixed arguments: - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = Complex128Array.of( z, 1.0 ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - z = new Complex128( 1.0, 0.0 ); - z.valueOf = valueOf( z ); - arr = Complex128Array.of( 1.0, z ); - t.strictEqual( arr instanceof Complex128Array, true, 'returns expected value' ); - - v = arr.length; - t.strictEqual( v, 1, 'returns expected value' ); - - t.end(); - - function valueOf( z ) { - return function valueOf() { - return real( z ); - }; - } -}); diff --git a/test/test.reduce.js b/test/test.reduce.js deleted file mode 100644 index ea87637..0000000 --- a/test/test.reduce.js +++ /dev/null @@ -1,212 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var cadd = require( '@stdlib/complex-float64-base-add' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'reduce' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.reduce ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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.reduce( value, cadd ); - }; - } -}); - -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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - - arr = new Complex128Array( 0 ); - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - arr.reduce( cadd ); - } -}); - -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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - accArray = [ 1.0, -1.0, 3.0, -3.0 ]; - valueArray = [ 2.0, -2.0, 3.0, -3.0 ]; - expected = new Complex128( 6.0, -6.0 ); - actual = arr.reduce( reducer ); - - t.strictEqual( instanceOf( actual, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( actual ), real( expected ), 'returns expected value' ); - t.strictEqual( imag( actual ), imag( expected ), 'returns expected value' ); - - t.end(); - - function reducer( acc, value, index ) { - var ind = 2*(index-1); - t.strictEqual( instanceOf( acc, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( acc ), accArray[ ind ], 'returns expected value' ); - t.strictEqual( imag( acc ), accArray[ ind+1 ], 'returns expected value' ); - t.strictEqual( instanceOf( value, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( value ), valueArray[ ind ], 'returns expected value' ); - t.strictEqual( imag( value ), valueArray[ ind+1 ], 'returns expected value' ); - return cadd( 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - accArray = [ 2.0, -2.0, 3.0, -3.0, 5.0, -5.0 ]; - valueArray = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ]; - expected = new Complex128( 8.0, -8.0 ); - actual = arr.reduce( reducer, new Complex128( 2.0, -2.0 ) ); - - t.strictEqual( instanceOf( actual, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( actual ), real( expected ), 'returns expected value' ); - t.strictEqual( imag( actual ), imag( expected ), 'returns expected value' ); - - t.end(); - - function reducer( acc, value, index ) { - t.strictEqual( instanceOf( acc, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( acc ), accArray[ 2*index ], 'returns expected value' ); - t.strictEqual( imag( acc ), accArray[ (2*index)+1 ], 'returns expected value' ); - t.strictEqual( instanceOf( value, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( value ), valueArray[ 2*index ], 'returns expected value' ); - t.strictEqual( imag( value ), valueArray[ (2*index)+1 ], 'returns expected value' ); - return cadd( acc, value ); - } -}); - -tape( 'the method returns the accumulated result', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Complex128( 6.0, -6.0 ); - actual = arr.reduce( cadd ); - - t.strictEqual( instanceOf( actual, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( actual ), real( expected ), 'returns expected value' ); - t.strictEqual( imag( actual ), imag( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports returning real-valued results', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = 6.0; - actual = arr.reduce( reducer, 0.0 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value ) { - return acc + real( value ); - } -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index fa37feb..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,217 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 cadd = require( '@stdlib/complex-float64-base-add' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'reduceRight' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.reduceRight ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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.reduceRight( value, cadd ); - }; - } -}); - -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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - - arr = new Complex128Array( 0 ); - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - arr.reduceRight( cadd ); - } -}); - -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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - len = arr.length; - accArray = [ 3.0, -3.0, 5.0, -5.0 ]; - valueArray = [ 2.0, -2.0, 1.0, -1.0 ]; - expected = new Complex128( 6.0, -6.0 ); - actual = arr.reduceRight( reducer ); - - t.strictEqual( instanceOf( actual, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( actual ), real( expected ), 'returns expected value' ); - t.strictEqual( imag( actual ), imag( expected ), 'returns expected value' ); - - t.end(); - - function reducer( acc, value, index ) { - var ind = 2*(len-index-2); - t.strictEqual( instanceOf( acc, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( acc ), accArray[ ind ], 'returns expected value' ); - t.strictEqual( imag( acc ), accArray[ ind+1 ], 'returns expected value' ); - t.strictEqual( instanceOf( value, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( value ), valueArray[ ind ], 'returns expected value' ); - t.strictEqual( imag( value ), valueArray[ ind+1 ], 'returns expected value' ); - return cadd( 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - len = arr.length; - accArray = [ 2.0, -2.0, 5.0, -5.0, 7.0, -7.0 ]; - valueArray = [ 3.0, -3.0, 2.0, -2.0, 1.0, -1.0 ]; - expected = new Complex128( 8.0, -8.0 ); - actual = arr.reduceRight( reducer, new Complex128( 2.0, -2.0 ) ); - - t.strictEqual( instanceOf( actual, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( actual ), real( expected ), 'returns expected value' ); - t.strictEqual( imag( actual ), imag( expected ), 'returns expected value' ); - - t.end(); - - function reducer( acc, value, index ) { - var ind = 2*(len-index-1); - t.strictEqual( instanceOf( acc, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( acc ), accArray[ ind ], 'returns expected value' ); - t.strictEqual( imag( acc ), accArray[ ind+1 ], 'returns expected value' ); - t.strictEqual( instanceOf( value, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( value ), valueArray[ ind ], 'returns expected value' ); - t.strictEqual( imag( value ), valueArray[ ind+1 ], 'returns expected value' ); - return cadd( acc, value ); - } -}); - -tape( 'the method returns the accumulated result', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Complex128( 6.0, -6.0 ); - actual = arr.reduceRight( cadd ); - - t.strictEqual( instanceOf( actual, Complex128 ), true, 'returns expected value' ); - t.strictEqual( real( actual ), real( expected ), 'returns expected value' ); - t.strictEqual( imag( actual ), imag( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the method supports returning real-valued results', function test( t ) { - var expected; - var actual; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = 6.0; - actual = arr.reduceRight( reducer, 0.0 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); - - function reducer( acc, value ) { - return acc + real( value ); - } -}); diff --git a/test/test.reverse.js b/test/test.reverse.js deleted file mode 100644 index b514bfb..0000000 --- a/test/test.reverse.js +++ /dev/null @@ -1,114 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'reverse' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.reverse ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - 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 complex number array in-place', function test( t ) { - var expected; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 3.0, -3.0, 2.0, -2.0, 1.0, -1.0 ] ); - out = arr.reverse(); - - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Complex128Array( 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 bcf9949..0000000 --- a/test/test.set.js +++ /dev/null @@ -1,714 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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 ArrayBuffer = require( '@stdlib/array-buffer' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.set ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 a first argument which is not a complex number, a complex number array, or an array-like object', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 10 ); - - 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.set( value ); - }; - } -}); - -tape( 'the method throws an error if provided a first argument which is not a complex number, a complex number array, or an array-like object (index argument)', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 10 ); - - 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.set( 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 Complex128Array( 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( new Complex128( 1.0, -1.0 ), value ); - }; - } -}); - -tape( 'the method throws an error if provided an index argument which is out-of-bounds (complex number)', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 10 ); - - values = [ - arr.length, - arr.length + 1, - arr.length + 2, - arr.length + 3 - ]; - 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.set( new Complex128( 1.0, -1.0 ), value ); - }; - } -}); - -tape( 'the method throws an error if provided an index argument which is out-of-bounds (complex typed array)', function test( t ) { - var values; - var arr1; - var arr2; - var i; - - arr1 = new Complex128Array( 10 ); - arr2 = new Complex128Array( 10 ); - - 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 throws an error if provided an index argument which is out-of-bounds (array-like object containing complex numbers)', function test( t ) { - var values; - var arr1; - var arr2; - var i; - - arr1 = new Complex128Array( 10 ); - arr2 = []; - for ( i = 0; i < arr1.length; i++ ) { - arr2.push( new Complex128( i, -i ) ); - } - - 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 throws an error if provided an index argument which is out-of-bounds (array-like object containing interleaved components)', function test( t ) { - var values; - var arr1; - var arr2; - var i; - - arr1 = new Complex128Array( 10 ); - arr2 = []; - for ( i = 0; i < arr1.length; i++ ) { - arr2.push( i ); - arr2.push( -i ); - } - - 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 throws an error if provided an array-like object containing interleaved components which has an odd length', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 10 ); - - values = [ - [ 1 ], - [ 1, 2, 3 ], - [ 1, 2, 3, 4, 5 ], - [ 1, 2, 3, 4, 5, 6, 7 ] - ]; - 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.set( value ); - }; - } -}); - -tape( 'the method throws an error if provided an array-like object containing interleaved components which has an odd length (index argument)', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 10 ); - - values = [ - [ 1 ], - [ 1, 2, 3 ], - [ 1, 2, 3, 4, 5 ], - [ 1, 2, 3, 4, 5, 6, 7 ] - ]; - 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.set( value, 0 ); - }; - } -}); - -tape( 'the method sets an array element (complex number)', function test( t ) { - var arr; - var v; - var i; - - arr = new Complex128Array( 10 ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+0 ); - - // No index argument: - arr.set( new Complex128( 20.0, -20.0 ) ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), 20.0, 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), -20.0, 'returns expected imaginary component for index '+0 ); - - arr.set( new Complex128( 0.0, 0.0 ) ); - - // Index argument: - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+i ); - - arr.set( new Complex128( i, -i ), i ); - - v = arr.get( i ); - t.strictEqual( real( v ), i, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), -i, 'returns expected imaginary component for index '+i ); - } - t.end(); -}); - -tape( 'the method sets an array element (complex typed array)', function test( t ) { - var arr; - var buf; - var v; - var i; - - arr = new Complex128Array( 10 ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+0 ); - - // No index argument: - buf = [ 20.0, -20.0 ]; - arr.set( new Complex128Array( buf ) ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - buf = [ 0.0, 0.0 ]; - arr.set( new Complex128Array( buf ) ); - - // Index argument: - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+i ); - - buf = [ i, -i ]; - arr.set( new Complex128Array( buf ), i ); - - v = arr.get( i ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+i ); - } - - // Multiple values, no index argument: - buf = [ 20.0, -20.0, -40.0, 40.0 ]; - arr.set( new Complex128Array( buf ) ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Multiple values, index argument: - buf = [ -100.0, -200.0, -300.0, -400.0 ]; - arr.set( new Complex128Array( buf ), 2 ); - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - t.end(); -}); - -tape( 'the method sets an array element (array-like object containing complex numbers)', function test( t ) { - var arr; - var buf; - var v; - var i; - - arr = new Complex128Array( 10 ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+0 ); - - // No index argument: - buf = [ 20.0, -20.0 ]; - arr.set( [ new Complex128( buf[0], buf[1] ) ] ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - buf = [ 0.0, 0.0 ]; - arr.set( [ new Complex128( buf[0], buf[1] ) ] ); - - // Index argument: - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+i ); - - buf = [ i, -i ]; - arr.set( [ new Complex128( buf[ 0 ], buf[ 1 ] ) ], i ); - - v = arr.get( i ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+i ); - } - - // Multiple values, no index argument: - buf = [ 20.0, -20.0, -40.0, 40.0 ]; - arr.set( [ new Complex128( buf[0], buf[1] ), new Complex128( buf[2], buf[3] ) ] ); // eslint-disable-line max-len - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Multiple values, index argument: - buf = [ -100.0, -200.0, -300.0, -400.0 ]; - arr.set( [ new Complex128( buf[0], buf[1] ), new Complex128( buf[2], buf[3] ) ], 2 ); // eslint-disable-line max-len - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - t.end(); -}); - -tape( 'the method sets an array element (array-like object containing interleaved components)', function test( t ) { - var arr; - var buf; - var v; - var i; - - arr = new Complex128Array( 10 ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+0 ); - - // No index argument: - buf = [ 20.0, -20.0 ]; - arr.set( buf ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - buf = [ 0.0, 0.0 ]; - arr.set( buf ); - - // Index argument: - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), 0.0, 'returns expected imaginary component for index '+i ); - - buf = [ i, -i ]; - arr.set( buf, i ); - - v = arr.get( i ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+i ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+i ); - } - - // Multiple values, no index argument: - buf = [ 20.0, -20.0, -40.0, 40.0 ]; - arr.set( buf ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Multiple values, index argument: - buf = [ -100.0, -200.0, -300.0, -400.0 ]; - arr.set( buf, 2 ); - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - t.end(); -}); - -tape( 'the method sets an array element (complex typed array; shared buffer)', function test( t ) { - var byteOffset; - var arr; - var src; - var buf; - var ab; - var v; - - byteOffset = 224; - - ab = new ArrayBuffer( 480 ); - arr = new Complex128Array( ab, byteOffset, 10 ); - - // Overlapping (requires copy), multiple values, no index argument: - buf = [ 20.0, -20.0, -40.0, 40.0 ]; - src = new Complex128Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); - src.set( buf ); - arr.set( src ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Overlapping (requires copy), multiple values, index argument: - buf = [ -100.0, -200.0, -300.0, -400.0 ]; - src = new Complex128Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); - src.set( buf ); - arr.set( src, 2 ); - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - // Overlapping (no copy), multiple values, no index argument: - buf = [ 25.0, -25.0, -45.0, 45.0 ]; - src = new Complex128Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); - src.set( buf ); - arr.set( src ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Overlapping (no copy), multiple values, index argument: - buf = [ -105.0, -205.0, -305.0, -405.0 ]; - src = new Complex128Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 2 ); - src.set( buf ); - arr.set( src, 2 ); - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - t.end(); -}); - -tape( 'the method sets an array element (typed array; shared buffer)', function test( t ) { - var byteOffset; - var arr; - var src; - var buf; - var ab; - var v; - var i; - - byteOffset = 224; - - ab = new ArrayBuffer( 480 ); - arr = new Complex128Array( ab, byteOffset, 10 ); - - // Overlapping (requires copy), multiple values, no index argument: - buf = [ 20.0, -20.0, -40.0, 40.0 ]; - src = new Float64Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 4 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Overlapping (requires copy), multiple values, index argument: - buf = [ -100.0, -200.0, -300.0, -400.0 ]; - src = new Float64Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 4 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src, 2 ); - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - // Overlapping (no copy), multiple values, no index argument: - buf = [ 25.0, -25.0, -45.0, 45.0 ]; - src = new Float64Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 4 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src ); - - v = arr.get( 0 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+0 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+0 ); - - v = arr.get( 1 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+1 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+1 ); - - // Overlapping (no copy), multiple values, index argument: - buf = [ -105.0, -205.0, -305.0, -405.0 ]; - src = new Float64Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 4 ); - for ( i = 0; i < buf.length; i++ ) { - src[ i ] = buf[ i ]; - } - arr.set( src, 2 ); - - v = arr.get( 2 ); - t.strictEqual( real( v ), buf[ 0 ], 'returns expected real component for index '+2 ); - t.strictEqual( imag( v ), buf[ 1 ], 'returns expected imaginary component for index '+2 ); - - v = arr.get( 3 ); - t.strictEqual( real( v ), buf[ 2 ], 'returns expected real component for index '+3 ); - t.strictEqual( imag( v ), buf[ 3 ], 'returns expected imaginary component for index '+3 ); - - t.end(); -}); diff --git a/test/test.slice.js b/test/test.slice.js deleted file mode 100644 index e6d54e6..0000000 --- a/test/test.slice.js +++ /dev/null @@ -1,271 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'slice' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.slice ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.slice(); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.notEqual( actual, arr, 'returns a new instance' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.slice( 1 ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.slice( 1, 3 ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - actual = arr.slice( 1, 30 ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.slice( -3, -1 ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - actual = arr.slice( -30, -2 ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [] ); - actual = arr.slice( 2, 0 ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [] ); - actual = arr.slice( 5 ); - - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [] ); - - actual = arr.slice( 2, -8 ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - - actual = arr.slice( 1, 0 ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.some.js b/test/test.some.js deleted file mode 100644 index dda9b48..0000000 --- a/test/test.some.js +++ /dev/null @@ -1,197 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the prototype of the main export is a `some` method for returning a boolean indicating whether at least one element passes a test', function test( t ) { - t.strictEqual( hasOwnProp( Complex128Array.prototype, 'some' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.some ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 ( real( v ) > 0 && imag( v ) < 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 Complex128Array( 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 complex number array', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array(); - 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 Complex128Array( [ 1.0, 1.0, 1.0, 2.0 ] ); - bool = arr.some( predicate ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method returns `false` if all elements fail a test', function test( t ) { - var bool; - var arr; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - bool = arr.some( predicate ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); - - function predicate( v ) { - return ( real( v ) === imag( v ) ); - } -}); - -tape( 'the method supports providing an execution context', function test( t ) { - var bool; - var ctx; - var arr; - - ctx = { - 'count': 0 - }; - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, 3.0 ] ); - bool = arr.some( predicate, ctx ); - - t.strictEqual( bool, true, '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 ( imag( v ) === real( v ) ); - } -}); - -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 Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - 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 ( imag( v ) === real( v ) ); - } -}); diff --git a/test/test.sort.js b/test/test.sort.js deleted file mode 100644 index de1e321..0000000 --- a/test/test.sort.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 real = require( '@stdlib/complex-float64-real' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Comparison function. -* -* @private -* @param {Complex128} a - first value for comparison -* @param {Complex128} b - second value for comparison -* @returns {number} comparison result -*/ -function compareFcn( a, b ) { - var re1; - var re2; - var im1; - var im2; - re1 = real( a ); - re2 = real( b ); - if ( re1 < re2 ) { - return -1; - } - if ( re1 > re2 ) { - return 1; - } - im1 = imag( a ); - im2 = imag( b ); - if ( im1 < im2 ) { - return -1; - } - if ( im1 > im2 ) { - return 1; - } - return 0; -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'sort' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.sort ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - 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 complex number array in-place', function test( t ) { - var expected; - var arr; - var out; - - arr = new Complex128Array( [ 3.0, -3.0, 1.0, -1.0, 2.0, -2.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - out = arr.sort( compareFcn ); - - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out, arr, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - 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 44229df..0000000 --- a/test/test.subarray.js +++ /dev/null @@ -1,272 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'subarray' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.subarray ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.subarray(); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.subarray( 1 ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.subarray( 1, 3 ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - - expected = new Float64Array( [ 2.0, -2.0, 3.0, -3.0 ] ); - actual = arr.subarray( -3, -1 ); - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - actual = arr.subarray( -30, -2 ); - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [] ); - actual = arr.subarray( 2, 0 ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [] ); - actual = arr.subarray( 5 ); - - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); - expected = new Float64Array( [] ); - - actual = arr.subarray( 2, -8 ); - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), expected, 'returns expected value' ); - - actual = arr.subarray( 1, 0 ); - t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); - t.strictEqual( instanceOf( actual, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( actual, 0 ), 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 ba8f47b..0000000 --- a/test/test.to_locale_string.js +++ /dev/null @@ -1,187 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'toLocaleString' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.toLocaleString ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array(); - - 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 Complex128Array(); - - 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 Complex128Array(); - - 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 Complex128Array(); - str = arr.toLocaleString(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a complex number array', function test( t ) { - var expected; - var str; - var arr; - - arr = new Complex128Array( [ 1, 2, -3, -4 ] ); - expected = '1 + 2i,-3 - 4i'; - - 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 3595bca..0000000 --- a/test/test.to_reversed.js +++ /dev/null @@ -1,113 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'toReversed' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.toReversed ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - 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 out; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - expected = new Float64Array( [ 3.0, -3.0, 2.0, -2.0, 1.0, -1.0 ] ); - out = arr.toReversed(); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Complex128Array( 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 15d3bb2..0000000 --- a/test/test.to_sorted.js +++ /dev/null @@ -1,180 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex128Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Comparison function. -* -* @private -* @param {Complex128} a - first value for comparison -* @param {Complex128} b - second value for comparison -* @returns {number} comparison result -*/ -function compareFcn( a, b ) { - var re1; - var re2; - var im1; - var im2; - re1 = real( a ); - re2 = real( b ); - if ( re1 < re2 ) { - return -1; - } - if ( re1 > re2 ) { - return 1; - } - im1 = imag( a ); - im2 = imag( b ); - if ( im1 < im2 ) { - return -1; - } - if ( im1 > im2 ) { - return 1; - } - return 0; -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'toSorted' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.toSorted ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( 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 complex number array', function test( t ) { - var arr; - var out; - - arr = new Complex128Array(); - 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; - - arr = new Complex128Array( [ 3.0, -3.0, 1.0, -1.0, 2.0, -2.0 ] ); - expected = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - out = arr.toSorted( compareFcn ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - 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 11e045d..0000000 --- a/test/test.to_string.js +++ /dev/null @@ -1,97 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.toString ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array(); - str = arr.toString(); - - t.strictEqual( str, '', 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a string representation of a complex number array', function test( t ) { - var expected; - var str; - var arr; - - arr = new Complex128Array( [ 1, 2, -3, -4 ] ); - expected = '1 + 2i,-3 - 4i'; - - 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 f9be9de..0000000 --- a/test/test.values.js +++ /dev/null @@ -1,272 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 isComplex128 = require( '@stdlib/assert-is-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'values' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.values ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - expected = [ - { - 'value': new Complex128( 1.0, -1.0 ), - 'done': false - }, - { - 'value': new Complex128( 2.0, -2.0 ), - 'done': false - }, - { - 'done': true - } - ]; - it = arr.values(); - - t.strictEqual( typeof it, 'object', 'returns an object' ); - 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( isComplex128( r.value ), true, 'returns expected value' ); - t.strictEqual( real( r.value ), real( e.value ), 'returns expected value' ); - t.strictEqual( imag( r.value ), imag( 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 Complex128Array( [] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - it = arr.values(); - - t.strictEqual( typeof it, 'object', 'returns an object' ); - 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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - it = arr.values(); - - v = it.next(); - t.strictEqual( real( v.value ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v.value ), -1.0, 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( real( v.value ), 2.0, 'returns expected value' ); - t.strictEqual( imag( v.value ), -2.0, '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 Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); - it = arr.values(); - - v = it.next(); - t.strictEqual( real( v.value ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v.value ), -1.0, 'returns expected value' ); - t.strictEqual( v.done, false, 'returns expected value' ); - - v = it.next(); - t.strictEqual( real( v.value ), 2.0, 'returns expected value' ); - t.strictEqual( imag( v.value ), -2.0, '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 Complex128Array; - var arr; - var buf; - var it1; - var it2; - var v1; - var v2; - var i; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( 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 an object' ); - 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( real( v1 ), real( v2 ), 'returns expected value' ); - t.strictEqual( imag( v1 ), imag( 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 Complex128Array; - var arr; - var buf; - var it; - - Complex128Array = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - buf = [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ]; - arr = new Complex128Array( buf ); - - it = arr.values(); - t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/test/test.with.js b/test/test.with.js deleted file mode 100644 index f048035..0000000 --- a/test/test.with.js +++ /dev/null @@ -1,203 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Float64Array = require( '@stdlib/array-float64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex128Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Complex128Array, '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( Complex128Array.prototype, 'with' ), true, 'has property' ); - t.strictEqual( isFunction( Complex128Array.prototype.with ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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, new Complex128( 1.0, 1.0 ) ); - }; - } -}); - -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 Complex128Array( 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, new Complex128( 1.0, 1.0 ) ); - }; - } -}); - -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 Complex128Array( 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, new Complex128( 1.0, 1.0 ) ); - }; - } -}); - -tape( 'the method throws an error if provided a second argument which is not a complex number', function test( t ) { - var values; - var arr; - var i; - - arr = new Complex128Array( 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.with( 0, value ); - }; - } -}); - -tape( 'the method does not change the array length', function test( t ) { - var arr; - var out; - - arr = new Complex128Array( 10 ); - out = arr.with( 5, new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( out.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the method returns a new complex number array with the element at a provided index replaced with a provided value', function test( t ) { - var expected; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); - expected = new Float64Array( [ 1.0, 1.0, 5.0, 5.0, 3.0, 3.0, 4.0, 4.0 ] ); - out = arr.with( 1, new Complex128( 5.0, 5.0 ) ); - - t.strictEqual( out instanceof Complex128Array, true, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), 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 out; - - arr = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); - expected = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 1.0, 1.0 ] ); - - out = arr.with( -1, new Complex128( 1.0, 1.0 ) ); - - t.strictEqual( out instanceof Complex128Array, true, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - t.end(); -});