diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +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 -insert_final_newline = false - -# 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 b64306a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:18:06.370Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1c22993..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/random/base/triangular) 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/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 b275b5a..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/random/base/triangular) 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 02b1e86..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: '6 18 * * 1' - - # 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 + + ```
@@ -462,7 +459,7 @@ for ( i = 0; i < 100; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -527,15 +524,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/tree/esm -[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular +[@stdlib/random/streams/triangular]: https://github.com/stdlib-js/random-streams-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 99ccd39..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,105 +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 bench = require( '@stdlib/bench-harness' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var minstd = require( '@stdlib/random-base-minstd-shuffle' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'seed': 1 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed += i; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:seed=', function benchmark( b ) { - var seed; - var opts; - var f; - var i; - - opts = {}; - - seed = new Uint32Array( 10 ); - for ( i = 0; i < seed.length; i++ ) { - seed[ i ] = minstd(); - } - opts.seed = seed; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.seed[ 0 ] = i + 1; - f = factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( isnan( f( 200.0, 440.0, 383.5 ) ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index bedd436..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,111 +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 bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pkg = require( './../package.json' ).name; -var triangular = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( assert ) { - var a; - var b; - var c; - var z; - var i; - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - a = randu() * 100.0; - c = a + ( randu()*100.0 ); - b = c + ( randu()*100.0 ); - z = triangular( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory( a, b, c ); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); - -bench( pkg+'::factory,arguments', function benchmark( assert ) { - var rand; - var a; - var b; - var c; - var z; - var i; - - a = 200.0; - b = 440.0; - c = 383.5; - rand = triangular.factory(); - - assert.tic(); - for ( i = 0; i < assert.iterations; i++ ) { - z = rand( a, b, c ); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - } - assert.toc(); - if ( isnan( z ) ) { - assert.fail( 'should not return NaN' ); - } - assert.pass( 'benchmark finished' ); - assert.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 7a3680d..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,48 +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 bench = require( '@stdlib/bench-harness' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var rand = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON', function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = rand.toJSON(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isObject( o ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/r/DESCRIPTION b/benchmark/r/DESCRIPTION deleted file mode 100644 index d2abd2f..0000000 --- a/benchmark/r/DESCRIPTION +++ /dev/null @@ -1,10 +0,0 @@ -Package: rtriangle-benchmarks -Title: Benchmarks -Version: 0.0.0 -Authors@R: person("stdlib", "js", role = c("aut","cre")) -Description: Benchmarks. -Depends: R (>=3.4.0) -Imports: - microbenchmark - VGAM -LazyData: true diff --git a/benchmark/r/benchmark.R b/benchmark/r/benchmark.R deleted file mode 100644 index c1f72ec..0000000 --- a/benchmark/r/benchmark.R +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env Rscript -# -# @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. - -# Set the precision to 16 digits: -options( digits = 16L ); - -#' Run benchmarks. -#' -#' @examples -#' main(); -main <- function() { - # Define benchmark parameters: - name <- "random-triangular"; - iterations <- 1000000L; - repeats <- 3L; - - #' Print the TAP version. - #' - #' @examples - #' print_version(); - print_version <- function() { - cat( "TAP version 13\n" ); - } - - #' Print the TAP summary. - #' - #' @param total Total number of tests. - #' @param passing Total number of passing tests. - #' - #' @examples - #' print_summary( 3, 3 ); - print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); - } - - #' Print benchmark results. - #' - #' @param iterations Number of iterations. - #' @param elapsed Elapsed time in seconds. - #' - #' @examples - #' print_results( 10000L, 0.131009101868 ); - print_results <- function( iterations, elapsed ) { - rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); - } - - #' Run a benchmark. - #' - #' ## Notes - #' - #' * We compute and return a total "elapsed" time, rather than the minimum - #' evaluation time, to match benchmark results in other languages (e.g., - #' Python). - #' - #' - #' @param iterations Number of Iterations. - #' @return Elapsed time in seconds. - #' - #' @examples - #' elapsed <- benchmark( 10000L ); - benchmark <- function( iterations ) { - # Run the benchmarks: - results <- microbenchmark::microbenchmark({ - a <- runif( 1, 0.0, 100.0 ); - c <- a + runif( 1, 0.0, 100.0 ); - b <- c + runif( 1, 0.0, 100.0 ); - VGAM::rtriangle( 1, c, a, b ); - }, - times = iterations - ); - - # Sum all the raw timing results to get a total "elapsed" time: - elapsed <- sum( results$time ); - - # Convert the elapsed time from nanoseconds to seconds: - elapsed <- elapsed / 1.0e9; - - return( elapsed ); - } - - print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); - elapsed <- benchmark( iterations ); - print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); - } - print_summary( repeats, repeats ); -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c284b1f..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular" -%% click B href "https://github.com/stdlib-js/random-base-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-base-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-base-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-base-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-base-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/base/triangular -[production-url]: https://github.com/stdlib-js/random-base-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-base-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-base-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-base-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-base-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-base-triangular/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e0b727b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var w=l(function(er,N){ -var c=require('@stdlib/assert-is-number/dist').isPrimitive,v=require('@stdlib/error-tools-fmtprodmsg/dist'),q=require('@stdlib/assert-is-nan/dist');function H(t,r,e){return !c(t)||q(t)?new TypeError(v('0p96v',t)):!c(r)||q(r)?new TypeError(v('0p96w',r)):!c(e)||q(e)?new TypeError(v('0p97C',e)):t<=e&&e<=r?null:new RangeError(v('0p99C',"a <= c <= b",t,r,e));}N.exports=H -});var L=l(function(tr,O){ -var b=require('@stdlib/math-base-special-sqrt/dist');function I(t,r,e,o){var a,u,i;return a=(o-r)/(e-r),i=t(),i3){if(t=arguments[3],!E(t))throw new TypeError(p('0p92V',t));if(T(t,"prng")){if(!R(t.prng))throw new TypeError(p('0p96u',"prng",t.prng));r=t.prng}else r=m(t)}else r=m()}return a===void 0?e=D:e=C,s(e,"NAME","triangular"),t&&t.prng?(s(e,"seed",null),s(e,"seedLength",null),S(e,"state",x(null),K),s(e,"stateLength",null),s(e,"byteLength",null),s(e,"toJSON",x(null)),s(e,"PRNG",r)):(f(e,"seed",G),f(e,"seedLength",J),S(e,"state",W,k),f(e,"stateLength",z),f(e,"byteLength",M),s(e,"toJSON",B),s(e,"PRNG",r),r=r.normalized),e;function G(){return r.seed}function J(){return r.seedLength}function z(){return r.stateLength}function M(){return r.byteLength}function W(){return r.state}function k(n){r.state=n}function B(){var n={};return n.type="PRNG",n.name=e.NAME,n.state=Q(r.state),a===void 0?n.params=[]:n.params=[a,u,i],n}function C(){return P(r,a,u,i)}function D(n,d,g){return h(n)||h(d)||h(g)||!(n<=g&&g<=d)?NaN:P(r,n,d,g)}}V.exports=X -});var A=l(function(ar,j){ -var Y=y(),Z=Y();j.exports=Z -});var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),F=A(),$=y();_(F,"factory",$);module.exports=F; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3b1fb24..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/triangular.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar isnan = require( '@stdlib/assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar randu = require( '@stdlib/random-base-mt19937' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar typedarray2json = require( '@stdlib/array-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar triangular0 = require( './triangular.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\n\n\t/**\n\t* Returns the PRNG seed.\n\t*\n\t* @private\n\t* @returns {PRNGSeedMT19937} seed\n\t*/\n\tfunction getSeed() {\n\t\treturn rand.seed;\n\t}\n\n\t/**\n\t* Returns the PRNG seed length.\n\t*\n\t* @private\n\t* @returns {PositiveInteger} seed length\n\t*/\n\tfunction getSeedLength() {\n\t\treturn rand.seedLength;\n\t}\n\n\t/**\n\t* Returns the PRNG state length.\n\t*\n\t* @private\n\t* @returns {PositiveInteger} state length\n\t*/\n\tfunction getStateLength() {\n\t\treturn rand.stateLength;\n\t}\n\n\t/**\n\t* Returns the PRNG state size (in bytes).\n\t*\n\t* @private\n\t* @returns {PositiveInteger} state size (in bytes)\n\t*/\n\tfunction getStateSize() {\n\t\treturn rand.byteLength;\n\t}\n\n\t/**\n\t* Returns the current pseudorandom number generator state.\n\t*\n\t* @private\n\t* @returns {PRNGStateMT19937} current state\n\t*/\n\tfunction getState() {\n\t\treturn rand.state;\n\t}\n\n\t/**\n\t* Sets the pseudorandom number generator state.\n\t*\n\t* @private\n\t* @param {PRNGStateMT19937} s - generator state\n\t* @throws {Error} must provide a valid state\n\t*/\n\tfunction setState( s ) {\n\t\trand.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-base-triangular' );\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var factory = require( '@stdlib/random-base-triangular' ).factory;\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,QAAS,uBAAwB,EAoB7C,SAASC,EAAUC,EAAGC,EAAGC,EAAI,CAC5B,MAAK,CAACN,EAAUI,CAAE,GAAKF,EAAOE,CAAE,EACxB,IAAI,UAAWH,EAAQ,8EAA+EG,CAAE,CAAE,EAE7G,CAACJ,EAAUK,CAAE,GAAKH,EAAOG,CAAE,EACxB,IAAI,UAAWJ,EAAQ,+EAAgFI,CAAE,CAAE,EAE9G,CAACL,EAAUM,CAAE,GAAKJ,EAAOI,CAAE,EACxB,IAAI,UAAWL,EAAQ,8EAA+EK,CAAE,CAAE,EAE3GF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAI,WAAYJ,EAAQ,qGAAsG,cAAeG,EAAGC,EAAGC,CAAE,CAAE,CAGhK,CAKAP,EAAO,QAAUI,IC/DjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EAerD,SAASC,EAAYC,EAAMC,EAAGC,EAAGC,EAAI,CACpC,IAAIC,EACAC,EACAC,EAGJ,OAFAF,GAAMD,EAAIF,IAAMC,EAAID,GACpBK,EAAIN,EAAK,EACJM,EAAIF,GACRC,GAAKH,EAAID,IAAME,EAAIF,GACZA,EAAIH,EAAMO,EAAIC,CAAE,IAExBD,GAAKH,EAAID,IAAMC,EAAIC,GACZD,EAAIJ,EAAMO,GAAK,EAAMC,EAAG,EAChC,CAKAT,EAAO,QAAUE,ICtDjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAsB,QAAS,uDAAwD,EACvFC,EAAuB,QAAS,wDAAyD,EACzFC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,4BAA6B,EACnDC,EAAa,QAAS,iCAAkC,EACxDC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAO,QAAS,oBAAqB,EACrCC,EAAQ,QAAS,6BAA8B,EAAE,QACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAkB,QAAS,uBAAwB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAc,IAsClB,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzBJ,EAAOR,EAAM,UACF,UAAU,SAAW,EAAI,CAEpC,GADAO,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,KAAO,CAKN,GAJA,EAAI,UAAW,CAAE,EACjBI,EAAI,UAAW,CAAE,EACjBC,EAAI,UAAW,CAAE,EACjBF,EAAMN,EAAU,EAAGO,EAAGC,CAAE,EACnBF,EACJ,MAAMA,EAEP,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAO,UAAW,CAAE,EACf,CAACZ,EAAUY,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAK,CAAE,EAE3G,GAAKV,EAAYU,EAAM,MAAO,EAAI,CACjC,GAAK,CAACX,EAAYW,EAAK,IAAK,EAC3B,MAAM,IAAI,UAAWJ,EAAQ,8FAA+F,OAAQI,EAAK,IAAK,CAAE,EAEjJC,EAAOD,EAAK,IACb,MACCC,EAAOR,EAAOO,CAAK,CAErB,MACCC,EAAOR,EAAM,CAEf,CACA,OAAK,IAAM,OACVS,EAAOI,EAEPJ,EAAOK,EAERtB,EAAaiB,EAAM,OAAQ,YAAa,EAGnCF,GAAQA,EAAK,MACjBf,EAAaiB,EAAM,OAAQ,IAAK,EAChCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCf,EAAsBe,EAAM,QAASX,EAAkB,IAAK,EAAGC,CAAK,EACpEP,EAAaiB,EAAM,cAAe,IAAK,EACvCjB,EAAaiB,EAAM,aAAc,IAAK,EACtCjB,EAAaiB,EAAM,SAAUX,EAAkB,IAAK,CAAE,EACtDN,EAAaiB,EAAM,OAAQD,CAAK,IAEhCf,EAAqBgB,EAAM,OAAQM,CAAQ,EAC3CtB,EAAqBgB,EAAM,aAAcO,CAAc,EACvDtB,EAAsBe,EAAM,QAASQ,EAAUC,CAAS,EACxDzB,EAAqBgB,EAAM,cAAeU,CAAe,EACzD1B,EAAqBgB,EAAM,aAAcW,CAAa,EACtD5B,EAAaiB,EAAM,SAAUY,CAAO,EACpC7B,EAAaiB,EAAM,OAAQD,CAAK,EAChCA,EAAOA,EAAK,YAENC,EAQP,SAASM,GAAU,CAClB,OAAOP,EAAK,IACb,CAQA,SAASQ,GAAgB,CACxB,OAAOR,EAAK,UACb,CAQA,SAASW,GAAiB,CACzB,OAAOX,EAAK,WACb,CAQA,SAASY,GAAe,CACvB,OAAOZ,EAAK,UACb,CAQA,SAASS,GAAW,CACnB,OAAOT,EAAK,KACb,CASA,SAASU,EAAUI,EAAI,CACtBd,EAAK,MAAQc,CACd,CAYA,SAASD,GAAS,CACjB,IAAIE,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,OACXA,EAAI,KAAOd,EAAK,KAChBc,EAAI,MAAQrB,EAAiBM,EAAK,KAAM,EACnC,IAAM,OACVe,EAAI,OAAS,CAAC,EAEdA,EAAI,OAAS,CAAE,EAAGZ,EAAGC,CAAE,EAEjBW,CACR,CAYA,SAAST,GAAc,CACtB,OAAOT,EAAaG,EAAM,EAAGG,EAAGC,CAAE,CACnC,CAuBA,SAASC,EAAaW,EAAGb,EAAGC,EAAI,CAC/B,OACCX,EAAOuB,CAAE,GACTvB,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACT,EAAEY,GAAKZ,GAAKA,GAAKD,GAEV,IAEDN,EAAaG,EAAMgB,EAAGb,EAAGC,CAAE,CACnC,CACD,CAKArB,EAAO,QAAUe,IC7RjB,IAAAmB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmBVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICMjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isNumber", "format", "isnan", "validate", "a", "b", "c", "require_triangular", "__commonJSMin", "exports", "module", "sqrt", "triangular", "rand", "a", "b", "c", "fc", "x", "u", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "isObject", "isFunction", "hasOwnProp", "constantFunction", "noop", "randu", "isnan", "typedarray2json", "format", "validate", "triangular0", "factory", "opts", "rand", "prng", "err", "b", "c", "triangular2", "triangular1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "toJSON", "s", "out", "a", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ce45429..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,190 +0,0 @@ - -{{alias}}( a, b, c ) - Returns a pseudorandom number drawn from a triangular distribution. - - If the condition `a <= c <= b` is not satisfied, the function returns `NaN`. - - If either `a`, `b`, or `c` is `NaN`, the function returns `NaN`. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - Returns - ------- - r: integer - Pseudorandom number. - - Examples - -------- - > var r = {{alias}}( 2.0, 5.0, 3.33 ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a pseudorandom number generator (PRNG) for generating pseudorandom - numbers drawn from a triangular distribution. - - If provided `a`, `b`, and `c`, the returned PRNG returns random variates - drawn from the specified distribution. - - If not provided `a`, `b`, and `c`, the returned PRNG requires that `a`, `b`, - and `c` be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - rand: Function - Pseudorandom number generator (PRNG). - - Examples - -------- - // Basic usage: - > var rand = {{alias}}.factory(); - > var r = rand( 0.0, 1.0, 0.5 ); - > r = rand( -2.0, 2.0, 1.0 ); - - // Provide `a`, `b`, and `c`: - > rand = {{alias}}.factory( 0.0, 1.0, 0.5 ); - > r = rand(); - > r = rand(); - - -{{alias}}.NAME - Generator name. - - Examples - -------- - > var str = {{alias}}.NAME - 'triangular' - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - // Set the state: - > {{alias}}.state = state; - - // Replay the last two pseudorandom numbers: - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - > r = {{alias}}( 0.0, 1.0, 0.5 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - -{{alias}}.toJSON() - Serializes the pseudorandom number generator as a JSON object. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var o = {{alias}}.toJSON() - { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 678c525..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import triangular = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - triangular( 2.0, 5.0, 3.33 ); // $ExpectType number - triangular( 1.0, 2.0, 1.8 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided values other than three numbers... -{ - triangular( true, 3, 0.8 ); // $ExpectError - triangular( false, 2, 0.8 ); // $ExpectError - triangular( '5', 1, 0.8 ); // $ExpectError - triangular( [], 1, 0.8 ); // $ExpectError - triangular( {}, 2, 0.8 ); // $ExpectError - triangular( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - triangular( 0.2, true, 0.8 ); // $ExpectError - triangular( 0.2, false, 0.8 ); // $ExpectError - triangular( 0.5, '5', 0.8 ); // $ExpectError - triangular( 0.2, [], 0.8 ); // $ExpectError - triangular( 0.4, {}, 0.8 ); // $ExpectError - triangular( 0.4, ( x: number ): number => x, 0.8 ); // $ExpectError - - triangular( 0.9, 3, true ); // $ExpectError - triangular( 0.9, 3, false ); // $ExpectError - triangular( 0.5, 5, '5' ); // $ExpectError - triangular( 0.8, 8, [] ); // $ExpectError - triangular( 0.9, 3, {} ); // $ExpectError - triangular( 0.8, 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - triangular(); // $ExpectError - triangular( 2 ); // $ExpectError - triangular( 2, 4 ); // $ExpectError - triangular( 2, 4, 3.5, 4, 8 ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - triangular.factory( 2, 4, 2.7 ); // $ExpectType NullaryFunction - triangular.factory(); // $ExpectType BinaryFunction - triangular.factory( { 'copy': false } ); // $ExpectType BinaryFunction -} - -// The `factory` method returns a function which returns a number... -{ - const fcn1 = triangular.factory( 2, 4, 2.7 ); - fcn1(); // $ExpectType number - - const fcn2 = triangular.factory(); - fcn2( 2, 2, 0.7 ); // $ExpectType number -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 12 ); // $ExpectError - fcn1( true ); // $ExpectError - fcn1( false ); // $ExpectError - fcn1( '5' ); // $ExpectError - fcn1( [] ); // $ExpectError - fcn1( {} ); // $ExpectError - fcn1( ( x: number ): number => x ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2( true, 2, 0.8 ); // $ExpectError - fcn2( false, 2, 0.8 ); // $ExpectError - fcn2( '5', 2, 0.8 ); // $ExpectError - fcn2( [], 2, 0.8 ); // $ExpectError - fcn2( {}, 2, 0.8 ); // $ExpectError - fcn2( ( x: number ): number => x, 2, 0.8 ); // $ExpectError - - fcn2( 0.1, true, 0.8 ); // $ExpectError - fcn2( 0.1, false, 0.8 ); // $ExpectError - fcn2( 0.1, '5', 0.8 ); // $ExpectError - fcn2( 0.1, [], 0.8 ); // $ExpectError - fcn2( 0.1, {}, 0.8 ); // $ExpectError - fcn2( 0.1, ( x: number ): number => x, 0.8 ); // $ExpectError - - fcn2( 0.1, 1, true ); // $ExpectError - fcn2( 0.1, 1, false ); // $ExpectError - fcn2( 0.1, 1, '5' ); // $ExpectError - fcn2( 0.1, 1, [] ); // $ExpectError - fcn2( 0.1, 1, {} ); // $ExpectError - fcn2( 0.1, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn1 = triangular.factory( 2, 4, 2.8 ); - fcn1( 1 ); // $ExpectError - fcn1( 2, 1 ); // $ExpectError - fcn1( 2, 1, 1 ); // $ExpectError - - const fcn2 = triangular.factory(); - fcn2(); // $ExpectError - fcn2( 1 ); // $ExpectError - fcn2( 2, 1 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided values other than three numbers aside from an options object... -{ - triangular.factory( true, 3, 0.7 ); // $ExpectError - triangular.factory( false, 2, 0.7 ); // $ExpectError - triangular.factory( '5', 1, 0.7 ); // $ExpectError - triangular.factory( [], 1, 0.7 ); // $ExpectError - triangular.factory( {}, 2, 0.7 ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7 ); // $ExpectError - - triangular.factory( 0.2, true, 0.7 ); // $ExpectError - triangular.factory( 0.2, false, 0.7 ); // $ExpectError - triangular.factory( 0.2, '5', 0.7 ); // $ExpectError - triangular.factory( 0.2, [], 0.7 ); // $ExpectError - triangular.factory( 0.2, {}, 0.7 ); // $ExpectError - triangular.factory( 0.2, ( x: number ): number => x, 0.7 ); // $ExpectError - - triangular.factory( 0.2, 3, true ); // $ExpectError - triangular.factory( 0.2, 3, false ); // $ExpectError - triangular.factory( 0.3, 3, '5' ); // $ExpectError - triangular.factory( 0.3, 3, [] ); // $ExpectError - triangular.factory( 0.3, 3, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x ); // $ExpectError - - triangular.factory( true, 3, 0.7, {} ); // $ExpectError - triangular.factory( false, 2, 0.7, {} ); // $ExpectError - triangular.factory( '5', 1, 0.7, {} ); // $ExpectError - triangular.factory( [], 1, 0.7, {} ); // $ExpectError - triangular.factory( {}, 2, 0.7, {} ); // $ExpectError - triangular.factory( ( x: number ): number => x, 2, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, true, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, false, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, '5', 0.7, {} ); // $ExpectError - triangular.factory( 0.3, [], 0.7, {} ); // $ExpectError - triangular.factory( 0.3, {}, 0.7, {} ); // $ExpectError - triangular.factory( 0.3, ( x: number ): number => x, 0.7, {} ); // $ExpectError - - triangular.factory( 0.3, 3, true, {} ); // $ExpectError - triangular.factory( 0.3, 3, false, {} ); // $ExpectError - triangular.factory( 0.3, 3, '5', {} ); // $ExpectError - triangular.factory( 0.3, 3, [], {} ); // $ExpectError - triangular.factory( 0.3, 3, {}, {} ); // $ExpectError - triangular.factory( 0.3, 8, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - triangular.factory( null ); // $ExpectError - triangular.factory( 0.5, 2, 1, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - triangular.factory( 2, 4, 2.5, { 'prng': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'prng': true ); // $ExpectError - - triangular.factory( { 'prng': 123 } ); // $ExpectError - triangular.factory( { 'prng': 'abc' } ); // $ExpectError - triangular.factory( { 'prng': null } ); // $ExpectError - triangular.factory( { 'prng': [] } ); // $ExpectError - triangular.factory( { 'prng': {} } ); // $ExpectError - triangular.factory( { 'prng': true ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - triangular.factory( 2, 4, 2.5, { 'seed': true } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'seed': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'seed': true } ); // $ExpectError - triangular.factory( { 'seed': 'abc' } ); // $ExpectError - triangular.factory( { 'seed': null } ); // $ExpectError - triangular.factory( { 'seed': [ 'a' ] } ); // $ExpectError - triangular.factory( { 'seed': {} } ); // $ExpectError - triangular.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - triangular.factory( 2, 4, 2.5, { 'state': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': true ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'state': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'state': 123 } ); // $ExpectError - triangular.factory( { 'state': 'abc' } ); // $ExpectError - triangular.factory( { 'state': null } ); // $ExpectError - triangular.factory( { 'state': [] } ); // $ExpectError - triangular.factory( { 'state': {} } ); // $ExpectError - triangular.factory( { 'state': true ); // $ExpectError - triangular.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - triangular.factory( 2, 4, 2.5, { 'copy': 123 } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': 'abc' } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': null } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': [] } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': {} } ); // $ExpectError - triangular.factory( 2, 4, 2.5, { 'copy': ( x: number ): number => x } ); // $ExpectError - - triangular.factory( { 'copy': 123 } ); // $ExpectError - triangular.factory( { 'copy': 'abc' } ); // $ExpectError - triangular.factory( { 'copy': null } ); // $ExpectError - triangular.factory( { 'copy': [] } ); // $ExpectError - triangular.factory( { 'copy': {} } ); // $ExpectError - triangular.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than four arguments... -{ - triangular.factory( 2, 4, 2.8, {}, 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9059c10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,50 +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'; - -var triangular = require( './../lib' ); - -var seed; -var rand; -var i; - -// Generate pseudorandom numbers... -console.log( '\nseed: %d', triangular.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( triangular( 0.0, 1.0, 0.5 ) ); -} - -// Create a new pseudorandom number generator... -seed = 1234; -rand = triangular.factory( 2.0, 5.0, 3.0, { - 'seed': seed -}); -console.log( '\nseed: %d', seed ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} - -// Create another pseudorandom number generator using a previous seed... -rand = triangular.factory( 0.0, 1.0, 0.5, { - 'seed': triangular.seed -}); -console.log( '\nseed: %d', rand.seed[ 0 ] ); -for ( i = 0; i < 100; i++ ) { - console.log( rand() ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dc80cb6..fc6107f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..753b7e9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-write-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-constant-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-mt19937@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@v0.3.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nan@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-sqrt@v0.2.2-esm/index.mjs";function u(e,t,n,s){var r,i;return r=(s-t)/(n-t),(i=e())3){if(!s(j=arguments[3]))throw new TypeError(a("0p92V",j));if(i(j,"prng")){if(!r(j.prng))throw new TypeError(a("0p96u","prng",j.prng));g=j.prng}else g=m(j)}else g=m()}return e(c=void 0===b?function(e,t,n){if(l(e)||l(t)||l(n)||!(e<=n&&n<=t))return NaN;return u(g,e,t,n)}:function(){return u(g,b,y,w)},"NAME","triangular"),j&&j.prng?(e(c,"seed",null),e(c,"seedLength",null),n(c,"state",o(null),d),e(c,"stateLength",null),e(c,"byteLength",null),e(c,"toJSON",o(null)),e(c,"PRNG",g)):(t(c,"seed",(function(){return g.seed})),t(c,"seedLength",(function(){return g.seedLength})),n(c,"state",(function(){return g.state}),(function(e){g.state=e})),t(c,"stateLength",(function(){return g.stateLength})),t(c,"byteLength",(function(){return g.byteLength})),e(c,"toJSON",(function(){var e={type:"PRNG"};e.name=c.NAME,e.state=p(g.state),e.params=void 0===b?[]:[b,y,w];return e})),e(c,"PRNG",g),g=g.normalized),c}var c=g();e(c,"factory",g);export{c as default,g as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6293ecd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/triangular.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport sqrt from '@stdlib/math-base-special-sqrt';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`.\n*\n* @private\n* @param {PRNG} rand - PRNG for generating uniformly distributed numbers\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*/\nfunction triangular( rand, a, b, c ) {\n\tvar fc;\n\tvar x;\n\tvar u;\n\tfc = (c - a) / (b - a);\n\tu = rand();\n\tif ( u < fc ) {\n\t\tx = (b - a) * (c - a);\n\t\treturn a + sqrt( x * u );\n\t}\n\tx = (b - a) * (b - c);\n\treturn b - sqrt( x * (1.0 - u) );\n}\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-nonenumerable-read-write-accessor';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport isFunction from '@stdlib/assert-is-function';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport constantFunction from '@stdlib/utils-constant-function';\nimport noop from '@stdlib/utils-noop';\nimport { factory as randu } from '@stdlib/random-base-mt19937';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport typedarray2json from '@stdlib/array-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport triangular0 from './triangular.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {PRNG} pseudorandom number generator\n*\n* @example\n* var triangular = factory( 0.0, 1.0, 0.8 );\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* var triangular = factory( -3.0, -1.0, -2.0, {\n* 'seed': 297\n* });\n* var v = triangular();\n* // returns \n*/\nfunction factory() {\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\tvar a;\n\tvar b;\n\tvar c;\n\n\tif ( arguments.length === 0 ) {\n\t\trand = randu();\n\t} else if ( arguments.length === 1 ) {\n\t\topts = arguments[ 0 ];\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t}\n\t\t\trand = opts.prng;\n\t\t} else {\n\t\t\trand = randu( opts );\n\t\t}\n\t} else {\n\t\ta = arguments[ 0 ];\n\t\tb = arguments[ 1 ];\n\t\tc = arguments[ 2 ];\n\t\terr = validate( a, b, c );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tif ( arguments.length > 3 ) {\n\t\t\topts = arguments[ 3 ];\n\t\t\tif ( !isObject( opts ) ) {\n\t\t\t\tthrow new TypeError( format( '0p92V', opts ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( opts, 'prng' ) ) {\n\t\t\t\tif ( !isFunction( opts.prng ) ) {\n\t\t\t\t\tthrow new TypeError( format( '0p96u', 'prng', opts.prng ) );\n\t\t\t\t}\n\t\t\t\trand = opts.prng;\n\t\t\t} else {\n\t\t\t\trand = randu( opts );\n\t\t\t}\n\t\t} else {\n\t\t\trand = randu();\n\t\t}\n\t}\n\tif ( a === void 0 ) {\n\t\tprng = triangular2;\n\t} else {\n\t\tprng = triangular1;\n\t}\n\tsetReadOnly( prng, 'NAME', 'triangular' );\n\n\t// If we are provided an \"external\" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.\n\tif ( opts && opts.prng ) {\n\t\tsetReadOnly( prng, 'seed', null );\n\t\tsetReadOnly( prng, 'seedLength', null );\n\t\tsetReadWriteAccessor( prng, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( prng, 'stateLength', null );\n\t\tsetReadOnly( prng, 'byteLength', null );\n\t\tsetReadOnly( prng, 'toJSON', constantFunction( null ) );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t} else {\n\t\tsetReadOnlyAccessor( prng, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( prng, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( prng, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( prng, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( prng, 'byteLength', getStateSize );\n\t\tsetReadOnly( prng, 'toJSON', toJSON );\n\t\tsetReadOnly( prng, 'PRNG', rand );\n\t\trand = rand.normalized;\n\t}\n\treturn prng;\n\n\t/**\n\t* Returns the PRNG seed.\n\t*\n\t* @private\n\t* @returns {PRNGSeedMT19937} seed\n\t*/\n\tfunction getSeed() {\n\t\treturn rand.seed;\n\t}\n\n\t/**\n\t* Returns the PRNG seed length.\n\t*\n\t* @private\n\t* @returns {PositiveInteger} seed length\n\t*/\n\tfunction getSeedLength() {\n\t\treturn rand.seedLength;\n\t}\n\n\t/**\n\t* Returns the PRNG state length.\n\t*\n\t* @private\n\t* @returns {PositiveInteger} state length\n\t*/\n\tfunction getStateLength() {\n\t\treturn rand.stateLength;\n\t}\n\n\t/**\n\t* Returns the PRNG state size (in bytes).\n\t*\n\t* @private\n\t* @returns {PositiveInteger} state size (in bytes)\n\t*/\n\tfunction getStateSize() {\n\t\treturn rand.byteLength;\n\t}\n\n\t/**\n\t* Returns the current pseudorandom number generator state.\n\t*\n\t* @private\n\t* @returns {PRNGStateMT19937} current state\n\t*/\n\tfunction getState() {\n\t\treturn rand.state;\n\t}\n\n\t/**\n\t* Sets the pseudorandom number generator state.\n\t*\n\t* @private\n\t* @param {PRNGStateMT19937} s - generator state\n\t* @throws {Error} must provide a valid state\n\t*/\n\tfunction setState( s ) {\n\t\trand.state = s;\n\t}\n\n\t/**\n\t* Serializes the pseudorandom number generator as a JSON object.\n\t*\n\t* ## Notes\n\t*\n\t* - `JSON.stringify()` implicitly calls this method when stringifying a PRNG.\n\t*\n\t* @private\n\t* @returns {Object} JSON representation\n\t*/\n\tfunction toJSON() {\n\t\tvar out = {};\n\t\tout.type = 'PRNG';\n\t\tout.name = prng.NAME;\n\t\tout.state = typedarray2json( rand.state );\n\t\tif ( a === void 0 ) {\n\t\t\tout.params = [];\n\t\t} else {\n\t\t\tout.params = [ a, b, c ];\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with bound parameters.\n\t*\n\t* @private\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular1();\n\t* // returns \n\t*/\n\tfunction triangular1() {\n\t\treturn triangular0( rand, a, b, c );\n\t}\n\n\t/**\n\t* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @returns {number} pseudorandom number\n\t*\n\t* @example\n\t* var v = triangular2( 0.0, 1.0, 0.5 );\n\t* // returns \n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 0.0, 0.5 );\n\t* // returns NaN\n\t*\n\t* @example\n\t* var v = triangular2( 1.0, 2.0, NaN );\n\t* // returns NaN\n\t*/\n\tfunction triangular2( a, b, c ) {\n\t\tif (\n\t\t\tisnan( a ) ||\n\t\t\tisnan( b ) ||\n\t\t\tisnan( c ) ||\n\t\t\t!(a <= c && c <= b)\n\t\t) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn triangular0( rand, a, b, c );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isnan from '@stdlib/assert-is-nan';\n\n\n// MAIN //\n\n/**\n* Validates parameters.\n*\n* @private\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {(Error|null)} error or null\n*\n* @example\n* var err = validate( 1.0, 2.0, 1.3 );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( a, b, c ) {\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\treturn new TypeError( format( '0p96v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\treturn new TypeError( format( '0p96w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\treturn new TypeError( format( '0p97C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\treturn new RangeError( format( '0p99C', 'a <= c <= b', a, b, c ) );\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`.\n*\n* @name triangular\n* @type {PRNG}\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\n* @returns {number} pseudorandom number\n*\n* @example\n* var v = triangular( 0.0, 1.0, 0.5 );\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Triangular distributed pseudorandom numbers.\n*\n* @module @stdlib/random-base-triangular\n*\n* @example\n* import triangular from '@stdlib/random-base-triangular';\n*\n* var v = triangular( 0.0, 10.0, 7.0 );\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory( -5.0, 5.0, 3.0, {\n* 'seed': 297\n* });\n*\n* var v = triangular();\n* // returns \n*\n* @example\n* import { factory as factory } from '@stdlib/random-base-triangular';\n* var triangular = factory({\n* 'seed': 297\n* });\n*\n* var v = triangular( -5.0, 5.0, 3.0 );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["triangular","rand","a","b","c","fc","u","sqrt","factory","opts","prng","err","arguments","length","randu","isObject","TypeError","format","hasOwnProp","isFunction","isNumber","isnan","RangeError","validate","setReadOnly","NaN","triangular0","setReadWriteAccessor","constantFunction","noop","setReadOnlyAccessor","seed","seedLength","state","s","stateLength","byteLength","out","name","NAME","typedarray2json","params","normalized","main"],"mappings":";;u+CAqCA,SAASA,EAAYC,EAAMC,EAAGC,EAAGC,GAChC,IAAIC,EAEAC,EAGJ,OAFAD,GAAMD,EAAIF,IAAMC,EAAID,IACpBI,EAAIL,KACKI,EAEDH,EAAIK,GADNJ,EAAID,IAAME,EAAIF,GACEI,GAGfH,EAAII,GADNJ,EAAID,IAAMC,EAAIC,IACG,EAAME,GAC7B,CCwBA,SAASE,IACR,IAAIC,EACAR,EACAS,EACAC,EACAT,EACAC,EACAC,EAEJ,GAA0B,IAArBQ,UAAUC,OACdZ,EAAOa,SACD,GAA0B,IAArBF,UAAUC,OAAe,CAEpC,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IACf,MACGT,EAAOa,EAAOL,EAEjB,KAAQ,CAKN,GADAE,ECzDF,SAAmBT,EAAGC,EAAGC,GACxB,OAAMgB,EAAUlB,IAAOmB,EAAOnB,GACtB,IAAIc,UAAWC,EAAQ,QAASf,KAElCkB,EAAUjB,IAAOkB,EAAOlB,GACtB,IAAIa,UAAWC,EAAQ,QAASd,KAElCiB,EAAUhB,IAAOiB,EAAOjB,GACtB,IAAIY,UAAWC,EAAQ,QAASb,IAEjCF,GAAKE,GAAKA,GAAKD,EAGf,KAFC,IAAImB,WAAYL,EAAQ,QAAS,cAAef,EAAGC,EAAGC,GAG/D,CD2CQmB,CAHNrB,EAAIU,UAAW,GACfT,EAAIS,UAAW,GACfR,EAAIQ,UAAW,IAGd,MAAMD,EAEP,GAAKC,UAAUC,OAAS,EAAI,CAE3B,IAAME,EADNN,EAAOG,UAAW,IAEjB,MAAM,IAAII,UAAWC,EAAQ,QAASR,IAEvC,GAAKS,EAAYT,EAAM,QAAW,CACjC,IAAMU,EAAYV,EAAKC,MACtB,MAAM,IAAIM,UAAWC,EAAQ,QAAS,OAAQR,EAAKC,OAEpDT,EAAOQ,EAAKC,IAChB,MACIT,EAAOa,EAAOL,EAElB,MACGR,EAAOa,GAER,CA2BD,OArBAU,EAJCd,OADU,IAANR,EAmJL,SAAsBA,EAAGC,EAAGC,GAC3B,GACCiB,EAAOnB,IACPmB,EAAOlB,IACPkB,EAAOjB,MACLF,GAAKE,GAAKA,GAAKD,GAEjB,OAAOsB,IAER,OAAOC,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAnCD,WACC,OAAOsB,EAAazB,EAAMC,EAAGC,EAAGC,EAChC,EAvHkB,OAAQ,cAGtBK,GAAQA,EAAKC,MACjBc,EAAad,EAAM,OAAQ,MAC3Bc,EAAad,EAAM,aAAc,MACjCiB,EAAsBjB,EAAM,QAASkB,EAAkB,MAAQC,GAC/DL,EAAad,EAAM,cAAe,MAClCc,EAAad,EAAM,aAAc,MACjCc,EAAad,EAAM,SAAUkB,EAAkB,OAC/CJ,EAAad,EAAM,OAAQT,KAE3B6B,EAAqBpB,EAAM,QAiB5B,WACC,OAAOT,EAAK8B,IACZ,IAlBAD,EAAqBpB,EAAM,cA0B5B,WACC,OAAOT,EAAK+B,UACZ,IA3BAL,EAAsBjB,EAAM,SAuD7B,WACC,OAAOT,EAAKgC,KACZ,IASD,SAAmBC,GAClBjC,EAAKgC,MAAQC,CACb,IAnEAJ,EAAqBpB,EAAM,eAkC5B,WACC,OAAOT,EAAKkC,WACZ,IAnCAL,EAAqBpB,EAAM,cA2C5B,WACC,OAAOT,EAAKmC,UACZ,IA5CAZ,EAAad,EAAM,UA6EpB,WACC,IAAI2B,EAAM,CACVA,KAAW,QACXA,EAAIC,KAAO5B,EAAK6B,KAChBF,EAAIJ,MAAQO,EAAiBvC,EAAKgC,OAEjCI,EAAII,YADM,IAANvC,EACS,GAEA,CAAEA,EAAGC,EAAGC,GAEtB,OAAOiC,CACP,IAvFAb,EAAad,EAAM,OAAQT,GAC3BA,EAAOA,EAAKyC,YAENhC,CAoIR,CE/OG,IAACV,EAAaQ,ICkBjBgB,EAAAmB,EAAA,UAAAnC"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2346fdb..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,286 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var noop = require( '@stdlib/utils-noop' ); -var randu = require( '@stdlib/random-base-mt19937' ).factory; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var triangular0 = require( './triangular.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number generator for generating random numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {PRNG} pseudorandom number generator -* -* @example -* var triangular = factory( 0.0, 1.0, 0.8 ); -* -* var v = triangular(); -* // returns -* -* @example -* var triangular = factory( -3.0, -1.0, -2.0, { -* 'seed': 297 -* }); -* var v = triangular(); -* // returns -*/ -function factory() { - var opts; - var rand; - var prng; - var err; - var a; - var b; - var c; - - if ( arguments.length === 0 ) { - rand = randu(); - } else if ( arguments.length === 1 ) { - opts = arguments[ 0 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - a = arguments[ 0 ]; - b = arguments[ 1 ]; - c = arguments[ 2 ]; - err = validate( a, b, c ); - if ( err ) { - throw err; - } - if ( arguments.length > 3 ) { - opts = arguments[ 3 ]; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'prng' ) ) { - if ( !isFunction( opts.prng ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', opts.prng ) ); - } - rand = opts.prng; - } else { - rand = randu( opts ); - } - } else { - rand = randu(); - } - } - if ( a === void 0 ) { - prng = triangular2; - } else { - prng = triangular1; - } - setReadOnly( prng, 'NAME', 'triangular' ); - - // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity. - if ( opts && opts.prng ) { - setReadOnly( prng, 'seed', null ); - setReadOnly( prng, 'seedLength', null ); - setReadWriteAccessor( prng, 'state', constantFunction( null ), noop ); - setReadOnly( prng, 'stateLength', null ); - setReadOnly( prng, 'byteLength', null ); - setReadOnly( prng, 'toJSON', constantFunction( null ) ); - setReadOnly( prng, 'PRNG', rand ); - } else { - setReadOnlyAccessor( prng, 'seed', getSeed ); - setReadOnlyAccessor( prng, 'seedLength', getSeedLength ); - setReadWriteAccessor( prng, 'state', getState, setState ); - setReadOnlyAccessor( prng, 'stateLength', getStateLength ); - setReadOnlyAccessor( prng, 'byteLength', getStateSize ); - setReadOnly( prng, 'toJSON', toJSON ); - setReadOnly( prng, 'PRNG', rand ); - rand = rand.normalized; - } - return prng; - - /** - * Returns the PRNG seed. - * - * @private - * @returns {PRNGSeedMT19937} seed - */ - function getSeed() { - return rand.seed; - } - - /** - * Returns the PRNG seed length. - * - * @private - * @returns {PositiveInteger} seed length - */ - function getSeedLength() { - return rand.seedLength; - } - - /** - * Returns the PRNG state length. - * - * @private - * @returns {PositiveInteger} state length - */ - function getStateLength() { - return rand.stateLength; - } - - /** - * Returns the PRNG state size (in bytes). - * - * @private - * @returns {PositiveInteger} state size (in bytes) - */ - function getStateSize() { - return rand.byteLength; - } - - /** - * Returns the current pseudorandom number generator state. - * - * @private - * @returns {PRNGStateMT19937} current state - */ - function getState() { - return rand.state; - } - - /** - * Sets the pseudorandom number generator state. - * - * @private - * @param {PRNGStateMT19937} s - generator state - * @throws {Error} must provide a valid state - */ - function setState( s ) { - rand.state = s; - } - - /** - * Serializes the pseudorandom number generator as a JSON object. - * - * ## Notes - * - * - `JSON.stringify()` implicitly calls this method when stringifying a PRNG. - * - * @private - * @returns {Object} JSON representation - */ - function toJSON() { - var out = {}; - out.type = 'PRNG'; - out.name = prng.NAME; - out.state = typedarray2json( rand.state ); - if ( a === void 0 ) { - out.params = []; - } else { - out.params = [ a, b, c ]; - } - return out; - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with bound parameters. - * - * @private - * @returns {number} pseudorandom number - * - * @example - * var v = triangular1(); - * // returns - */ - function triangular1() { - return triangular0( rand, a, b, c ); - } - - /** - * Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @returns {number} pseudorandom number - * - * @example - * var v = triangular2( 0.0, 1.0, 0.5 ); - * // returns - * - * @example - * var v = triangular2( 1.0, 0.0, 0.5 ); - * // returns NaN - * - * @example - * var v = triangular2( 1.0, 2.0, NaN ); - * // returns NaN - */ - function triangular2( a, b, c ) { - if ( - isnan( a ) || - isnan( b ) || - isnan( c ) || - !(a <= c && c <= b) - ) { - return NaN; - } - return triangular0( rand, a, b, c ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 321424d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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'; - -/** -* Triangular distributed pseudorandom numbers. -* -* @module @stdlib/random-base-triangular -* -* @example -* var triangular = require( '@stdlib/random-base-triangular' ); -* -* var v = triangular( 0.0, 10.0, 7.0 ); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory( -5.0, 5.0, 3.0, { -* 'seed': 297 -* }); -* -* var v = triangular(); -* // returns -* -* @example -* var factory = require( '@stdlib/random-base-triangular' ).factory; -* var triangular = factory({ -* 'seed': 297 -* }); -* -* var v = triangular( -5.0, 5.0, 3.0 ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8512800..0000000 --- a/lib/main.js +++ /dev/null @@ -1,47 +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 factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b`, and mode `c`. -* -* @name triangular -* @type {PRNG} -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -* -* @example -* var v = triangular( 0.0, 1.0, 0.5 ); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/triangular.js b/lib/triangular.js deleted file mode 100644 index bdc4554..0000000 --- a/lib/triangular.js +++ /dev/null @@ -1,55 +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 sqrt = require( '@stdlib/math-base-special-sqrt' ); - - -// MAIN // - -/** -* Returns a pseudorandom number drawn from a triangular distribution with minimum support `a`, maximum support `b` and mode `c`. -* -* @private -* @param {PRNG} rand - PRNG for generating uniformly distributed numbers -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {number} pseudorandom number -*/ -function triangular( rand, a, b, c ) { - var fc; - var x; - var u; - fc = (c - a) / (b - a); - u = rand(); - if ( u < fc ) { - x = (b - a) * (c - a); - return a + sqrt( x * u ); - } - x = (b - a) * (b - c); - return b - sqrt( x * (1.0 - u) ); -} - - -// EXPORTS // - -module.exports = triangular; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 99526d7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,64 +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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var isnan = require( '@stdlib/assert-is-nan' ); - - -// MAIN // - -/** -* Validates parameters. -* -* @private -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @returns {(Error|null)} error or null -* -* @example -* var err = validate( 1.0, 2.0, 1.3 ); -* if ( err ) { -* throw err; -* } -*/ -function validate( a, b, c ) { - if ( !isNumber( a ) || isnan( a ) ) { - return new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - return new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - return new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - return new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5882b84..c2ce925 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Triangular distributed pseudorandom numbers.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-to-json": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-nan": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-sqrt": "^0.2.2", - "@stdlib/random-base-mt19937": "^0.2.1", - "@stdlib/string-format": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-constant-function": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/assert-is-uint32array": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/process-env": "^0.2.2", - "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/random-base-minstd-shuffle": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/stats-kstest": "^0.2.2", - "@stdlib/time-now": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dc929a3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + 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.factory.js b/test/test.factory.js deleted file mode 100644 index 62790ec..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,985 +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 ENV = require( '@stdlib/process-env' ); -var kstest = require( '@stdlib/stats-kstest' ); -var now = require( '@stdlib/time-now' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var typedarray2json = require( '@stdlib/array-to-json' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ENV.TEST_MODE === 'coverage' ) -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - factory( value, 2.0, 1.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - factory( 2.0, value, 3.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '5', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - factory( 2.0, 3.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.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( arr ) { - return function badValue() { - factory( arr[0], arr[1], arr[2] ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (no other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (other arguments)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - factory( 0.0, 1.0, 0.5, value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error (other arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 0.0, 1.0, 0.5, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', 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 a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - 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() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) { - var triangular; - var r; - var i; - - // When binding distribution parameters... - triangular = factory( -10.0, 10.0, 5.0 ); - for ( i = 0; i < 100; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - - // Without binding distribution parameters... - triangular = factory(); - for ( i = 0; i < 100; i++ ) { - r = triangular( -10.0, 10.0, 5.0 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (integer seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a seeded pseudorandom number generator (array seed)', function test( t ) { - var triangular1; - var triangular2; - var seed; - var r1; - var r2; - var i; - - seed = [ now()+1, now()+2, now()+3 ]; - - triangular1 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - triangular2 = factory( 0.0, 4.0, 2.0, { - 'seed': seed - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 100; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator name', function test( t ) { - var triangular = factory(); - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var triangular = factory({ - 'seed': 12345 - }); - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.equal( triangular.seed[ 0 ], 12345, 'equal to provided seed' ); - - triangular = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.equal( triangular.seed, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.equal( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.equal( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.seedLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var triangular = factory(); - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.state, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.stateLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var triangular = factory(); - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( triangular.byteLength, null, 'equal to `null`' ); - t.end(); -}); - -tape( 'attached to the returned function is a method to serialize the generator as a JSON object', function test( t ) { - var triangular; - var o; - - triangular = factory(); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - - o = triangular.toJSON(); - t.equal( o.type, 'PRNG', 'has property' ); - t.equal( o.name, triangular.NAME, 'has property' ); - t.deepEqual( o.state, typedarray2json( triangular.state ), 'has property' ); - t.deepEqual( o.params, [], 'has property' ); - - triangular = factory( 2.0, 4.0, 3.33 ); - o = triangular.toJSON(); - - t.deepEqual( o.params, [ 2.0, 4.0, 3.33 ], 'has property' ); - - triangular = factory({ - 'prng': minstd.normalized - }); - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.equal( triangular.toJSON(), null, 'returns expected value' ); - - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `a` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, 5.0, 2.5 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `b` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, NaN, 1.0 ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if `c` is `NaN`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( 0.0, 10.0, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if provided all `NaNs`', function test( t ) { - var triangular; - var r; - - triangular = factory(); - r = triangular( NaN, NaN, NaN ); - - t.strictEqual( isnan( r ), true, 'returns NaN' ); - t.end(); -}); - -tape( 'when called without arguments, the function returns a function that returns `NaN` if the condition `a <= c <= b` is not satisfied', function test( t ) { - var triangular; - var values; - var r; - var i; - - triangular = factory(); - values = [ - [ 2.0, 1.0, 1.5 ], - [ -5.0, -4.0, 3.14 ], - [ 0.0, 1.0, 5.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - r = triangular( values[ i ][ 0 ], values[ i ][ 1 ], values[ i ][ 2 ] ); - t.strictEqual( isnan( r ), true, 'returns `NaN` when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory( 1.0, 2.0, 1.5, { - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular(); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG (parameters)', function test( t ) { - var triangular; - var r; - var i; - - triangular = factory({ - 'prng': minstd.normalized - }); - - for ( i = 0; i < 1e2; i++ ) { - r = triangular( 1.0, 2.0, 1.5 ); - t.equal( typeof r, 'number', 'returns a number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory( 1.0, 2.0, 1.5, { - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1(); - r2 = triangular2(); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG (parameters)', function test( t ) { - var triangular1; - var triangular2; - var randu; - var seed; - var r1; - var r2; - var i; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - triangular1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - triangular2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( triangular1, triangular2, 'separate generators' ); - - for ( i = 0; i < 1e2; i++ ) { - r1 = triangular1( 1.0, 2.0, 1.5 ); - r2 = triangular2( 1.0, 2.0, 1.5 ); - t.equal( r1, r2, 'both return same number' ); - } - t.end(); -}); - -tape( 'the function returns a PRNG for generating random numbers from a triangular distribution', opts, function test( t ) { - var threshold; - var count; - var npass; - var N; - var a; - var b; - var c; - var x; - - threshold = 0.10; - - a = 2.0; - b = 4.0; - c = 3.33; - - x = new Array( 1e3 ); - N = 500; - - count = -1; - npass = 0; - - gof(); - - function gof() { - var triangular; - var rejected; - var pValue; - var bool; - var i; - var j; - - count += 1; - rejected = 0; - for ( i = 0; i < N; i++ ) { - triangular = factory( a, b, c ); - t.ok( true, 'seed: '+triangular.seed ); - for ( j = 0; j < x.length; j++ ) { - x[ j ] = triangular(); - if ( x[ j ] < a || x[ j ] > b ) { - t.ok( false, 'returned a number outside support: '+x[ j ] ); - } - } - // Test using Kolmogorov-Smirnov goodness-of-fit test: - pValue = kstest( x, 'triangular', a, b, c ).pValue; - t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue ); - if ( pValue < 0.05 ) { - rejected += 1; - } - } - // Account for small sample size and few repeats... - bool = ( rejected / N < threshold ); - - // If we succeed the first time, we are done... - if ( count === 0 && bool ) { - return done( bool, rejected ); - } - // Retry mode... - if ( bool ) { - npass += 1; - } - // Retry twice... - if ( count < 2 ) { - return gof(); - } - // Both retries must succeed for test to pass: - bool = ( npass >= 2 ); - return done( bool, rejected ); - } - - function done( bool, rejected ) { - t.ok( bool, 'null hypothesis (i.e., that numbers are drawn from Triangular('+a+','+b+','+c+')) is rejected in less than '+(threshold*100)+'% of cases ('+rejected+' of '+N+'). Repeats: '+npass+' of '+count+'.' ); - t.end(); - } -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create another PRNG using the captured state: - triangular = factory( 0.0, 1.0, 0.5, { - 'state': state - }); - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); - -tape( 'the function supports specifying a shared generator state', function test( t ) { - var triangular; - var shared; - var state; - var rand1; - var rand2; - var arr; - var v1; - var v2; - var i; - var j; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - - // Create PRNGs using the captured state: - rand1 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - rand2 = factory( 0.0, 1.0, 0.5, { - 'state': shared, - 'copy': false - }); - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - v2 = rand2(); - } - - // Reset the (shared) state: - rand1.state = state; - - // Replay previously generated values... - j = 0; - for ( i = 0; i < 25; i++ ) { - v1 = rand1(); - v2 = rand2(); - t.equal( v1, arr[ j ], 'returns expected value. i: '+j+'.' ); - t.equal( v2, arr[ j+1 ], 'returns expected value. i: '+(j+1)+'.' ); - j += 2; // stride - } - t.end(); -}); - -tape( 'the returned function supports setting the generator state', function test( t ) { - var triangular; - var state; - var arr; - var i; - - triangular = factory( 0.0, 1.0, 0.5 ); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular(); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular() ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular(), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7ce370a..0000000 --- a/test/test.js +++ /dev/null @@ -1,124 +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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var triangular = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof triangular, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { - t.equal( typeof triangular.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { - t.equal( typeof triangular.toJSON, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is the generator name', function test( t ) { - t.equal( triangular.NAME, 'triangular', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.equal( typeof triangular.PRNG, 'function', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.equal( isUint32Array( triangular.seed ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.equal( typeof triangular.seedLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.equal( isUint32Array( triangular.state ), true, 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.equal( typeof triangular.stateLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.equal( typeof triangular.byteLength, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function returns pseudorandom numbers', function test( t ) { - var r; - var a; - var b; - var c; - var i; - - a = 200.0; - b = 499.974; - c = 211.33; - for ( i = 0; i < 1e2; i++ ) { - r = triangular( a, b, c ); - t.equal( typeof r, 'number', 'returns a number' ); - t.equal( r >= a && r <= b, true, 'within support: '+r ); - } - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - triangular( 0.0, 1.0, 0.5 ); - } - // Capture the current state: - state = triangular.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 100; i++ ) { - arr.push( triangular( 0.0, 1.0, 0.5 ) ); - } - // Set the state: - triangular.state = state; - - // Replay previously generated values... - for ( i = 0; i < 100; i++ ) { - t.equal( triangular( 0.0, 1.0, 0.5 ), arr[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); -});