diff --git a/.github/.keepalive b/.github/.keepalive new file mode 100644 index 0000000..c1960e2 --- /dev/null +++ b/.github/.keepalive @@ -0,0 +1 @@ +2023-10-01T05:36:44.497Z diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 06a9a75..ab56cca 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -41,11 +41,13 @@ jobs: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml index a00dbe5..3acd3a9 100644 --- a/.github/workflows/cancel.yml +++ b/.github/workflows/cancel.yml @@ -44,7 +44,8 @@ jobs: # Cancel existing workflow runs: - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 + # Pin action to full length commit SHA corresponding to v0.11.0 + uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 with: workflow_id: >- benchmark.yml, diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml index fc6d38a..6f7c875 100644 --- a/.github/workflows/close_pull_requests.yml +++ b/.github/workflows/close_pull_requests.yml @@ -26,19 +26,29 @@ on: # 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: - - uses: superbrothers/close-pull-request@v3 - 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/pool) 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 + + # 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/pool) 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 index 7902a7d..c1c45e7 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -39,13 +39,15 @@ jobs: # Define the sequence of job steps... steps: - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 + # Checkout repository: + - name: 'Checkout repository' + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml index 9ef1395..4f5a65c 100644 --- a/.github/workflows/npm_downloads.yml +++ b/.github/workflows/npm_downloads.yml @@ -45,12 +45,14 @@ jobs: steps: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 timeout-minutes: 10 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -84,7 +86,8 @@ jobs: # Upload the download data: - name: 'Upload data' - uses: actions/upload-artifact@v3 + # Pin action to full length commit SHA corresponding to v3.1.3 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: # Define a name for the uploaded artifact (ensuring a unique name for each job): name: npm_downloads @@ -99,7 +102,8 @@ jobs: # Send data to events server: - name: 'Post data' - uses: distributhor/workflow-webhook@v3 + # Pin action to full length commit SHA corresponding to v3.0.3: + uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 env: webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml index 91f2b93..265afda 100644 --- a/.github/workflows/productionize.yml +++ b/.github/workflows/productionize.yml @@ -61,13 +61,15 @@ jobs: steps: # Checkout main branch of repository: - name: 'Checkout main branch' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: ref: main # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -132,7 +134,8 @@ jobs: # Checkout the repository: - name: 'Checkout repository' if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: # Use the `production` branch: ref: production @@ -140,7 +143,8 @@ jobs: # Install Node.js: - name: 'Install Node.js' if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -184,7 +188,8 @@ jobs: steps: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Configure git: - name: 'Configure git' @@ -251,7 +256,8 @@ jobs: # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -334,7 +340,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -357,7 +364,8 @@ jobs: steps: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Configure git: - name: 'Configure git' @@ -416,7 +424,8 @@ jobs: # Install Node.js - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -505,7 +514,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -528,7 +538,8 @@ jobs: steps: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Configure git: - name: 'Configure git' @@ -595,7 +606,8 @@ jobs: # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -682,7 +694,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -706,7 +719,8 @@ jobs: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: fetch-depth: 2 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 474004b..b17435b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -61,11 +61,13 @@ jobs: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -197,7 +199,8 @@ jobs: # Publish package to npm: - name: 'Publish package to npm' - uses: JS-DevTools/npm-publish@v2 + # Pin action to full length commit SHA corresponding to v2.2.2 + uses: JS-DevTools/npm-publish@fe72237be0920f7a0cafd6a966c9b929c9466e9b with: token: ${{ secrets.NPM_TOKEN }} access: public @@ -209,7 +212,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -230,7 +234,8 @@ jobs: # Cancel any running or queued workflow runs: - name: 'Cancel running or queued workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 + # Pin action to full length commit SHA corresponding to v0.11.0 + uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 with: workflow_id: >- benchmark.yml, diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 20cab70..c397022 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,11 +58,13 @@ jobs: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -89,7 +91,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/.github/workflows/test_bundles.yml b/.github/workflows/test_bundles.yml index 172cb2d..0d26143 100644 --- a/.github/workflows/test_bundles.yml +++ b/.github/workflows/test_bundles.yml @@ -49,13 +49,15 @@ jobs: steps: # Checkout UMD branch of the repository: - name: 'Checkout branch with UMD build' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: ref: umd # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 17 @@ -88,7 +90,8 @@ jobs: # Send notification to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -113,13 +116,15 @@ jobs: # Checkout ES modules branch of the repository: - name: 'Checkout branch with ESM build' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: ref: esm # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 17 @@ -130,7 +135,8 @@ jobs: # Send notification to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -155,13 +161,15 @@ jobs: # Checkout Deno branch of the repository: - name: 'Checkout branch with Deno build' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: ref: deno # Install Deno: - name: 'Install Deno' - uses: denoland/setup-deno@v1 + # Pin action to full length commit SHA corresponding to v1.1.2 + uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 with: deno-version: vx.x.x @@ -172,7 +180,8 @@ jobs: # Send notification to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index a73c515..5b2b1ea 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -46,11 +46,13 @@ jobs: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -77,7 +79,8 @@ jobs: # Upload coverage report to Codecov: - name: 'Upload coverage to Codecov' id: upload - uses: codecov/codecov-action@v3 + # Pin action to full length commit SHA corresponding to v3.1.4 + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d with: directory: reports/coverage flags: unittests @@ -106,7 +109,8 @@ jobs: # Send Slack notification if job fails: - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} @@ -115,7 +119,8 @@ jobs: # Send data to events server: - name: 'Post data' - uses: distributhor/workflow-webhook@v3 + # Pin action to full length commit SHA corresponding to v3.0.3: + uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 env: webhook_url: ${{ secrets.STDLIB_COVERAGE_URL }} webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml index fc470ee..c41146b 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/test_install.yml @@ -58,11 +58,13 @@ jobs: # Checkout the repository: - name: 'Checkout repository' - uses: actions/checkout@v3 + # Pin action to full length commit SHA corresponding to v4.1.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # Install Node.js: - name: 'Install Node.js' - uses: actions/setup-node@v3 + # Pin action to full length commit SHA corresponding to v3.8.1 + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d with: node-version: 16 timeout-minutes: 5 @@ -75,7 +77,8 @@ jobs: # Send Slack notification if job fails: - name: 'Send notification to Slack in case of failure' - uses: act10ns/slack@v2 + # Pin action to full length commit SHA corresponding to v2.0.0 + uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/README.md b/README.md index d3ef808..97458a1 100644 --- a/README.md +++ b/README.md @@ -523,8 +523,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [npm-image]: http://img.shields.io/npm/v/@stdlib/array-pool.svg [npm-url]: https://npmjs.org/package/@stdlib/array-pool -[test-image]: https://github.com/stdlib-js/array-pool/actions/workflows/test.yml/badge.svg?branch=v0.1.0 -[test-url]: https://github.com/stdlib-js/array-pool/actions/workflows/test.yml?query=branch:v0.1.0 +[test-image]: https://github.com/stdlib-js/array-pool/actions/workflows/test.yml/badge.svg?branch=main +[test-url]: https://github.com/stdlib-js/array-pool/actions/workflows/test.yml?query=branch:main [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-pool/main.svg [coverage-url]: https://codecov.io/github/stdlib-js/array-pool?branch=main diff --git a/package.json b/package.json index 79df9ec..e58bc2b 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "@stdlib/complex-real": "^0.1.0", "@stdlib/complex-realf": "^0.1.0", "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.0.8", + "@stdlib/random-base-randu": "^0.1.0", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git" diff --git a/test/dist/test.js b/test/dist/test.js new file mode 100644 index 0000000..0566527 --- /dev/null +++ b/test/dist/test.js @@ -0,0 +1,1797 @@ +/* eslint-disable max-lines */ + +/** +* @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 Float64Array = require( '@stdlib/array-float64' ); +var Float32Array = require( '@stdlib/array-float32' ); +var Int32Array = require( '@stdlib/array-int32' ); +var Uint32Array = require( '@stdlib/array-uint32' ); +var Int16Array = require( '@stdlib/array-int16' ); +var Uint16Array = require( '@stdlib/array-uint16' ); +var Int8Array = require( '@stdlib/array-int8' ); +var Uint8Array = require( '@stdlib/array-uint8' ); +var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); +var Complex64Array = require( '@stdlib/array-complex64' ); +var Complex128Array = require( '@stdlib/array-complex128' ); +var instanceOf = require( '@stdlib/assert-instance-of' ); +var randu = require( '@stdlib/random-base-randu' ); +var Complex128 = require( '@stdlib/complex-float64' ); +var Complex64 = require( '@stdlib/complex-float32' ); +var real = require( '@stdlib/complex-real' ); +var realf = require( '@stdlib/complex-realf' ); +var imag = require( '@stdlib/complex-imag' ); +var imagf = require( '@stdlib/complex-imagf' ); +var typedarraypool = require( './../../dist' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'typedarray', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32' + ]; + + 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() { + typedarraypool( value ); + }; + } +}); + +tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'typedarray', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32' + ]; + + 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() { + typedarraypool( 10, value ); + }; + } +}); + +tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'typedarray', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32' + ]; + + 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() { + typedarraypool( new Float64Array( 10 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'typedarray', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32' + ]; + + 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() { + typedarraypool( [ 1, 2, 3 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { + var values; + var i; + + values = [ + 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() { + typedarraypool( value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { + var values; + var i; + + values = [ + 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() { + typedarraypool( value, 'float64' ); + }; + } +}); + +tape( 'the function returns a typed array (default)', function test( t ) { + var arr = typedarraypool(); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float64)', function test( t ) { + var arr = typedarraypool( 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float32)', function test( t ) { + var arr = typedarraypool( 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { + var arr = typedarraypool( 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { + var arr = typedarraypool( 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int32)', function test( t ) { + var arr = typedarraypool( 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { + var arr = typedarraypool( 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int16)', function test( t ) { + var arr = typedarraypool( 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { + var arr = typedarraypool( 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int8)', function test( t ) { + var arr = typedarraypool( 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { + var arr = typedarraypool( 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { + var arr = typedarraypool( 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (default, length)', function test( t ) { + var arr = typedarraypool( 10 ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { + var arr = typedarraypool( 10, 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { + var arr = typedarraypool( 10, 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { + var arr = typedarraypool( 10, 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { + var arr = typedarraypool( 10, 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { + var arr = typedarraypool( 10, 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { + var arr = typedarraypool( 10, 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { + var arr = typedarraypool( 10, 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { + var arr = typedarraypool( 10, 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { + var arr = typedarraypool( 10, 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { + var arr = typedarraypool( 10, 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { + var arr = typedarraypool( 10, 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (default, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'float64' ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'float64' ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'float32' ); + t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'float32' ); + t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { + var arr; + var out; + var v; + + arr = []; + out = typedarraypool( arr, 'complex128' ); + t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0, 4.0 ]; + out = typedarraypool( arr, 'complex128' ); + t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + + v = out.get( 0 ); + t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); + t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); + + v = out.get( 1 ); + t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); + t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { + var arr; + var out; + var v; + + arr = []; + out = typedarraypool( arr, 'complex64' ); + t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0, 4.0 ]; + out = typedarraypool( arr, 'complex64' ); + t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + + v = out.get( 0 ); + t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); + t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); + + v = out.get( 1 ); + t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); + t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'int32' ); + t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'int32' ); + t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'uint32' ); + t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'uint32' ); + t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'int16' ); + t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'int16' ); + t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'uint16' ); + t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'uint16' ); + t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'int8' ); + t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'int8' ); + t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'uint8' ); + t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'uint8' ); + t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { + var arr; + var out; + + arr = []; + out = typedarraypool( arr, 'uint8c' ); + t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = [ 1.0, 2.0, 3.0 ]; + out = typedarraypool( arr, 'uint8c' ); + t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (default, typed array)', function test( t ) { + var arr; + var out; + + arr = new Float64Array( 0 ); + out = typedarraypool( arr ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { + var arr; + var out; + + arr = new Float64Array( 0 ); + out = typedarraypool( arr, 'float64' ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'float64' ); + t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { + var arr; + var out; + + arr = new Uint32Array( 0 ); + out = typedarraypool( arr, 'float32' ); + t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'float32' ); + t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { + var arr; + var out; + var v; + + arr = new Float64Array( 0 ); + out = typedarraypool( arr, 'complex128' ); + t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = typedarraypool( arr, 'complex128' ); + t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + + v = out.get( 0 ); + t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); + t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); + + v = out.get( 1 ); + t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); + t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { + var arr; + var out; + var v; + + arr = new Float32Array( 0 ); + out = typedarraypool( arr, 'complex64' ); + t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = typedarraypool( arr, 'complex64' ); + t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + + v = out.get( 0 ); + t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); + t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); + + v = out.get( 1 ); + t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); + t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { + var arr; + var out; + + arr = new Float32Array( 0 ); + out = typedarraypool( arr, 'int32' ); + t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'int32' ); + t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { + var arr; + var out; + + arr = new Uint8ClampedArray( 0 ); + out = typedarraypool( arr, 'uint32' ); + t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'uint32' ); + t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { + var arr; + var out; + + arr = new Float64Array( 0 ); + out = typedarraypool( arr, 'int16' ); + t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'int16' ); + t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { + var arr; + var out; + + arr = new Int8Array( 0 ); + out = typedarraypool( arr, 'uint16' ); + t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'uint16' ); + t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { + var arr; + var out; + + arr = new Int16Array( 0 ); + out = typedarraypool( arr, 'int8' ); + t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'int8' ); + t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { + var arr; + var out; + + arr = new Int32Array( 0 ); + out = typedarraypool( arr, 'uint8' ); + t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'uint8' ); + t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { + var arr; + var out; + + arr = new Float32Array( 0 ); + out = typedarraypool( arr, 'uint8c' ); + t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + out = typedarraypool( arr, 'uint8c' ); + t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + + typedarraypool.free( out ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { + t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { + var arr = typedarraypool.calloc(); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { + var arr = typedarraypool.calloc( 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { + var arr = typedarraypool.calloc( 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { + var arr = typedarraypool.calloc( 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { + var arr = typedarraypool.calloc( 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { + var arr = typedarraypool.calloc( 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { + var arr = typedarraypool.calloc( 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { + var arr = typedarraypool.calloc( 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { + var arr = typedarraypool.calloc( 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { + var arr = typedarraypool.calloc( 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { + var arr = typedarraypool.calloc( 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { + var arr = typedarraypool.calloc( 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10 ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10 ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'float64' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'float32' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { + var arr; + var tmp; + var v; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'complex128' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( i ); + t.strictEqual( real( v ), 0.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { + var arr; + var tmp; + var v; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'complex64' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( i ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'int32' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'uint32' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'int16' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'uint16' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'int8' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'uint8' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { + var arr; + var tmp; + var i; + + typedarraypool.clear(); + + tmp = typedarraypool.malloc( 10, 'uint8c' ); + for ( i = 0; i < tmp.length; i++ ) { + tmp[ i ] = randu() * 256.0; + } + typedarraypool.free( tmp ); + + arr = typedarraypool.calloc( 10, 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.notEqual( arr, tmp, 'returns a new view' ); + t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); + + t.strictEqual( arr.length, 10, 'returns expected value' ); + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( arr[ i ], 0, 'returns expected value' ); + } + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { + var arr; + var buf; + var i; + + typedarraypool.clear(); + + arr = typedarraypool( 10, 'uint8c' ); + buf = arr.buffer; + typedarraypool.free( arr ); + + for ( i = 0; i < 10; i++ ) { + arr = typedarraypool( 10, 'uint8c' ); + t.strictEqual( arr.buffer, buf, 'returns expected value' ); + typedarraypool.free( arr ); + } + typedarraypool.clear(); + t.end(); +}); + +tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { + var arr; + var buf; + var i; + + typedarraypool.clear(); + + arr = typedarraypool( 10, 'uint8c' ); + buf = arr.buffer; + typedarraypool.free( buf ); + + for ( i = 0; i < 10; i++ ) { + arr = typedarraypool( 10, 'uint8c' ); + t.strictEqual( arr.buffer, buf, 'returns expected value' ); + typedarraypool.free( arr.buffer ); + } + typedarraypool.clear(); + t.end(); +}); + +tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { + var bool; + var arr; + + typedarraypool.clear(); + + arr = typedarraypool( 10, 'uint8c' ); + bool = typedarraypool.free( arr ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = typedarraypool.free( arr ); + t.strictEqual( bool, false, 'returns expected value' ); + + typedarraypool.clear(); + t.end(); +}); + +tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { + var bool; + var arr; + var buf; + + typedarraypool.clear(); + + arr = typedarraypool( 10, 'uint8c' ); + buf = arr.buffer; + bool = typedarraypool.free( buf ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = typedarraypool.free( buf ); + t.strictEqual( bool, false, 'returns expected value' ); + + typedarraypool.clear(); + t.end(); +}); + +tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', 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() { + typedarraypool.free( value ); + }; + } +}); + +tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { + t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); + t.end(); +}); + +tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { + var arr; + + typedarraypool.clear(); + t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); + + arr = typedarraypool( 10, 'uint8' ); + t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); + + typedarraypool.free( arr ); + typedarraypool.clear(); + + t.end(); +}); + +tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { + var arrs; + var i; + + typedarraypool.clear(); + t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); + + arrs = new Array( 10 ); + for ( i = 0; i < arrs.length; i++ ) { + arrs[ i ] = typedarraypool( 10, 'uint8' ); + t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); + } + for ( i = 0; i < arrs.length; i++ ) { + typedarraypool.free( arrs[ i ] ); + } + t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); + + typedarraypool.clear(); + t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { + t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); + t.end(); +});