diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.at.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.at.js new file mode 100644 index 000000000000..bfbaa617a566 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.at.js @@ -0,0 +1,134 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has an `at` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'at' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.at ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.at.call( value, 0 ); + }; + } +}); + +tape( 'the method returns the tuple element at a given index', function test( t ) { + var Point; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + v = p.at( 0 ); + t.strictEqual( v, 1, 'returns expected value' ); + + v = p.at( 1 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = p.at( 2 ); + t.strictEqual( v, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var Point; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + v = p.at( -1 ); + t.strictEqual( v, 3, 'returns expected value' ); + + v = p.at( -2 ); + t.strictEqual( v, 2, 'returns expected value' ); + + v = p.at( -3 ); + t.strictEqual( v, 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `undefined` if the index is out of bounds', function test( t ) { + var Point; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + v = p.at( 10 ); + t.strictEqual( v, void 0, 'returns expected value' ); + + v = p.at( -10 ); + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.entries.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.entries.js new file mode 100644 index 000000000000..d2995bd2eea6 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.entries.js @@ -0,0 +1,192 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var namedtypedtuple = require( './../lib' ); + + +// VARIABLES // + +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has an `entries` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasOwnProp( p, 'entries' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.entries ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.entries.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object which iterates over tuple key-value pairs', function test( t ) { + var Point; + var iter; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter = p.entries(); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + t.deepEqual( v.value, [ 0, 'x', 10 ], 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + t.deepEqual( v.value, [ 1, 'y', 20 ], 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + t.deepEqual( v.value, [ 2, 'z', 30 ], 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + t.strictEqual( v.value, void 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var Point; + var iter; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter = p.entries(); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = iter.return(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var Point; + var iter; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter = p.entries(); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = iter.return( 'finished' ); + t.strictEqual( v.value, 'finished', 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { + var Point; + var iter1; + var iter2; + var v1; + var v2; + var p; + + if ( !HAS_ITERATOR_SYMBOL ) { + t.pass( 'environment does not support Symbol.iterator' ); + return t.end(); + } + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter1 = p.entries(); + + t.strictEqual( isFunction( iter1[ ITERATOR_SYMBOL ] ), true, 'returns expected value' ); + + iter2 = iter1[ ITERATOR_SYMBOL ](); + + v1 = iter1.next(); + v2 = iter2.next(); + + t.deepEqual( v1.value, v2.value, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.every.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.every.js new file mode 100644 index 000000000000..e2f90e400353 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.every.js @@ -0,0 +1,207 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has an `every` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'every' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.every ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.every.call( value, fcn ); + }; + } + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.every( value ); + }; + } +}); + +tape( 'the method returns `true` if all elements pass a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.every( fcn ); + + t.strictEqual( out, true, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method returns `false` if not all elements pass a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, -2, 3 ] ); + out = p.every( fcn ); + + t.strictEqual( out, false, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.every( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return true; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.every( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + return true; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.field_of.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.field_of.js new file mode 100644 index 000000000000..f2208cef01f7 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.field_of.js @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `fieldOf` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'fieldOf' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.fieldOf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.fieldOf.call( value, 1 ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.fieldOf( 1, value ); + }; + } +}); + +tape( 'the method returns the field name of the first element strictly equal to a search element', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.fieldOf( 2 ); + t.strictEqual( out, 'y', 'returns expected value' ); + + out = p.fieldOf( 1 ); + t.strictEqual( out, 'x', 'returns expected value' ); + + out = p.fieldOf( 3 ); + t.strictEqual( out, 'z', 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `undefined` if unable to locate a search element', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.fieldOf( 10 ); + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + out = p.fieldOf( 1, 1 ); + t.strictEqual( out, 'z', 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a negative starting index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + out = p.fieldOf( 1, -2 ); + t.strictEqual( out, 'z', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `undefined` if the starting index exceeds the tuple length', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.fieldOf( 1, 10 ); + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js new file mode 100644 index 000000000000..98900c023425 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js @@ -0,0 +1,213 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `fill` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'fill' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.fill ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.fill.call( value, 1 ); + }; + } +}); + +tape( 'the method returns the tuple', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.fill( 9 ); + + t.strictEqual( out, p, 'returns expected value' ); + t.end(); +}); + +tape( 'the method fills all tuple elements with a value', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.fill( 9 ); + + t.strictEqual( p[ 0 ], 9, 'returns expected value' ); + t.strictEqual( p[ 1 ], 9, 'returns expected value' ); + t.strictEqual( p[ 2 ], 9, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 9, 'returns expected value' ); + t.strictEqual( p.y, 9, 'returns expected value' ); + t.strictEqual( p.z, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the method fills tuple elements from a start index', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.fill( 9, 1 ); + + t.strictEqual( p[ 0 ], 1, 'returns expected value' ); + t.strictEqual( p[ 1 ], 9, 'returns expected value' ); + t.strictEqual( p[ 2 ], 9, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 9, 'returns expected value' ); + t.strictEqual( p.z, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the method fills tuple elements from a start index to an end index (non-inclusive)', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.fill( 9, 0, 2 ); + + t.strictEqual( p[ 0 ], 9, 'returns expected value' ); + t.strictEqual( p[ 1 ], 9, 'returns expected value' ); + t.strictEqual( p[ 2 ], 3, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 9, 'returns expected value' ); + t.strictEqual( p.y, 9, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative start indices', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.fill( 9, -2 ); + + t.strictEqual( p[ 0 ], 1, 'returns expected value' ); + t.strictEqual( p[ 1 ], 9, 'returns expected value' ); + t.strictEqual( p[ 2 ], 9, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 9, 'returns expected value' ); + t.strictEqual( p.z, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative end indices', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.fill( 9, 0, -1 ); + + t.strictEqual( p[ 0 ], 9, 'returns expected value' ); + t.strictEqual( p[ 1 ], 9, 'returns expected value' ); + t.strictEqual( p[ 2 ], 3, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 9, 'returns expected value' ); + t.strictEqual( p.y, 9, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method is a no-op if the starting index is greater than or equal to the ending index', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.fill( 9, 2, 1 ); + + t.strictEqual( p[ 0 ], 1, 'returns expected value' ); + t.strictEqual( p[ 1 ], 2, 'returns expected value' ); + t.strictEqual( p[ 2 ], 3, 'returns expected value' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.filter.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.filter.js new file mode 100644 index 000000000000..2e8407f68962 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.filter.js @@ -0,0 +1,231 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `filter` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'filter' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.filter ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.filter.call( value, fcn ); + }; + } + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.filter( value ); + }; + } +}); + +tape( 'the method returns a new tuple containing elements which pass a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, -2, 3 ] ); + out = p.filter( fcn ); + + t.notEqual( out, p, 'returns expected value' ); + t.deepEqual( out.fields, [ 'x', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 1, 'returns expected value' ); + t.strictEqual( out[ 1 ], 3, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method returns a new tuple with all fields if all elements pass', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.filter( fcn ); + + t.notEqual( out, p, 'returns expected value' ); + t.deepEqual( out.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 1, 'returns expected value' ); + t.strictEqual( out[ 1 ], 2, 'returns expected value' ); + t.strictEqual( out[ 2 ], 3, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method returns `null` if no elements pass a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.filter( fcn ); + + t.strictEqual( out, null, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 10; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.filter( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return true; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.filter( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + return true; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find.js new file mode 100644 index 000000000000..536f92ff2998 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find.js @@ -0,0 +1,207 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `find` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'find' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.find ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.find.call( value, fcn ); + }; + } + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.find( value ); + }; + } +}); + +tape( 'the method returns the first element which passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.find( fcn ); + + t.strictEqual( out, 2, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 1; + } +}); + +tape( 'the method returns `undefined` if no element passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.find( fcn ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 10; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.find( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return false; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.find( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + return false; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_field.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_field.js new file mode 100644 index 000000000000..bb8625eadb3b --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_field.js @@ -0,0 +1,207 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `findField` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'findField' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.findField ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.findField.call( value, fcn ); + }; + } + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.findField( value ); + }; + } +}); + +tape( 'the method returns the field name of the first element which passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.findField( fcn ); + + t.strictEqual( out, 'y', 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 1; + } +}); + +tape( 'the method returns `undefined` if no element passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.findField( fcn ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 10; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.findField( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return false; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.findField( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + return false; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_index.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_index.js new file mode 100644 index 000000000000..e95ad65402dd --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_index.js @@ -0,0 +1,207 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `findIndex` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'findIndex' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.findIndex ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.findIndex.call( value, fcn ); + }; + } + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.findIndex( value ); + }; + } +}); + +tape( 'the method returns the index of the first element which passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.findIndex( fcn ); + + t.strictEqual( out, 1, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 1; + } +}); + +tape( 'the method returns `-1` if no element passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.findIndex( fcn ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v > 10; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.findIndex( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return false; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.findIndex( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + return false; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js index 39c99d237837..80b31fd2e5e6 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js @@ -132,7 +132,7 @@ tape( 'the method returns `undefined`', function test( t ) { } }); -tape( 'the method invokes a provided function for each element in a tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -149,12 +149,12 @@ tape( 'the method invokes a provided function for each element in a tuple', func p = new Point( [ 1, 2, 3 ] ); p.forEach( fcn ); - t.deepEqual( values, [ 1, 2, 3 ], 'returns expected values' ); - t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected indices' ); - t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected field names' ); - t.strictEqual( tuples[ 0 ], p, 'returns expected tuple reference' ); - t.strictEqual( tuples[ 1 ], p, 'returns expected tuple reference' ); - t.strictEqual( tuples[ 2 ], p, 'returns expected tuple reference' ); + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from.js new file mode 100644 index 000000000000..c922a3ee9d06 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from.js @@ -0,0 +1,311 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var namedtypedtuple = require( './../lib' ); + + +// VARIABLES // + +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); + + +// FUNCTIONS // + +/** +* Returns an iterable object. +* +* @private +* @param {Array} arr - source array +* @returns {Object} iterable object +*/ +function createIterable( arr ) { + var obj = {}; + var i = -1; + if ( HAS_ITERATOR_SYMBOL ) { + obj[ ITERATOR_SYMBOL ] = iterator; + } + return obj; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + i += 1; + if ( i < arr.length ) { + return { + 'value': arr[ i ], + 'done': false + }; + } + return { + 'done': true + }; + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple factory has a `from` method', function test( t ) { + var Point; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + t.strictEqual( hasOwnProp( Point, 'from' ), true, 'returns expected value' ); + t.strictEqual( isFunction( Point.from ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not the host tuple factory', function test( t ) { + var values; + var Point; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Point.from.call( value, [ 1, 2 ] ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var Point; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Point.from( [ 1, 2 ], value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an array-like object or an iterable', function test( t ) { + var values; + var Point; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + 5, + 3.14, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Point.from( value ); + }; + } +}); + +tape( 'the method throws a range error if provided an array-like object whose length is incompatible with the number of tuple fields', function test( t ) { + var Point; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + return Point.from( [ 1, 2, 3 ] ); + } +}); + +tape( 'the method creates a new tuple from an array-like object', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.from( [ 10, 20, 30 ] ); + + t.strictEqual( p[ 0 ], 10, 'returns expected value' ); + t.strictEqual( p[ 1 ], 20, 'returns expected value' ); + t.strictEqual( p[ 2 ], 30, 'returns expected value' ); + t.deepEqual( p.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method creates a new tuple from an iterable', function test( t ) { + var Point; + var p; + + if ( !HAS_ITERATOR_SYMBOL ) { + t.pass( 'environment does not support Symbol.iterator' ); + return t.end(); + } + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.from( createIterable( [ 10, 20, 30 ] ) ); + + t.strictEqual( p[ 0 ], 10, 'returns expected value' ); + t.strictEqual( p[ 1 ], 20, 'returns expected value' ); + t.strictEqual( p[ 2 ], 30, 'returns expected value' ); + t.deepEqual( p.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method creates a new tuple from an iterable using a callback', function test( t ) { + var Point; + var p; + + if ( !HAS_ITERATOR_SYMBOL ) { + t.pass( 'environment does not support Symbol.iterator' ); + return t.end(); + } + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.from( createIterable( [ 10, 20, 30 ] ), fcn ); + + t.strictEqual( p[ 0 ], 20, 'returns expected value' ); + t.strictEqual( p[ 1 ], 40, 'returns expected value' ); + t.strictEqual( p[ 2 ], 60, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v * 2; + } +}); + +tape( 'the method creates a new tuple from an array-like object using a callback', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.from( [ 10, 20, 30 ], fcn ); + + t.strictEqual( p[ 0 ], 20, 'returns expected value' ); + t.strictEqual( p[ 1 ], 40, 'returns expected value' ); + t.strictEqual( p[ 2 ], 60, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v * 2; + } +}); + +tape( 'the callback is invoked with three arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var Point; + + if ( !HAS_ITERATOR_SYMBOL ) { + t.pass( 'environment does not support Symbol.iterator' ); + return t.end(); + } + values = []; + indices = []; + fieldNames = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + Point.from( createIterable( [ 10, 20, 30 ] ), fcn ); + + t.deepEqual( values, [ 10, 20, 30 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); + + function fcn( v, i, f ) { + values.push( v ); + indices.push( i ); + fieldNames.push( f ); + return v; + } +}); + +tape( 'the method supports providing a callback execution context', function test( t ) { + var Point; + var ctx; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + Point.from( [ 10, 20, 30 ], fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); + + function fcn( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from_object.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from_object.js new file mode 100644 index 000000000000..29dd083b1f13 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from_object.js @@ -0,0 +1,270 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple factory has a `fromObject` method', function test( t ) { + var Point; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + t.strictEqual( hasOwnProp( Point, 'fromObject' ), true, 'returns expected value' ); + t.strictEqual( isFunction( Point.fromObject ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not the host tuple factory', function test( t ) { + var values; + var Point; + var opts; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + 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() { + opts = { + 'x': 1, + 'y': 2 + }; + return Point.fromObject.call( value, opts ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an object', function test( t ) { + var values; + var Point; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + '5', + 5, + 3.14, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Point.fromObject( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var Point; + var opts; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'x': 1, + 'y': 2 + }; + return Point.fromObject( opts, value ); + }; + } +}); + +tape( 'the method creates a new tuple from an object', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.fromObject({ + 'x': 10, + 'y': 20, + 'z': 30 + }); + + t.strictEqual( p[ 0 ], 10, 'returns expected value' ); + t.strictEqual( p[ 1 ], 20, 'returns expected value' ); + t.strictEqual( p[ 2 ], 30, 'returns expected value' ); + t.deepEqual( p.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method ignores object properties which are not tuple fields', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = Point.fromObject({ + 'x': 10, + 'y': 20, + 'extra': 999 + }); + + t.strictEqual( p[ 0 ], 10, 'returns expected value' ); + t.strictEqual( p[ 1 ], 20, 'returns expected value' ); + t.end(); +}); + +tape( 'the method sets missing fields to zero', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.fromObject({ + 'x': 10 + }); + + t.strictEqual( p[ 0 ], 10, 'returns expected value' ); + t.strictEqual( p[ 1 ], 0, 'returns expected value' ); + t.strictEqual( p[ 2 ], 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method creates a new tuple from an object using a callback', function test( t ) { + var Point; + var opts; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + opts = { + 'x': 10, + 'y': 20, + 'z': 30 + }; + p = Point.fromObject( opts, fcn ); + + t.strictEqual( p[ 0 ], 20, 'returns expected value' ); + t.strictEqual( p[ 1 ], 40, 'returns expected value' ); + t.strictEqual( p[ 2 ], 60, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v * 2; + } +}); + +tape( 'the callback is invoked with two arguments', function test( t ) { + var fieldNames; + var values; + var Point; + var opts; + + values = []; + fieldNames = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + opts = { + 'x': 10, + 'y': 20, + 'z': 30 + }; + Point.fromObject( opts, fcn ); + + t.deepEqual( values, [ 10, 20, 30 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); + + function fcn( v, f ) { + values.push( v ); + fieldNames.push( f ); + return v; + } +}); + +tape( 'the method supports providing a callback execution context', function test( t ) { + var Point; + var opts; + var ctx; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + opts = { + 'x': 10, + 'y': 20, + 'z': 30 + }; + Point.fromObject( opts, fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); + + function fcn( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.includes.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.includes.js new file mode 100644 index 000000000000..f20c3c09266d --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.includes.js @@ -0,0 +1,179 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has an `includes` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'includes' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.includes ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.includes.call( value, 1 ); + }; + } +}); + +tape( 'the method returns `true` if a tuple includes a search element', function test( t ) { + var Point; + var bool; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + bool = p.includes( 1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = p.includes( 2 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = p.includes( 3 ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `false` if a tuple does not include a search element', function test( t ) { + var Point; + var bool; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + bool = p.includes( 10 ); + t.strictEqual( bool, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a starting index', function test( t ) { + var Point; + var bool; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + bool = p.includes( 1, 1 ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = p.includes( 3, 1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a negative starting index', function test( t ) { + var Point; + var bool; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + bool = p.includes( 1, -2 ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = p.includes( 3, -1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method does not distinguish between signed and unsigned zero', function test( t ) { + var Point; + var bool; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 0.0, 1.0 ] ); + + bool = p.includes( -0.0 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = p.includes( 0.0 ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method can find NaN values', function test( t ) { + var Point; + var bool; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ NaN, 1 ] ); + + bool = p.includes( NaN ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.ind2key.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.ind2key.js new file mode 100644 index 000000000000..115411fd7b7e --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.ind2key.js @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has an `ind2key` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'ind2key' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.ind2key ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.ind2key.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.ind2key( value ); + }; + } +}); + +tape( 'the method converts a tuple index to a field name', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.strictEqual( p.ind2key( 0 ), 'x', 'returns expected value' ); + t.strictEqual( p.ind2key( 1 ), 'y', 'returns expected value' ); + t.strictEqual( p.ind2key( 2 ), 'z', 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.strictEqual( p.ind2key( -1 ), 'z', 'returns expected value' ); + t.strictEqual( p.ind2key( -2 ), 'y', 'returns expected value' ); + t.strictEqual( p.ind2key( -3 ), 'x', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `undefined` if provided an out-of-bounds index', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.strictEqual( p.ind2key( 10 ), void 0, 'returns expected value' ); + t.strictEqual( p.ind2key( -10 ), void 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.index_of.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.index_of.js new file mode 100644 index 000000000000..ed33ae544a9f --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.index_of.js @@ -0,0 +1,201 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has an `indexOf` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'indexOf' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.indexOf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.indexOf.call( value, 1 ); + }; + } +}); + +tape( 'the method returns the index of the first element strictly equal to a search element', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + idx = p.indexOf( 2 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = p.indexOf( 1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + idx = p.indexOf( 3 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `-1` if unable to locate a search element', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + idx = p.indexOf( 10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a starting index', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + idx = p.indexOf( 1, 1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a negative starting index', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + idx = p.indexOf( 1, -2 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `-1` if the starting index exceeds the tuple length', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + idx = p.indexOf( 1, 10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method does not distinguish between signed and unsigned zero', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 0.0, -0.0 ] ); + + idx = p.indexOf( 0.0 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + idx = p.indexOf( -0.0 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns the index of the first occurrence when there are duplicates', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + idx = p.indexOf( 1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `-1` when searching for NaN', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ NaN, 1 ] ); + + idx = p.indexOf( NaN ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.join.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.join.js new file mode 100644 index 000000000000..9207991e2e5c --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.join.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `join` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'join' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.join ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.join.call( value ); + }; + } +}); + +tape( 'the method joins all tuple elements as a string using a comma as the default separator', function test( t ) { + var Point; + var str; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 0, -1 ], 'int32' ); + + str = p.join(); + + t.strictEqual( str, '1,0,-1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a separator', function test( t ) { + var Point; + var str; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 0, -1 ], 'int32' ); + + str = p.join( '|' ); + + t.strictEqual( str, '1|0|-1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports an empty string separator', function test( t ) { + var Point; + var str; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 0, -1 ], 'int32' ); + + str = p.join( '' ); + + t.strictEqual( str, '10-1', 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns an empty string for an empty tuple', function test( t ) { + var Point; + var str; + var p; + + Point = namedtypedtuple( [] ); + p = new Point(); + + str = p.join(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.key2ind.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.key2ind.js new file mode 100644 index 000000000000..0d6b325611ba --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.key2ind.js @@ -0,0 +1,137 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `key2ind` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'key2ind' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.key2ind ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.key2ind.call( value, 'x' ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a string', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + 5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.key2ind( value ); + }; + } +}); + +tape( 'the method converts a field name to a tuple index', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.strictEqual( p.key2ind( 'x' ), 0, 'returns expected value' ); + t.strictEqual( p.key2ind( 'y' ), 1, 'returns expected value' ); + t.strictEqual( p.key2ind( 'z' ), 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if provided an unknown field name', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.strictEqual( p.key2ind( 'w' ), -1, 'returns expected value' ); + t.strictEqual( p.key2ind( 'foo' ), -1, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.keys.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.keys.js new file mode 100644 index 000000000000..6b6c0a6bb93e --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.keys.js @@ -0,0 +1,192 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var namedtypedtuple = require( './../lib' ); + + +// VARIABLES // + +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `keys` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasOwnProp( p, 'keys' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.keys ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.keys.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object which iterates over tuple keys', function test( t ) { + var Point; + var iter; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter = p.keys(); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + t.deepEqual( v.value, [ 0, 'x' ], 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + t.deepEqual( v.value, [ 1, 'y' ], 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + t.deepEqual( v.value, [ 2, 'z' ], 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + t.strictEqual( v.value, void 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var Point; + var iter; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter = p.keys(); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = iter.return(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var Point; + var iter; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter = p.keys(); + + v = iter.next(); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = iter.return( 'finished' ); + t.strictEqual( v.value, 'finished', 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { + var Point; + var iter1; + var iter2; + var v1; + var v2; + var p; + + if ( !HAS_ITERATOR_SYMBOL ) { + t.pass( 'environment does not support Symbol.iterator' ); + return t.end(); + } + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + iter1 = p.keys(); + + t.strictEqual( isFunction( iter1[ ITERATOR_SYMBOL ] ), true, 'returns expected value' ); + + iter2 = iter1[ ITERATOR_SYMBOL ](); + + v1 = iter1.next(); + v2 = iter2.next(); + + t.deepEqual( v1.value, v2.value, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_field_of.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_field_of.js new file mode 100644 index 000000000000..720c1aa59444 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_field_of.js @@ -0,0 +1,194 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `lastFieldOf` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'lastFieldOf' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.lastFieldOf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.lastFieldOf.call( value, 1 ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.lastFieldOf( 1, value ); + }; + } +}); + +tape( 'the method returns the field name of the last element strictly equal to a search element', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + out = p.lastFieldOf( 1 ); + t.strictEqual( out, 'z', 'returns expected value' ); + + out = p.lastFieldOf( 2 ); + t.strictEqual( out, 'y', 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `undefined` if unable to locate a search element', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.lastFieldOf( 10 ); + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + out = p.lastFieldOf( 1, 1 ); + t.strictEqual( out, 'x', 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a negative starting index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + out = p.lastFieldOf( 1, -2 ); + t.strictEqual( out, 'x', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `undefined` if a negative starting index resolves to a negative index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.lastFieldOf( 1, -10 ); + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method clamps a starting index which exceeds the maximum tuple index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.lastFieldOf( 3, 100 ); + t.strictEqual( out, 'z', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_index_of.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_index_of.js new file mode 100644 index 000000000000..720405a6805d --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_index_of.js @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `lastIndexOf` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'lastIndexOf' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.lastIndexOf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.lastIndexOf.call( value, 1 ); + }; + } +}); + +tape( 'the method returns the index of the last element strictly equal to a search element', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + idx = p.lastIndexOf( 1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + idx = p.lastIndexOf( 2 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `-1` if unable to locate a search element', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + idx = p.lastIndexOf( 10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a starting index', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + idx = p.lastIndexOf( 1, 1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a negative starting index', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 1 ] ); + + idx = p.lastIndexOf( 1, -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `-1` if the starting index resolves to an index less than zero', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + idx = p.lastIndexOf( 1, -10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method does not distinguish between signed and unsigned zero', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ -0.0, 0.0 ] ); + + idx = p.lastIndexOf( 0.0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = p.lastIndexOf( -0.0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns `-1` when searching for NaN', function test( t ) { + var Point; + var idx; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ NaN, 1 ] ); + + idx = p.lastIndexOf( NaN ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.map.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.map.js new file mode 100644 index 000000000000..2d928e399deb --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.map.js @@ -0,0 +1,194 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `map` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'map' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.map ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.map.call( value, fcn ); + }; + } + + function fcn( v ) { + return v * 2; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.map( value ); + }; + } +}); + +tape( 'the method returns a new tuple with mapped values', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.map( fcn ); + + t.notEqual( out, p, 'returns expected value' ); + t.strictEqual( out[ 0 ], 2, 'returns expected value' ); + t.strictEqual( out[ 1 ], 4, 'returns expected value' ); + t.strictEqual( out[ 2 ], 6, 'returns expected value' ); + t.deepEqual( out.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v * 2; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.map( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return v; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.map( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.of.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.of.js new file mode 100644 index 000000000000..04dfff3534fc --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.of.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple factory has an `of` method', function test( t ) { + var Point; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + t.strictEqual( hasOwnProp( Point, 'of' ), true, 'returns expected value' ); + t.strictEqual( isFunction( Point.of ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not the host tuple factory', function test( t ) { + var values; + var Point; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Point.of.call( value, 1, 2 ); + }; + } +}); + +tape( 'the method throws a range error if the number of arguments is incompatible with the number of tuple fields', function test( t ) { + var values; + var Point; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + values = [ + [], + [ 1 ], + [ 1, 2, 3 ], + [ 1, 2, 3, 4 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an array of length '+values[ i ].length ); + } + t.end(); + + function badValue( args ) { + return function badValue() { + return Point.of.apply( Point, args ); + }; + } +}); + +tape( 'the method creates a new tuple from a variable number of arguments', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = Point.of( 10, 20, 30 ); + + t.strictEqual( p[ 0 ], 10, 'returns expected value' ); + t.strictEqual( p[ 1 ], 20, 'returns expected value' ); + t.strictEqual( p[ 2 ], 30, 'returns expected value' ); + t.deepEqual( p.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce.js new file mode 100644 index 000000000000..4683ea14f090 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce.js @@ -0,0 +1,210 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `reduce` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'reduce' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.reduce ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.reduce.call( value, fcn ); + }; + } + + function fcn( acc, v ) { + return acc + v; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.reduce( value ); + }; + } +}); + +tape( 'the method reduces tuple elements to a single value (no initial value)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.reduce( fcn ); + + t.strictEqual( out, 6, 'returns expected value' ); + t.end(); + + function fcn( acc, v ) { + return acc + v; + } +}); + +tape( 'the method reduces tuple elements to a single value (initial value)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.reduce( fcn, 10 ); + + t.strictEqual( out, 16, 'returns expected value' ); + t.end(); + + function fcn( acc, v ) { + return acc + v; + } +}); + +tape( 'the method provides the callback with five arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.reduce( fcn, 0 ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( acc, v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return acc + v; + } +}); + +tape( 'when no initial value is provided, the method uses the first element as the initial value and starts iteration from the second element', function test( t ) { + var indices; + var values; + var Point; + var p; + + indices = []; + values = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.reduce( fcn ); + + t.deepEqual( values, [ 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 1, 2 ], 'returns expected value' ); + + t.end(); + + function fcn( acc, v, i ) { + values.push( v ); + indices.push( i ); + return acc + v; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce_right.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce_right.js new file mode 100644 index 000000000000..4b3863541218 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce_right.js @@ -0,0 +1,210 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `reduceRight` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'reduceRight' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.reduceRight ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.reduceRight.call( value, fcn ); + }; + } + + function fcn( acc, v ) { + return acc + v; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.reduceRight( value ); + }; + } +}); + +tape( 'the method reduces tuple elements from right to left to a single value (no initial value)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.reduceRight( fcn ); + + t.strictEqual( out, 6, 'returns expected value' ); + t.end(); + + function fcn( acc, v ) { + return acc + v; + } +}); + +tape( 'the method reduces tuple elements from right to left to a single value (initial value)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.reduceRight( fcn, 10 ); + + t.strictEqual( out, 16, 'returns expected value' ); + t.end(); + + function fcn( acc, v ) { + return acc + v; + } +}); + +tape( 'the method provides the callback with five arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.reduceRight( fcn, 0 ); + + t.deepEqual( values, [ 3, 2, 1 ], 'returns expected value' ); + t.deepEqual( indices, [ 2, 1, 0 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'z', 'y', 'x' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( acc, v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return acc + v; + } +}); + +tape( 'when no initial value is provided, the method uses the last element as the initial value and starts iteration from the second-to-last element', function test( t ) { + var indices; + var values; + var Point; + var p; + + indices = []; + values = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.reduceRight( fcn ); + + t.deepEqual( values, [ 2, 1 ], 'returns expected value' ); + t.deepEqual( indices, [ 1, 0 ], 'returns expected value' ); + + t.end(); + + function fcn( acc, v, i ) { + values.push( v ); + indices.push( i ); + return acc + v; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reverse.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reverse.js new file mode 100644 index 000000000000..66c33ba4921f --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reverse.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `reverse` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'reverse' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.reverse ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.reverse.call( value ); + }; + } +}); + +tape( 'the method reverses a tuple in-place', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.deepEqual( p.orderedFields, [ 'x', 'y', 'z' ], 'returns expected value' ); + + out = p.reverse(); + + t.strictEqual( out, p, 'returns expected value' ); + t.strictEqual( p[ 0 ], 3, 'returns expected value' ); + t.strictEqual( p[ 1 ], 2, 'returns expected value' ); + t.strictEqual( p[ 2 ], 1, 'returns expected value' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.deepEqual( p.orderedFields, [ 'z', 'y', 'x' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method handles even-length tuples', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'a', 'b', 'c', 'd' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + p.reverse(); + + t.strictEqual( p[ 0 ], 4, 'returns expected value' ); + t.strictEqual( p[ 1 ], 3, 'returns expected value' ); + t.strictEqual( p[ 2 ], 2, 'returns expected value' ); + t.strictEqual( p[ 3 ], 1, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.set.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.set.js new file mode 100644 index 000000000000..330fd5073295 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.set.js @@ -0,0 +1,195 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `set` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'set' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.set ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.set.call( value, [ 1, 2 ] ); + }; + } +}); + +tape( 'the method throws an error if the source array plus offset exceeds the tuple length', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + values = [ + [ [ 7, 8 ], 3 ], + [ [ 1, 2, 3, 4 ], 0 ], + [ [ 1, 2 ], 2 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments '+values[ i ] ); + } + t.end(); + + function badValue( args ) { + return function badValue() { + p.set( args[ 0 ], args[ 1 ] ); + }; + } +}); + +tape( 'the method returns `undefined`', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.set( [ 7, 8 ] ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method sets tuple elements from an array-like object', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.set( [ 7, 8 ] ); + + t.strictEqual( p[ 0 ], 7, 'returns expected value' ); + t.strictEqual( p[ 1 ], 8, 'returns expected value' ); + t.strictEqual( p[ 2 ], 3, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 7, 'returns expected value' ); + t.strictEqual( p.y, 8, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method sets tuple elements from a typed array', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.set( new Float64Array( [ 7, 8 ] ) ); + + t.strictEqual( p[ 0 ], 7, 'returns expected value' ); + t.strictEqual( p[ 1 ], 8, 'returns expected value' ); + t.strictEqual( p[ 2 ], 3, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 7, 'returns expected value' ); + t.strictEqual( p.y, 8, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying an offset', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.set( [ 9 ], 2 ); + + t.strictEqual( p[ 0 ], 1, 'returns expected value' ); + t.strictEqual( p[ 1 ], 2, 'returns expected value' ); + t.strictEqual( p[ 2 ], 9, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the method updates values accessible via field names', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + p.set( [ 7, 8 ] ); + + t.strictEqual( p.x, 7, 'returns expected value' ); + t.strictEqual( p.y, 8, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.some.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.some.js new file mode 100644 index 000000000000..2685cbf578ff --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.some.js @@ -0,0 +1,207 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `some` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'some' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.some ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.some.call( value, fcn ); + }; + } + + function fcn( v ) { + return v > 0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.some( value ); + }; + } +}); + +tape( 'the method returns `true` if at least one element passes a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, -2, 3 ] ); + out = p.some( fcn ); + + t.strictEqual( out, true, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v < 0; + } +}); + +tape( 'the method returns `false` if no elements pass a test', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + out = p.some( fcn ); + + t.strictEqual( out, false, 'returns expected value' ); + t.end(); + + function fcn( v ) { + return v < 0; + } +}); + +tape( 'the method provides the callback with four arguments', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.some( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected value' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected value' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + return false; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.some( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + return false; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.sort.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.sort.js new file mode 100644 index 000000000000..992e99e7e1e5 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.sort.js @@ -0,0 +1,159 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `sort` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasOwnProp( p, 'sort' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.sort ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.sort.call( value ); + }; + } +}); + +tape( 'the method throws an error if provided an argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.sort( value ); + }; + } +}); + +tape( 'the method sorts a tuple in-place (default ascending)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 3, 1, 2 ] ); + + t.deepEqual( p.orderedFields, [ 'x', 'y', 'z' ], 'returns expected value' ); + + out = p.sort(); + + t.strictEqual( out, p, 'returns expected value' ); + t.strictEqual( p[ 0 ], 1, 'returns expected value' ); + t.strictEqual( p[ 1 ], 2, 'returns expected value' ); + t.strictEqual( p[ 2 ], 3, 'returns expected value' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 3, 'returns expected value' ); + t.strictEqual( p.y, 1, 'returns expected value' ); + t.strictEqual( p.z, 2, 'returns expected value' ); + t.deepEqual( p.orderedFields, [ 'y', 'z', 'x' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method sorts a tuple in-place (custom comparator)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 3, 2 ] ); + + // Sort descending: + out = p.sort( fcn ); + + t.strictEqual( out, p, 'returns expected value' ); + t.strictEqual( p[ 0 ], 3, 'returns expected value' ); + t.strictEqual( p[ 1 ], 2, 'returns expected value' ); + t.strictEqual( p[ 2 ], 1, 'returns expected value' ); + + t.end(); + + function fcn( a, b ) { + return b - a; + } +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subarray.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subarray.js new file mode 100644 index 000000000000..9532dea18982 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subarray.js @@ -0,0 +1,187 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `subarray` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'subarray' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.subarray ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subarray.call( value ); + }; + } +}); + +tape( 'the method returns a new typed array view over the same buffer', function test( t ) { + var Point; + var arr; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + arr = p.subarray(); + + t.strictEqual( arr.length, 3, 'returns expected value' ); + t.strictEqual( arr[ 0 ], 1, 'returns expected value' ); + t.strictEqual( arr[ 1 ], 2, 'returns expected value' ); + t.strictEqual( arr[ 2 ], 3, 'returns expected value' ); + t.strictEqual( arr.buffer, p.buffer, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying a beginning index', function test( t ) { + var Point; + var arr; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + arr = p.subarray( 1 ); + + t.strictEqual( arr.length, 2, 'returns expected value' ); + t.strictEqual( arr[ 0 ], 2, 'returns expected value' ); + t.strictEqual( arr[ 1 ], 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports specifying an end index', function test( t ) { + var Point; + var arr; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + arr = p.subarray( 0, 2 ); + + t.strictEqual( arr.length, 2, 'returns expected value' ); + t.strictEqual( arr[ 0 ], 1, 'returns expected value' ); + t.strictEqual( arr[ 1 ], 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var Point; + var arr; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + arr = p.subarray( -p.length, -1 ); + + t.strictEqual( arr.length, 2, 'returns expected value' ); + t.strictEqual( arr[ 0 ], 1, 'returns expected value' ); + t.strictEqual( arr[ 1 ], 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns an empty typed array if unable to resolve indices to a non-empty range', function test( t ) { + var Point; + var arr; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + arr = p.subarray( 10, -1 ); + + t.strictEqual( arr.length, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned view shares the same underlying buffer', function test( t ) { + var Point; + var arr; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + arr = p.subarray( 1 ); + + // Modifying the view modifies the original: + arr[ 0 ] = 99; + t.strictEqual( p[ 1 ], 99, 'returns expected value' ); + + // Field values reflect the update: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 99, 'returns expected value' ); + t.strictEqual( p.z, 3, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subtuple.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subtuple.js new file mode 100644 index 000000000000..11d75b25787d --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subtuple.js @@ -0,0 +1,394 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `subtuple` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 10, 20 ] ); + + t.strictEqual( hasOwnProp( p, 'subtuple' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.subtuple ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subtuple.call( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance (start)', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subtuple.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance (start, end)', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subtuple.call( value, 0, 1 ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subtuple( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer (end)', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subtuple( value, 1 ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.subtuple( 0, value ); + }; + } +}); + +tape( 'if called without arguments, the method returns a new tuple over the same underlying buffer', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + out = p.subtuple(); + + t.notEqual( out, p, 'returns expected value' ); + t.strictEqual( out.buffer, p.buffer, 'returns expected value' ); + t.deepEqual( out.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 10, 'returns expected value' ); + t.strictEqual( out[ 1 ], 20, 'returns expected value' ); + t.strictEqual( out[ 2 ], 30, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided one argument, the method returns a subtuple starting from a specified index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + out = p.subtuple( 1 ); + + t.strictEqual( out.buffer, p.buffer, 'returns expected value' ); + t.deepEqual( out.fields, [ 'y', 'z', 'w' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 2, 'returns expected value' ); + t.strictEqual( out[ 1 ], 3, 'returns expected value' ); + t.strictEqual( out[ 2 ], 4, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided two arguments, the method returns a subtuple from a start index (inclusive) to an end index (exclusive)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + out = p.subtuple( 1, 3 ); + + t.strictEqual( out.buffer, p.buffer, 'returns expected value' ); + t.deepEqual( out.fields, [ 'y', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 2, 'returns expected value' ); + t.strictEqual( out[ 1 ], 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + out = p.subtuple( -3, -1 ); + + t.strictEqual( out.buffer, p.buffer, 'returns expected value' ); + t.deepEqual( out.fields, [ 'y', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 2, 'returns expected value' ); + t.strictEqual( out[ 1 ], 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method clamps a very negative begin index to zero', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.subtuple( -100 ); + + t.strictEqual( out.buffer, p.buffer, 'returns expected value' ); + t.deepEqual( out.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 1, 'returns expected value' ); + t.strictEqual( out[ 1 ], 2, 'returns expected value' ); + t.strictEqual( out[ 2 ], 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method clamps a very negative end index to zero', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.subtuple( 0, -100 ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.deepEqual( out.fields, [], 'returns expected value' ); + t.end(); +}); + +tape( 'the method clamps an end index which exceeds the tuple length', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + out = p.subtuple( 1, 100 ); + + t.strictEqual( out.buffer, p.buffer, 'returns expected value' ); + t.deepEqual( out.fields, [ 'y', 'z' ], 'returns expected value' ); + t.strictEqual( out[ 0 ], 2, 'returns expected value' ); + t.strictEqual( out[ 1 ], 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty tuple if a resolved beginning index exceeds a resolved ending index', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + out = p.subtuple( 2, 0 ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.deepEqual( out.fields, [], 'returns expected value' ); + t.end(); +}); + +tape( 'the subtuple shares the same underlying buffer (mutations are shared)', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + out = p.subtuple( 1 ); + out[ 0 ] = 99; + + t.strictEqual( p[ 1 ], 99, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js index 3ee752ae275e..473a3f0daf34 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js @@ -64,7 +64,8 @@ tape( 'the method throws an error if invoked with a `this` context which is not 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] ); @@ -78,6 +79,69 @@ tape( 'the method throws an error if invoked with a `this` context which is not } }); +tape( 'the method throws an error if provided a first argument which is not a string or an array of strings', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + 5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.toLocaleString( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + 3.14, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.toLocaleString( 'en-US', value ); + }; + } +}); + tape( 'the method serializes a tuple as a locale-specific string (default locale)', function test( t ) { var expected; var actual; diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.values.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.values.js new file mode 100644 index 000000000000..8f7e0ee67723 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.values.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `values` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'values' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.values ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.values.call( value ); + }; + } +}); + +tape( 'the method returns an iterator for iterating over tuple elements', function test( t ) { + var Point; + var it; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + it = p.values(); + + v = it.next(); + t.strictEqual( v.value, 1, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, 2, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, 3, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns an iterator which yields values in index order', function test( t ) { + var expected; + var actual; + var Point; + var it; + var v; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + expected = [ 10, 20, 30 ]; + actual = []; + + it = p.values(); + v = it.next(); + while ( !v.done ) { + actual.push( v.value ); + v = it.next(); + } + + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});