From 44643e79ae03314b976657dcbad2495d8e6c8079 Mon Sep 17 00:00:00 2001 From: praneki Date: Sun, 25 Feb 2024 22:53:46 +0530 Subject: [PATCH 1/4] feat: add @stdlib/math/iter/sequences/tribonacci added whole section --- .../math/iter/sequences/tribonacci/README.md | 215 +++++++++++++++ .../tribonacci/benchmark/benchmark.js | 71 +++++ ...quation_tribonacci_recurrence_relation.svg | 44 +++ .../docs/img/equation_tribonacci_sequence.svg | 84 ++++++ .../iter/sequences/tribonacci/docs/repl.txt | 46 ++++ .../tribonacci/docs/types/index.d.ts | 74 +++++ .../sequences/tribonacci/docs/types/tests.ts | 45 ++++ .../sequences/tribonacci/examples/index.js | 34 +++ .../iter/sequences/tribonacci/lib/index.js | 50 ++++ .../iter/sequences/tribonacci/lib/main.js | 168 ++++++++++++ .../iter/sequences/tribonacci/lib/validate.js | 69 +++++ .../iter/sequences/tribonacci/package.json | 65 +++++ .../iter/sequences/tribonacci/tests/test.js | 255 ++++++++++++++++++ .../tribonacci/tests/test.validate.js | 147 ++++++++++ 14 files changed, 1367 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md new file mode 100644 index 000000000000..936c6afd16b0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md @@ -0,0 +1,215 @@ + + +# iterTribonacciSeq + +> Create an iterator which generates a [tribonacci sequence][tribonacci-number]. + + + +
+ +The [Tribonacci numbers][tribonacci-number] are the integer sequence + + + +```math +0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, \ldots +``` + + + + + +The sequence is defined by the recurrence relation + + + +```math +F_n = F_{n-1} + F_{n-2} + F_{n-3} +``` + + + + + +with seed values `F_0 = 0`, `F_1 = 0`, and `F_2 = 1`. + +
+ + + + + +
+ +## Usage + +```javascript +var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); +``` + +#### iterTribonacciSeq( \[options] ) + +Returns an iterator which generates a [Tribonacci sequence][tribonacci-number]. + +```javascript +var it = iterTribonacciSeq(); +// returns + +var v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 1 + +// ... +``` + +The returned iterator protocol-compliant object has the following properties: + +- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. +- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. + +The function supports the following `options`: + +- **iter**: number of iterations. Default: `64`. + +The returned iterator can only generate the first `64` [Tribonacci numbers][tribonacci-number], as larger [Tribonacci numbers][tribonacci-number] cannot be safely represented in [double-precision floating-point format][ieee754]. By default, the function returns an iterator which generates all `64` numbers. To limit the number of iterations, set the `iter` option. + +```javascript +var opts = { + 'iter': 3 +}; +var it = iterTribonacciSeq( opts ); +// returns + +var v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 1 + +var bool = it.next().done; +// returns true +``` + + + + + + + +
+ +## Notes + +- If an environment supports `Symbol.iterator`, the returned iterator is iterable. + +
+ + + + + +
+ +## Examples + + + +```javascript +var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); + +// Create an iterator: +var it = iterTribonacciSeq(); + +// Perform manual iteration... +var v; +while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + console.log( v.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js new file mode 100644 index 000000000000..91e19e2555cf --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js @@ -0,0 +1,71 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var pkg = require( './../package.json' ).name; +var iterTribonacciSeq = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterTribonacciSeq(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var z; + var i; + + iter = iterTribonacciSeq(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = iter.next().value; + if ( isnan( z ) ) { + b.fail( 'should not be NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg new file mode 100644 index 000000000000..c49388bf2d32 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg @@ -0,0 +1,44 @@ + +upper F Subscript n Baseline equals upper F Subscript n minus 1 Baseline plus upper F Subscript n minus 2 Baseline plus upper F Subscript n minus 3 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg new file mode 100644 index 000000000000..4035b968717b --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg @@ -0,0 +1,84 @@ + +0 comma 0 comma 1 comma 1 comma 2 comma 4 comma 7 comma 13 comma 24 comma 44 comma 81 comma 149 comma 274 comma 504 comma 927 comma 1705 comma ellipsis + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt new file mode 100644 index 000000000000..6eb9cc3c2163 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( [options] ) + Returns an iterator which generates a Tribonacci sequence. + + The returned iterator can only generate the first 64 Tribonacci numbers, as + larger Tribonacci numbers cannot be safely represented in double-precision + floating-point format. + + If an environment supports Symbol.iterator, the returned iterator is + iterable. + + Parameters + ---------- + options: Object (optional) + Function options. + + options.iter: integer (optional) + Number of iterations. Default: 64. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object has the next + iterated value (if one exists) and a boolean flag indicating whether the + iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var it = {{alias}}(); + > var v = it.next().value + 0 + > v = it.next().value + 0 + > v = it.next().value + 1 + + See Also + -------- + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts new file mode 100644 index 000000000000..a021f8875098 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Interface describing function options. +*/ +interface Options { + /** + * Number of iterations. + */ + iter?: number; +} + +/** +* Returns an iterator which generates a Tribonacci sequence. +* +* ## Notes +* +* - The returned iterator can only generate the first `64` Tribonacci numbers, as larger Tribonacci numbers cannot be safely represented in double-precision floating-point format. +* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. +* +* @param options - function options +* @param options.iter - number of iterations (default: 64) +* @throws `iter` option must be a nonnegative integer +* @throws `iter` option must be less than or equal to 64 +* @returns iterator +* +* @example +* var iter = iterTribonacciSeq(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* v = iter.next().value; +* // returns 2 +* +* // ... +*/ +declare function iterTribonacciSeq( options?: Options ): Iterator; + + +// EXPORTS //s + +export = iterTribonacciSeq; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts new file mode 100644 index 000000000000..6b171a9823ee --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts @@ -0,0 +1,45 @@ +/* +* @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 iterTribonacciSeq = require( './index' ); + + + +// TESTS // + +// The function returns an iterator... +{ + iterTribonacciSeq(); // $ExpectType Iterator + iterTribonacciSeq( {} ); // $ExpectType Iterator + iterTribonacciSeq( { 'iter': 10 } ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an options object... +{ + iterTribonacciSeq( null ); // $ExpectError +} + +// The compiler throws an error if the function is provided an `iter` option which is not a number... +{ + iterTribonacciSeq( { 'iter': '5' } ); // $ExpectError + iterTribonacciSeq( { 'iter': true } ); // $ExpectError + iterTribonacciSeq( { 'iter': false } ); // $ExpectError + iterTribonacciSeq( { 'iter': null } ); // $ExpectError + iterTribonacciSeq( { 'iter': [] } ); // $ExpectError + iterTribonacciSeq( { 'iter': {} } ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js new file mode 100644 index 000000000000..cacebd3ff3ce --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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. +*/ + +'use strict'; + +var iterTribonacciSeq = require('./../lib'); + +// Create an iterator: +var it = iterTribonacciSeq(); + +// Perform manual iteration... +var v; +while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + console.log( v.value ); +} diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js new file mode 100644 index 000000000000..dec7cb774a79 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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. +*/ + +'use strict'; + +/** +* Create an iterator which generates a Tribonacci sequence. +* +* @module @stdlib/math/iter/sequences/tribonacci +* +* @example +* var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); +* +* var iter = iterTribonacciSeq(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* // ... +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js new file mode 100644 index 000000000000..6c9e5a254813 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js @@ -0,0 +1,168 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var validate = require( './validate.js' ); + + +// VARIABLES // + +var F0 = 0; +var F1 = 0; +var F2 = 1; + + +// MAIN // + +/** +* Returns an iterator which generates a Tribonacci sequence. +* +* ## Notes +* +* - The returned iterator can only generate the first `63` Tribonacci numbers, as larger Tribonacci numbers cannot be safely represented in double-precision floating-point format. +* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. +* +* @param {Options} [options] - function options +* @param {NonNegativeInteger} [options.iter=64] - number of iterations +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @throws {RangeError} `iter` option must be less than or equal to `64` +* @returns {Iterator} iterator +* +* @example +* var iter = iterTribonacciSeq(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* // ... +*/ +function iterTribonacciSeq( options ) { + var opts; + var iter; + var FLG; + var err; + var f1; + var f2; + var f3; + var f; + var i; + + opts = { + 'iter': 64 + }; + if ( arguments.length ) { + err = validate( opts, options ); + if ( err ) { + throw err; + } + } + f1 = F0; + f2 = F1; + f3 = F2; + f = 0; + i = 0; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator`, make the iterator iterable: + if ( iteratorSymbol ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + i += 1; + if ( FLG || i > opts.iter ) { + return { + 'done': true + }; + } + if ( i === 1 ) { + f = F0; + } else if ( i === 2 ) { + f = F1; + } else if( i == 3 ){ + f=F2; + }else { + f = f1 + f2 + f3; + f1 = f2; + f2 = f3; + f3 = f; + } + return { + 'value': f, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterTribonacciSeq( opts ); + } +} + + +// EXPORTS // + +module.exports = iterTribonacciSeq; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js new file mode 100644 index 000000000000..384677955fb0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js @@ -0,0 +1,69 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Validates function options. +* +* @private +* @param {Object} opts - destination object +* @param {Options} options - function options +* @param {NonNegativeInteger} [options.iter] - number of iterations +* @returns {(Error|null)} null or an error object +* +* @example +* var opts = {}; +* var options = { +* 'iter': 50 +* }; +* var err = validate( opts, options ); +* if ( err ) { +* throw err; +* } +*/ +function validate( opts, options ) { + if ( !isPlainObject( options ) ) { + return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'iter' ) ) { + opts.iter = options.iter; + if ( !isNonNegativeInteger( options.iter ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) ); + } + if ( options.iter > 64 ) { + return new RangeError( format( 'invalid option. `%s` option must be less than or equal to 64. Option: `%u`.', 'iter', options.iter ) ); + } + } + return null; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json new file mode 100644 index 000000000000..153503620dcd --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/math/iter/sequences/tribonacci", + "version": "0.0.0", + "description": "Create an iterator which generates a Tribonacci sequence.", + "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": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "tribonacci", + "tribo", + "sequence", + "iterator", + "iterate", + "iteration", + "iter" + ] + } + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js new file mode 100644 index 000000000000..dbf0d03b825d --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js @@ -0,0 +1,255 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var tribonacci = require( '@stdlib/math/base/special/tribonacci' ); +var iterTribonacciSeq = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterTribonacciSeq, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterTribonacciSeq( value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 3.14159265, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterTribonacciSeq({ + 'iter': value + }); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object which generates a Tribonacci sequence', function test( t ) { + var expected; + var actual; + var it; + var i; + + it = iterTribonacciSeq(); + t.equal( it.next.length, 0, 'has zero arity' ); + + for ( i = 0; i < 64; i++ ) { + actual = it.next(); + expected = tribonacci( i ); + t.equal( actual.value, expected, 'returns expected value' ); + t.equal( actual.done, false, 'returns expected value' ); + } + actual = it.next(); + t.equal( actual.value, void 0, 'returns expected value' ); + t.equal( actual.done, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports limiting the number of iterations', function test( t ) { + var expected; + var actual; + var opts; + var it; + var i; + + expected = [ + { + 'value': 0, + 'done': false + }, + { + 'value': 0, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'value': 2, + 'done': false + }, + { + 'done': true + } + ]; + + opts = { + 'iter': 5 + }; + it = iterTribonacciSeq( opts ); + t.equal( it.next.length, 0, 'has zero arity' ); + + actual = []; + for ( i = 0; i < opts.iter; i++ ) { + actual.push( it.next() ); + } + actual.push( it.next() ); + + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterTribonacciSeq(); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterTribonacciSeq(); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'finished' ); + t.equal( r.value, 'finished', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { + var iterTribonacciSeq; + var it1; + var it2; + var i; + + iterTribonacciSeq = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + it1 = iterTribonacciSeq(); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 10; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterTribonacciSeq; + var it; + + iterTribonacciSeq = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterTribonacciSeq(); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js new file mode 100644 index 000000000000..635a1f10c935 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js @@ -0,0 +1,147 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var validate = require( './../lib/validate.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof validate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + void 0, + null, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[ i ] ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided an `iter` option which is not a nonnegative integer', function test( t ) { + var values; + var opts; + var err; + var i; + + values = [ + '5', + -1, + 3.14159265, + NaN, + true, + false, + void 0, + null, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + opts = { + 'iter': values[ i ] + }; + err = validate( {}, opts ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided an `iter` option which is greater than `64`', function test( t ) { + var values; + var opts; + var err; + var i; + + values = [ + 65, + 69, + 70, + 82, + 83, + 84 + ]; + + for ( i = 0; i < values.length; i++ ) { + opts = { + 'iter': values[ i ] + }; + err = validate( {}, opts ); + t.strictEqual( err instanceof RangeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var options; + var opts; + var err; + + opts = {}; + options = { + 'iter': 50 + }; + + err = validate( opts, options ); + t.strictEqual( err, null, 'returns null' ); + t.deepEqual( opts, options, 'sets options' ); + + t.end(); +}); + +tape( 'the function will ignore unrecognized options', function test( t ) { + var options; + var opts; + var err; + + opts = {}; + options = { + 'ping': true, + 'ping': 'pong' + }; + + err = validate( opts, options ); + t.strictEqual( err, null, 'returns null' ); + t.deepEqual( opts, {}, 'ignores unrecognized options' ); + + t.end(); +}); From 558100d917b62674f5d1075e1f61070315fb6f98 Mon Sep 17 00:00:00 2001 From: praneki Date: Sun, 25 Feb 2024 23:02:43 +0530 Subject: [PATCH 2/4] Revert "feat: add @stdlib/math/iter/sequences/tribonacci added whole section" This reverts commit 44643e79ae03314b976657dcbad2495d8e6c8079. --- .../math/iter/sequences/tribonacci/README.md | 215 --------------- .../tribonacci/benchmark/benchmark.js | 71 ----- ...quation_tribonacci_recurrence_relation.svg | 44 --- .../docs/img/equation_tribonacci_sequence.svg | 84 ------ .../iter/sequences/tribonacci/docs/repl.txt | 46 ---- .../tribonacci/docs/types/index.d.ts | 74 ----- .../sequences/tribonacci/docs/types/tests.ts | 45 ---- .../sequences/tribonacci/examples/index.js | 34 --- .../iter/sequences/tribonacci/lib/index.js | 50 ---- .../iter/sequences/tribonacci/lib/main.js | 168 ------------ .../iter/sequences/tribonacci/lib/validate.js | 69 ----- .../iter/sequences/tribonacci/package.json | 65 ----- .../iter/sequences/tribonacci/tests/test.js | 255 ------------------ .../tribonacci/tests/test.validate.js | 147 ---------- 14 files changed, 1367 deletions(-) delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js delete mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md deleted file mode 100644 index 936c6afd16b0..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md +++ /dev/null @@ -1,215 +0,0 @@ - - -# iterTribonacciSeq - -> Create an iterator which generates a [tribonacci sequence][tribonacci-number]. - - - -
- -The [Tribonacci numbers][tribonacci-number] are the integer sequence - - - -```math -0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, \ldots -``` - - - - - -The sequence is defined by the recurrence relation - - - -```math -F_n = F_{n-1} + F_{n-2} + F_{n-3} -``` - - - - - -with seed values `F_0 = 0`, `F_1 = 0`, and `F_2 = 1`. - -
- - - - - -
- -## Usage - -```javascript -var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); -``` - -#### iterTribonacciSeq( \[options] ) - -Returns an iterator which generates a [Tribonacci sequence][tribonacci-number]. - -```javascript -var it = iterTribonacciSeq(); -// returns - -var v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 1 - -// ... -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -The function supports the following `options`: - -- **iter**: number of iterations. Default: `64`. - -The returned iterator can only generate the first `64` [Tribonacci numbers][tribonacci-number], as larger [Tribonacci numbers][tribonacci-number] cannot be safely represented in [double-precision floating-point format][ieee754]. By default, the function returns an iterator which generates all `64` numbers. To limit the number of iterations, set the `iter` option. - -```javascript -var opts = { - 'iter': 3 -}; -var it = iterTribonacciSeq( opts ); -// returns - -var v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. - -
- - - - - -
- -## Examples - - - -```javascript -var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); - -// Create an iterator: -var it = iterTribonacciSeq(); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js deleted file mode 100644 index 91e19e2555cf..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js +++ /dev/null @@ -1,71 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var iterTribonacciSeq = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = iterTribonacciSeq(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var z; - var i; - - iter = iterTribonacciSeq(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg deleted file mode 100644 index c49388bf2d32..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg +++ /dev/null @@ -1,44 +0,0 @@ - -upper F Subscript n Baseline equals upper F Subscript n minus 1 Baseline plus upper F Subscript n minus 2 Baseline plus upper F Subscript n minus 3 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg deleted file mode 100644 index 4035b968717b..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg +++ /dev/null @@ -1,84 +0,0 @@ - -0 comma 0 comma 1 comma 1 comma 2 comma 4 comma 7 comma 13 comma 24 comma 44 comma 81 comma 149 comma 274 comma 504 comma 927 comma 1705 comma ellipsis - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt deleted file mode 100644 index 6eb9cc3c2163..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( [options] ) - Returns an iterator which generates a Tribonacci sequence. - - The returned iterator can only generate the first 64 Tribonacci numbers, as - larger Tribonacci numbers cannot be safely represented in double-precision - floating-point format. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.iter: integer (optional) - Number of iterations. Default: 64. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object has the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}(); - > var v = it.next().value - 0 - > v = it.next().value - 0 - > v = it.next().value - 1 - - See Also - -------- - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts deleted file mode 100644 index a021f8875098..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts +++ /dev/null @@ -1,74 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Number of iterations. - */ - iter?: number; -} - -/** -* Returns an iterator which generates a Tribonacci sequence. -* -* ## Notes -* -* - The returned iterator can only generate the first `64` Tribonacci numbers, as larger Tribonacci numbers cannot be safely represented in double-precision floating-point format. -* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. -* -* @param options - function options -* @param options.iter - number of iterations (default: 64) -* @throws `iter` option must be a nonnegative integer -* @throws `iter` option must be less than or equal to 64 -* @returns iterator -* -* @example -* var iter = iterTribonacciSeq(); -* -* var v = iter.next().value; -* // returns 0 -* -* v = iter.next().value; -* // returns 0 -* -* v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* // ... -*/ -declare function iterTribonacciSeq( options?: Options ): Iterator; - - -// EXPORTS //s - -export = iterTribonacciSeq; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts deleted file mode 100644 index 6b171a9823ee..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/tests.ts +++ /dev/null @@ -1,45 +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 iterTribonacciSeq = require( './index' ); - - - -// TESTS // - -// The function returns an iterator... -{ - iterTribonacciSeq(); // $ExpectType Iterator - iterTribonacciSeq( {} ); // $ExpectType Iterator - iterTribonacciSeq( { 'iter': 10 } ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not an options object... -{ - iterTribonacciSeq( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `iter` option which is not a number... -{ - iterTribonacciSeq( { 'iter': '5' } ); // $ExpectError - iterTribonacciSeq( { 'iter': true } ); // $ExpectError - iterTribonacciSeq( { 'iter': false } ); // $ExpectError - iterTribonacciSeq( { 'iter': null } ); // $ExpectError - iterTribonacciSeq( { 'iter': [] } ); // $ExpectError - iterTribonacciSeq( { 'iter': {} } ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js deleted file mode 100644 index cacebd3ff3ce..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js +++ /dev/null @@ -1,34 +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. -*/ - -'use strict'; - -var iterTribonacciSeq = require('./../lib'); - -// Create an iterator: -var it = iterTribonacciSeq(); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js deleted file mode 100644 index dec7cb774a79..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js +++ /dev/null @@ -1,50 +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. -*/ - -'use strict'; - -/** -* Create an iterator which generates a Tribonacci sequence. -* -* @module @stdlib/math/iter/sequences/tribonacci -* -* @example -* var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); -* -* var iter = iterTribonacciSeq(); -* -* var v = iter.next().value; -* // returns 0 -* -* v = iter.next().value; -* // returns 0 -* -* v = iter.next().value; -* // returns 1 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js deleted file mode 100644 index 6c9e5a254813..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js +++ /dev/null @@ -1,168 +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. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var F0 = 0; -var F1 = 0; -var F2 = 1; - - -// MAIN // - -/** -* Returns an iterator which generates a Tribonacci sequence. -* -* ## Notes -* -* - The returned iterator can only generate the first `63` Tribonacci numbers, as larger Tribonacci numbers cannot be safely represented in double-precision floating-point format. -* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. -* -* @param {Options} [options] - function options -* @param {NonNegativeInteger} [options.iter=64] - number of iterations -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} `iter` option must be less than or equal to `64` -* @returns {Iterator} iterator -* -* @example -* var iter = iterTribonacciSeq(); -* -* var v = iter.next().value; -* // returns 0 -* -* v = iter.next().value; -* // returns 0 -* -* v = iter.next().value; -* // returns 1 -* -* // ... -*/ -function iterTribonacciSeq( options ) { - var opts; - var iter; - var FLG; - var err; - var f1; - var f2; - var f3; - var f; - var i; - - opts = { - 'iter': 64 - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - f1 = F0; - f2 = F1; - f3 = F2; - f = 0; - i = 0; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i > opts.iter ) { - return { - 'done': true - }; - } - if ( i === 1 ) { - f = F0; - } else if ( i === 2 ) { - f = F1; - } else if( i == 3 ){ - f=F2; - }else { - f = f1 + f2 + f3; - f1 = f2; - f2 = f3; - f3 = f; - } - return { - 'value': f, - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return iterTribonacciSeq( opts ); - } -} - - -// EXPORTS // - -module.exports = iterTribonacciSeq; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js deleted file mode 100644 index 384677955fb0..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js +++ /dev/null @@ -1,69 +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. -*/ - -'use strict'; - -// MODULES // - -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'iter': 50 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isPlainObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'iter' ) ) { - opts.iter = options.iter; - if ( !isNonNegativeInteger( options.iter ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) ); - } - if ( options.iter > 64 ) { - return new RangeError( format( 'invalid option. `%s` option must be less than or equal to 64. Option: `%u`.', 'iter', options.iter ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json deleted file mode 100644 index 153503620dcd..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "name": "@stdlib/math/iter/sequences/tribonacci", - "version": "0.0.0", - "description": "Create an iterator which generates a Tribonacci sequence.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdmath", - "mathematics", - "math", - "tribonacci", - "tribo", - "sequence", - "iterator", - "iterate", - "iteration", - "iter" - ] - } - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js deleted file mode 100644 index dbf0d03b825d..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.js +++ /dev/null @@ -1,255 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var tribonacci = require( '@stdlib/math/base/special/tribonacci' ); -var iterTribonacciSeq = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof iterTribonacciSeq, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - iterTribonacciSeq( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14159265, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - iterTribonacciSeq({ - 'iter': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which generates a Tribonacci sequence', function test( t ) { - var expected; - var actual; - var it; - var i; - - it = iterTribonacciSeq(); - t.equal( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < 64; i++ ) { - actual = it.next(); - expected = tribonacci( i ); - t.equal( actual.value, expected, 'returns expected value' ); - t.equal( actual.done, false, 'returns expected value' ); - } - actual = it.next(); - t.equal( actual.value, void 0, 'returns expected value' ); - t.equal( actual.done, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports limiting the number of iterations', function test( t ) { - var expected; - var actual; - var opts; - var it; - var i; - - expected = [ - { - 'value': 0, - 'done': false - }, - { - 'value': 0, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - opts = { - 'iter': 5 - }; - it = iterTribonacciSeq( opts ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < opts.iter; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = iterTribonacciSeq(); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = iterTribonacciSeq(); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var iterTribonacciSeq; - var it1; - var it2; - var i; - - iterTribonacciSeq = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - it1 = iterTribonacciSeq(); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < 10; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var iterTribonacciSeq; - var it; - - iterTribonacciSeq = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = iterTribonacciSeq(); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js deleted file mode 100644 index 635a1f10c935..000000000000 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/tests/test.validate.js +++ /dev/null @@ -1,147 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `iter` option which is not a nonnegative integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -1, - 3.14159265, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'iter': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `iter` option which is greater than `64`', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 65, - 69, - 70, - 82, - 83, - 84 - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'iter': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof RangeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'iter': 50 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'ping': true, - 'ping': 'pong' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 98b7e4dd3bafbab51875121134bb2d709a85a3bd Mon Sep 17 00:00:00 2001 From: praneki Date: Mon, 26 Feb 2024 23:42:40 +0530 Subject: [PATCH 3/4] feat: add @stdlib/math/iter/sequences/tribonacci --- .../math/iter/sequences/tribonacci/README.md | 215 +++++++++++++++ .../tribonacci/benchmark/benchmark.js | 71 +++++ ...quation_tribonacci_recurrence_relation.svg | 44 +++ .../docs/img/equation_tribonacci_sequence.svg | 84 ++++++ .../iter/sequences/tribonacci/docs/repl.txt | 48 ++++ .../tribonacci/docs/types/index.d.ts | 74 +++++ .../sequences/tribonacci/docs/types/test.ts | 44 +++ .../sequences/tribonacci/examples/index.js | 34 +++ .../iter/sequences/tribonacci/lib/index.js | 50 ++++ .../iter/sequences/tribonacci/lib/main.js | 168 ++++++++++++ .../iter/sequences/tribonacci/lib/validate.js | 69 +++++ .../iter/sequences/tribonacci/package.json | 65 +++++ .../iter/sequences/tribonacci/test/test.js | 255 ++++++++++++++++++ .../tribonacci/test/test.validate.js | 147 ++++++++++ 14 files changed, 1368 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js create mode 100644 lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md new file mode 100644 index 000000000000..936c6afd16b0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md @@ -0,0 +1,215 @@ + + +# iterTribonacciSeq + +> Create an iterator which generates a [tribonacci sequence][tribonacci-number]. + + + +
+ +The [Tribonacci numbers][tribonacci-number] are the integer sequence + + + +```math +0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, \ldots +``` + + + + + +The sequence is defined by the recurrence relation + + + +```math +F_n = F_{n-1} + F_{n-2} + F_{n-3} +``` + + + + + +with seed values `F_0 = 0`, `F_1 = 0`, and `F_2 = 1`. + +
+ + + + + +
+ +## Usage + +```javascript +var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); +``` + +#### iterTribonacciSeq( \[options] ) + +Returns an iterator which generates a [Tribonacci sequence][tribonacci-number]. + +```javascript +var it = iterTribonacciSeq(); +// returns + +var v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 1 + +// ... +``` + +The returned iterator protocol-compliant object has the following properties: + +- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. +- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. + +The function supports the following `options`: + +- **iter**: number of iterations. Default: `64`. + +The returned iterator can only generate the first `64` [Tribonacci numbers][tribonacci-number], as larger [Tribonacci numbers][tribonacci-number] cannot be safely represented in [double-precision floating-point format][ieee754]. By default, the function returns an iterator which generates all `64` numbers. To limit the number of iterations, set the `iter` option. + +```javascript +var opts = { + 'iter': 3 +}; +var it = iterTribonacciSeq( opts ); +// returns + +var v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 1 + +var bool = it.next().done; +// returns true +``` + + + + + + + +
+ +## Notes + +- If an environment supports `Symbol.iterator`, the returned iterator is iterable. + +
+ + + + + +
+ +## Examples + + + +```javascript +var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); + +// Create an iterator: +var it = iterTribonacciSeq(); + +// Perform manual iteration... +var v; +while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + console.log( v.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js new file mode 100644 index 000000000000..91e19e2555cf --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js @@ -0,0 +1,71 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var pkg = require( './../package.json' ).name; +var iterTribonacciSeq = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterTribonacciSeq(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var z; + var i; + + iter = iterTribonacciSeq(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = iter.next().value; + if ( isnan( z ) ) { + b.fail( 'should not be NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg new file mode 100644 index 000000000000..c49388bf2d32 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_recurrence_relation.svg @@ -0,0 +1,44 @@ + +upper F Subscript n Baseline equals upper F Subscript n minus 1 Baseline plus upper F Subscript n minus 2 Baseline plus upper F Subscript n minus 3 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg new file mode 100644 index 000000000000..4035b968717b --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/img/equation_tribonacci_sequence.svg @@ -0,0 +1,84 @@ + +0 comma 0 comma 1 comma 1 comma 2 comma 4 comma 7 comma 13 comma 24 comma 44 comma 81 comma 149 comma 274 comma 504 comma 927 comma 1705 comma ellipsis + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt new file mode 100644 index 000000000000..dcbd8486e0d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/repl.txt @@ -0,0 +1,48 @@ + +{{alias}}( [options] ) + Returns an iterator which generates a Tribonacci sequence. + + The returned iterator can only generate the first 64 Tribonacci numbers, as + larger Tribonacci numbers cannot be safely represented in double-precision + floating-point format. + + If an environment supports Symbol.iterator, the returned iterator is + iterable. + + + Parameters + ---------- + options: Object (optional) + Function options. + + options.iter: integer (optional) + Number of iterations. Default: 64. + + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant + object has the next + iterated value (if one exists) and a + boolean flag indicating whether the + iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + + Examples + -------- + > var it = {{alias}}(); + > var v = it.next().value + 0 + > v = it.next().value + 0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts new file mode 100644 index 000000000000..a021f8875098 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Interface describing function options. +*/ +interface Options { + /** + * Number of iterations. + */ + iter?: number; +} + +/** +* Returns an iterator which generates a Tribonacci sequence. +* +* ## Notes +* +* - The returned iterator can only generate the first `64` Tribonacci numbers, as larger Tribonacci numbers cannot be safely represented in double-precision floating-point format. +* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. +* +* @param options - function options +* @param options.iter - number of iterations (default: 64) +* @throws `iter` option must be a nonnegative integer +* @throws `iter` option must be less than or equal to 64 +* @returns iterator +* +* @example +* var iter = iterTribonacciSeq(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* v = iter.next().value; +* // returns 2 +* +* // ... +*/ +declare function iterTribonacciSeq( options?: Options ): Iterator; + + +// EXPORTS //s + +export = iterTribonacciSeq; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts new file mode 100644 index 000000000000..e0306080019b --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @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 iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); + + +// TESTS // + +// The function returns an iterator... +{ + iterTribonacciSeq(); // $ExpectType Iterator + iterTribonacciSeq( {} ); // $ExpectType Iterator + iterTribonacciSeq( { 'iter': 10 } ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an options object... +{ + iterTribonacciSeq( null ); // $ExpectError +} + +// The compiler throws an error if the function is provided an `iter` option which is not a number... +{ + iterTribonacciSeq( { 'iter': '5' } ); // $ExpectError + iterTribonacciSeq( { 'iter': true } ); // $ExpectError + iterTribonacciSeq( { 'iter': false } ); // $ExpectError + iterTribonacciSeq( { 'iter': null } ); // $ExpectError + iterTribonacciSeq( { 'iter': [] } ); // $ExpectError + iterTribonacciSeq( { 'iter': {} } ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js new file mode 100644 index 000000000000..cacebd3ff3ce --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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. +*/ + +'use strict'; + +var iterTribonacciSeq = require('./../lib'); + +// Create an iterator: +var it = iterTribonacciSeq(); + +// Perform manual iteration... +var v; +while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + console.log( v.value ); +} diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js new file mode 100644 index 000000000000..dec7cb774a79 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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. +*/ + +'use strict'; + +/** +* Create an iterator which generates a Tribonacci sequence. +* +* @module @stdlib/math/iter/sequences/tribonacci +* +* @example +* var iterTribonacciSeq = require( '@stdlib/math/iter/sequences/tribonacci' ); +* +* var iter = iterTribonacciSeq(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* // ... +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js new file mode 100644 index 000000000000..6aefeca8f18b --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js @@ -0,0 +1,168 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var validate = require( './validate.js' ); + + +// VARIABLES // + +var F0 = 0; +var F1 = 0; +var F2 = 1; + + +// MAIN // + +/** +* Returns an iterator which generates a Tribonacci sequence. +* +* ## Notes +* +* - The returned iterator can only generate the first `63` Tribonacci numbers, as larger Tribonacci numbers cannot be safely represented in double-precision floating-point format. +* - If an environment supports `Symbol.iterator`, the returned iterator is iterable. +* +* @param {Options} [options] - function options +* @param {NonNegativeInteger} [options.iter=64] - number of iterations +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @throws {RangeError} `iter` option must be less than or equal to `64` +* @returns {Iterator} iterator +* +* @example +* var iter = iterTribonacciSeq(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* // ... +*/ +function iterTribonacciSeq( options ) { + var opts; + var iter; + var FLG; + var err; + var f1; + var f2; + var f3; + var f; + var i; + + opts = { + 'iter': 64 + }; + if ( arguments.length ) { + err = validate( opts, options ); + if ( err ) { + throw err; + } + } + f1 = F0; + f2 = F1; + f3 = F2; + f = 0; + i = 0; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator`, make the iterator iterable: + if ( iteratorSymbol ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + i += 1; + if ( FLG || i > opts.iter ) { + return { + 'done': true + }; + } + if ( i === 1 ) { + f = F0; + } else if ( i === 2 ) { + f = F1; + } else if ( i === 3 ) { + f=F2; + } else { + f = f1 + f2 + f3; + f1 = f2; + f2 = f3; + f3 = f; + } + return { + 'value': f, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterTribonacciSeq( opts ); + } +} + + +// EXPORTS // + +module.exports = iterTribonacciSeq; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js new file mode 100644 index 000000000000..384677955fb0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js @@ -0,0 +1,69 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Validates function options. +* +* @private +* @param {Object} opts - destination object +* @param {Options} options - function options +* @param {NonNegativeInteger} [options.iter] - number of iterations +* @returns {(Error|null)} null or an error object +* +* @example +* var opts = {}; +* var options = { +* 'iter': 50 +* }; +* var err = validate( opts, options ); +* if ( err ) { +* throw err; +* } +*/ +function validate( opts, options ) { + if ( !isPlainObject( options ) ) { + return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'iter' ) ) { + opts.iter = options.iter; + if ( !isNonNegativeInteger( options.iter ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) ); + } + if ( options.iter > 64 ) { + return new RangeError( format( 'invalid option. `%s` option must be less than or equal to 64. Option: `%u`.', 'iter', options.iter ) ); + } + } + return null; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json new file mode 100644 index 000000000000..153503620dcd --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/math/iter/sequences/tribonacci", + "version": "0.0.0", + "description": "Create an iterator which generates a Tribonacci sequence.", + "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": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "tribonacci", + "tribo", + "sequence", + "iterator", + "iterate", + "iteration", + "iter" + ] + } + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js new file mode 100644 index 000000000000..b79cdf1c9228 --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js @@ -0,0 +1,255 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var tribonacci = require( '@stdlib/math/base/special/tribonacci' ); +var iterTribonacciSeq = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterTribonacciSeq, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterTribonacciSeq( value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 3.14159265, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterTribonacciSeq({ + 'iter': value + }); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object which generates a Tribonacci sequence', function test( t ) { + var expected; + var actual; + var it; + var i; + + it = iterTribonacciSeq(); + t.equal( it.next.length, 0, 'has zero arity' ); + + for ( i = 0; i < 64; i++ ) { + actual = it.next(); + expected = tribonacci( i ); + t.equal( actual.value, expected, 'returns expected value' ); + t.equal( actual.done, false, 'returns expected value' ); + } + actual = it.next(); + t.equal( actual.value, void 0, 'returns expected value' ); + t.equal( actual.done, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports limiting the number of iterations', function test( t ) { + var expected; + var actual; + var opts; + var it; + var i; + + expected = [ + { + 'value': 0, + 'done': false + }, + { + 'value': 0, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'value': 2, + 'done': false + }, + { + 'done': true + } + ]; + + opts = { + 'iter': 5 + }; + it = iterTribonacciSeq( opts ); + t.equal( it.next.length, 0, 'has zero arity' ); + + actual = []; + for ( i = 0; i < opts.iter; i++ ) { + actual.push( it.next() ); + } + actual.push( it.next() ); + + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterTribonacciSeq(); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterTribonacciSeq(); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'number', 'returns a number' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'finished' ); + t.equal( r.value, 'finished', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { + var iterTribonacciSeq; + var it1; + var it2; + var i; + + iterTribonacciSeq = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + it1 = iterTribonacciSeq(); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 10; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterTribonacciSeq; + var it; + + iterTribonacciSeq = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterTribonacciSeq(); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js new file mode 100644 index 000000000000..dd667647d9cb --- /dev/null +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js @@ -0,0 +1,147 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var validate = require( './../lib/validate.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof validate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + void 0, + null, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[ i ] ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided an `iter` option which is not a nonnegative integer', function test( t ) { + var values; + var opts; + var err; + var i; + + values = [ + '5', + -1, + 3.14159265, + NaN, + true, + false, + void 0, + null, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + opts = { + 'iter': values[ i ] + }; + err = validate( {}, opts ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided an `iter` option which is greater than `64`', function test( t ) { + var values; + var opts; + var err; + var i; + + values = [ + 65, + 69, + 70, + 82, + 83, + 84 + ]; + + for ( i = 0; i < values.length; i++ ) { + opts = { + 'iter': values[ i ] + }; + err = validate( {}, opts ); + t.strictEqual( err instanceof RangeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var options; + var opts; + var err; + + opts = {}; + options = { + 'iter': 50 + }; + + err = validate( opts, options ); + t.strictEqual( err, null, 'returns null' ); + t.deepEqual( opts, options, 'sets options' ); + + t.end(); +}); + +tape( 'the function will ignore unrecognized options', function test( t ) { + var options; + var opts; + var err; + + opts = {}; + options = { + 'beep': true, + 'ping': 'pong' + }; + + err = validate( opts, options ); + t.strictEqual( err, null, 'returns null' ); + t.deepEqual( opts, {}, 'ignores unrecognized options' ); + + t.end(); +}); From 6436ce3594234dbcbdc2c730a393be9612501e7d Mon Sep 17 00:00:00 2001 From: praneki Date: Tue, 27 Feb 2024 02:36:57 +0530 Subject: [PATCH 4/4] feat: add @stdlib/math/iter/sequences/tribonacci updated copyright year --- .../@stdlib/math/iter/sequences/tribonacci/README.md | 2 +- .../math/iter/sequences/tribonacci/benchmark/benchmark.js | 2 +- .../math/iter/sequences/tribonacci/docs/types/index.d.ts | 2 +- .../@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts | 2 +- .../@stdlib/math/iter/sequences/tribonacci/examples/index.js | 2 +- .../@stdlib/math/iter/sequences/tribonacci/lib/index.js | 2 +- .../@stdlib/math/iter/sequences/tribonacci/lib/main.js | 2 +- .../@stdlib/math/iter/sequences/tribonacci/lib/validate.js | 2 +- .../@stdlib/math/iter/sequences/tribonacci/test/test.js | 2 +- .../math/iter/sequences/tribonacci/test/test.validate.js | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md index 936c6afd16b0..9426d4d72ce5 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2019 The Stdlib Authors. +Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js index 91e19e2555cf..0258ee58b40a 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts index a021f8875098..72cff68e4c19 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts index e0306080019b..31d4966c473d 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js index cacebd3ff3ce..75a61f73e78e 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js index dec7cb774a79..757f25afb043 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js index 6aefeca8f18b..20ab0628f360 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js index 384677955fb0..83508855d0db 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/lib/validate.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js index b79cdf1c9228..f1a53dc7d971 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js index dd667647d9cb..0f8d0c3a139b 100644 --- a/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js +++ b/lib/node_modules/@stdlib/math/iter/sequences/tribonacci/test/test.validate.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.