From 1920b0759216a244594818cac204904e8f2d66d0 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 15 Mar 2026 02:57:03 +0500 Subject: [PATCH 1/4] test: add missing tests to dstructs/named-typed-tuple --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../named-typed-tuple/test/test.entries.js | 189 +++++++++ .../named-typed-tuple/test/test.every.js | 207 +++++++++ .../named-typed-tuple/test/test.field_of.js | 184 ++++++++ .../named-typed-tuple/test/test.filter.js | 231 ++++++++++ .../named-typed-tuple/test/test.find.js | 207 +++++++++ .../named-typed-tuple/test/test.find_field.js | 207 +++++++++ .../named-typed-tuple/test/test.find_index.js | 207 +++++++++ .../named-typed-tuple/test/test.from.js | 311 ++++++++++++++ .../test/test.from_object.js | 270 ++++++++++++ .../named-typed-tuple/test/test.ind2key.js | 150 +++++++ .../named-typed-tuple/test/test.key2ind.js | 137 ++++++ .../named-typed-tuple/test/test.keys.js | 189 +++++++++ .../test/test.last_field_of.js | 194 +++++++++ .../named-typed-tuple/test/test.map.js | 194 +++++++++ .../named-typed-tuple/test/test.of.js | 113 +++++ .../named-typed-tuple/test/test.reduce.js | 210 ++++++++++ .../test/test.reduce_right.js | 210 ++++++++++ .../named-typed-tuple/test/test.reverse.js | 141 +++++++ .../named-typed-tuple/test/test.some.js | 207 +++++++++ .../named-typed-tuple/test/test.sort.js | 165 ++++++++ .../named-typed-tuple/test/test.subtuple.js | 393 ++++++++++++++++++ .../test/test.to_locale_string.js | 63 +++ 22 files changed, 4379 insertions(+) create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.entries.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.every.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.field_of.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.filter.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_field.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_index.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from_object.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.ind2key.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.key2ind.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.keys.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_field_of.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.map.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.of.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reduce_right.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reverse.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.some.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.sort.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subtuple.js 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..434d0000d6e7 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.entries.js @@ -0,0 +1,189 @@ +/** +* @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', 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.done, true, 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator `return` method supports providing a value', 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.done, true, 'returns expected value' ); + t.strictEqual( v.value, 'finished', 'returns expected value' ); + + v = iter.next(); + 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..e7beb11e4be7 --- /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: value, index, field name, and tuple', 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 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.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.filter.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.filter.js new file mode 100644 index 000000000000..50b695587fba --- /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: value, index, field name, and tuple', 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 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.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..10c692230c1b --- /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: value, index, field name, and tuple', 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 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.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..10b003d1b09c --- /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: value, index, field name, and tuple', 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 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.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..3a03785f0052 --- /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: value, index, field name, and tuple', 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 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.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.from.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.from.js new file mode 100644 index 000000000000..b550bf0ac3c5 --- /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 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 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; + } +}); + +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 callback is provided the value, index, and field name when creating from an iterable', 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 values' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected indices' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected field names' ); + t.end(); + + function fcn( v, i, f ) { + values.push( v ); + indices.push( i ); + fieldNames.push( f ); + 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..44dfe5c14721 --- /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 provided the value and the field name', 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 values' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected field names' ); + 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.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.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..04bb3e2a17f1 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.keys.js @@ -0,0 +1,189 @@ +/** +* @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', 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.done, true, 'returns expected value' ); + + v = iter.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator `return` method supports providing a value', 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.done, true, 'returns expected value' ); + t.strictEqual( v.value, 'finished', 'returns expected value' ); + + v = iter.next(); + 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.map.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.map.js new file mode 100644 index 000000000000..1cd58523c0d6 --- /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: value, index, field name, and tuple', 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 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.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..4818a1a29310 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.of.js @@ -0,0 +1,113 @@ +/** +* @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 Point; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + + t.throws( tooFew, RangeError, 'throws an error' ); + t.throws( tooMany, RangeError, 'throws an error' ); + t.throws( none, RangeError, 'throws an error' ); + t.end(); + + function tooFew() { + return Point.of( 1 ); + } + + function tooMany() { + return Point.of( 1, 2, 3 ); + } + + function none() { + return Point.of(); + } +}); + +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..707a72a093b4 --- /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: accumulator, value, index, field name, and tuple', 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 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.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 values' ); + t.deepEqual( indices, [ 1, 2 ], 'returns expected indices' ); + + 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..109fa9ad7ce7 --- /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: accumulator, value, index, field name, and tuple', 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 values' ); + t.deepEqual( indices, [ 2, 1, 0 ], 'returns expected indices' ); + t.deepEqual( fieldNames, [ 'z', 'y', 'x' ], '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.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 values' ); + t.deepEqual( indices, [ 1, 0 ], 'returns expected indices' ); + + 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..c0787636ee75 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.reverse.js @@ -0,0 +1,141 @@ +/** +* @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 ] ); + 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' ); + t.end(); +}); + +tape( 'after reversal, field names still refer to the same values', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.reverse(); + + // Field accessors should still return the original values: + 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(); +}); + +tape( 'the method updates the ordered fields', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.deepEqual( p.orderedFields, [ 'x', 'y', 'z' ], 'returns expected value' ); + + p.reverse(); + + 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.some.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.some.js new file mode 100644 index 000000000000..b7338577813e --- /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: value, index, field name, and tuple', 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 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.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..449631334cb6 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.sort.js @@ -0,0 +1,165 @@ +/** +* @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 `sort` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( 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', + 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.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 ] ); + 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' ); + 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; + } +}); + +tape( 'the method updates the ordered fields', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 3, 1, 2 ] ); + + t.deepEqual( p.orderedFields, [ 'x', 'y', 'z' ], 'returns expected value' ); + + p.sort(); + + t.deepEqual( p.orderedFields, [ 'y', 'z', 'x' ], '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..2578bc923da2 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subtuple.js @@ -0,0 +1,393 @@ +/** +* @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..a9cae2d6ef0c 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 @@ -78,6 +78,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; From beae3d87720749697c9d3e3797fa3e01fdd7ef5c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 17 Mar 2026 19:27:40 +0500 Subject: [PATCH 2/4] test: add tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../named-typed-tuple/test/test.at.js | 149 +++++++++++ .../named-typed-tuple/test/test.fill.js | 228 +++++++++++++++++ .../named-typed-tuple/test/test.includes.js | 201 +++++++++++++++ .../named-typed-tuple/test/test.index_of.js | 238 ++++++++++++++++++ .../named-typed-tuple/test/test.join.js | 151 +++++++++++ .../test/test.last_index_of.js | 210 ++++++++++++++++ .../named-typed-tuple/test/test.set.js | 182 ++++++++++++++ .../named-typed-tuple/test/test.subarray.js | 206 +++++++++++++++ .../named-typed-tuple/test/test.values.js | 143 +++++++++++ 9 files changed, 1708 insertions(+) create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.at.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.includes.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.index_of.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.join.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_index_of.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.set.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subarray.js create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.values.js 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..a2366f380dcb --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.at.js @@ -0,0 +1,149 @@ +/** +* @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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // 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.fill.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js new file mode 100644 index 000000000000..217bd3eafd37 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js @@ -0,0 +1,228 @@ +/** +* @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 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.fill( 9, 1, 2 ); + + t.strictEqual( p.x, 1, '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 start is greater than or equal to end', 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.includes.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.includes.js new file mode 100644 index 000000000000..16a80d47e221 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.includes.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 `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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 0, 'returns expected value' ); + t.strictEqual( p.y, 1, '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' ); + + // Field values remain unchanged: + t.strictEqual( p.y, 1, '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..b4aecd17836e --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.index_of.js @@ -0,0 +1,238 @@ +/** +* @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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 1, '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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 1, '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' ); + + // 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(); +}); + +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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 0.0, 'returns expected value' ); + t.strictEqual( p.y, 0.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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 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.indexOf( NaN ); + t.strictEqual( idx, -1, 'returns expected value' ); + + // Field values remain unchanged: + t.strictEqual( p.y, 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..ab94847e5a25 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.join.js @@ -0,0 +1,151 @@ +/** +* @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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 0, 'returns expected value' ); + t.strictEqual( p.z, -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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 0, 'returns expected value' ); + t.strictEqual( p.z, -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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 0, 'returns expected value' ); + t.strictEqual( p.z, -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.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..e887c5164969 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.last_index_of.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 `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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 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' ); + + // 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(); +}); + +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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 1, '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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 1, 'returns expected value' ); + t.strictEqual( p.y, 2, 'returns expected value' ); + t.strictEqual( p.z, 1, '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' ); + + // 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(); +}); + +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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 0, 'returns expected value' ); + t.strictEqual( p.y, 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.lastIndexOf( NaN ); + t.strictEqual( idx, -1, 'returns expected value' ); + + // Field values remain unchanged: + t.strictEqual( p.y, 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..7e5ea8a7dfa0 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.set.js @@ -0,0 +1,182 @@ +/** +* @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 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(); +}); + +tape( 'the method throws an error if the source array plus offset exceeds the tuple length', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + + t.throws( function badValue() { + p.set( [ 7, 8 ], 3 ); + }, RangeError, 'returns expected value' ); + t.end(); +}); 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..1a18282e62a2 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.subarray.js @@ -0,0 +1,206 @@ +/** +* @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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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' ); + + // 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(); +}); + +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.values.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.values.js new file mode 100644 index 000000000000..ed0966620ecd --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.values.js @@ -0,0 +1,143 @@ +/** +* @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' ); + + // 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(); +}); + +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' ); + + // Field values remain unchanged: + t.strictEqual( p.x, 10, 'returns expected value' ); + t.strictEqual( p.y, 20, 'returns expected value' ); + t.strictEqual( p.z, 30, 'returns expected value' ); + t.end(); +}); From 1ba27950a821874af61df8626ed4e80fe56c7ed7 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 22 Mar 2026 19:06:32 +0500 Subject: [PATCH 3/4] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../named-typed-tuple/test/test.at.js | 15 ---- .../named-typed-tuple/test/test.entries.js | 9 ++- .../named-typed-tuple/test/test.every.js | 14 ++-- .../named-typed-tuple/test/test.fill.js | 17 +--- .../named-typed-tuple/test/test.filter.js | 14 ++-- .../named-typed-tuple/test/test.find.js | 14 ++-- .../named-typed-tuple/test/test.find_field.js | 14 ++-- .../named-typed-tuple/test/test.find_index.js | 14 ++-- .../named-typed-tuple/test/test.for_each.js | 14 ++-- .../named-typed-tuple/test/test.from.js | 80 +++++++++---------- .../test/test.from_object.js | 6 +- .../named-typed-tuple/test/test.keys.js | 9 ++- .../named-typed-tuple/test/test.map.js | 14 ++-- .../named-typed-tuple/test/test.of.js | 28 ++++--- .../named-typed-tuple/test/test.reduce.js | 18 ++--- .../test/test.reduce_right.js | 18 ++--- .../named-typed-tuple/test/test.reverse.js | 29 +------ .../named-typed-tuple/test/test.set.js | 39 ++++++--- .../named-typed-tuple/test/test.some.js | 14 ++-- .../named-typed-tuple/test/test.sort.js | 32 +++----- .../named-typed-tuple/test/test.subarray.js | 6 ++ .../named-typed-tuple/test/test.subtuple.js | 1 + 22 files changed, 195 insertions(+), 224 deletions(-) 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 index a2366f380dcb..bfbaa617a566 100644 --- 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 @@ -95,11 +95,6 @@ tape( 'the method returns the tuple element at a given index', function test( t v = p.at( 2 ); t.strictEqual( v, 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(); }); @@ -119,11 +114,6 @@ tape( 'the method supports negative indices', function test( t ) { v = p.at( -3 ); t.strictEqual( v, 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.end(); }); @@ -140,10 +130,5 @@ tape( 'the method returns `undefined` if the index is out of bounds', function t v = p.at( -10 ); t.strictEqual( v, void 0, '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.entries.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.entries.js index 434d0000d6e7..d2995bd2eea6 100644 --- 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 @@ -115,7 +115,7 @@ tape( 'the method returns an iterator protocol-compliant object which iterates o t.end(); }); -tape( 'the returned iterator has a `return` method for closing an iterator', function test( t ) { +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { var Point; var iter; var v; @@ -129,15 +129,17 @@ tape( 'the returned iterator has a `return` method for closing an iterator', fun 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 `return` method supports providing a value', function test( t ) { +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { var Point; var iter; var v; @@ -151,10 +153,11 @@ tape( 'the returned iterator `return` method supports providing a value', functi t.strictEqual( v.done, false, 'returns expected value' ); v = iter.return( 'finished' ); - t.strictEqual( v.done, true, 'returns expected value' ); 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(); 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 index e7beb11e4be7..e2f90e400353 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method returns `false` if not all elements pass a test', function tes } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.every( 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.fill.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.fill.js index 217bd3eafd37..98900c023425 100644 --- 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 @@ -192,22 +192,7 @@ tape( 'the method supports negative end indices', function test( t ) { 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.fill( 9, 1, 2 ); - - t.strictEqual( p.x, 1, '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 start is greater than or equal to end', function test( t ) { +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; 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 index 50b695587fba..2e8407f68962 100644 --- 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 @@ -173,7 +173,7 @@ tape( 'the method returns `null` if no elements pass a test', function test( t ) } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -190,12 +190,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.filter( 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.find.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find.js index 10c692230c1b..536f92ff2998 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method returns `undefined` if no element passes a test', function tes } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.find( 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.find_field.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_field.js index 10b003d1b09c..bb8625eadb3b 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method returns `undefined` if no element passes a test', function tes } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.findField( 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.find_index.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.find_index.js index 3a03785f0052..e95ad65402dd 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method returns `-1` if no element passes a test', function test( t ) } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.findIndex( 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.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 index b550bf0ac3c5..c922a3ee9d06 100644 --- 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 @@ -205,42 +205,6 @@ tape( 'the method creates a new tuple from an array-like object', function test( t.end(); }); -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 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; - } -}); - tape( 'the method creates a new tuple from an iterable', function test( t ) { var Point; var p; @@ -280,7 +244,24 @@ tape( 'the method creates a new tuple from an iterable using a callback', functi } }); -tape( 'the callback is provided the value, index, and field name when creating from an iterable', function test( t ) { +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; @@ -297,9 +278,9 @@ tape( 'the callback is provided the value, index, and field name when creating f Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); Point.from( createIterable( [ 10, 20, 30 ] ), fcn ); - t.deepEqual( values, [ 10, 20, 30 ], 'returns expected values' ); - t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected indices' ); - t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected field names' ); + 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 ) { @@ -309,3 +290,22 @@ tape( 'the callback is provided the value, index, and field name when creating 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 index 44dfe5c14721..29dd083b1f13 100644 --- 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 @@ -216,7 +216,7 @@ tape( 'the method creates a new tuple from an object using a callback', function } }); -tape( 'the callback is provided the value and the field name', function test( t ) { +tape( 'the callback is invoked with two arguments', function test( t ) { var fieldNames; var values; var Point; @@ -233,8 +233,8 @@ tape( 'the callback is provided the value and the field name', function test( t }; Point.fromObject( opts, fcn ); - t.deepEqual( values, [ 10, 20, 30 ], 'returns expected values' ); - t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected field names' ); + t.deepEqual( values, [ 10, 20, 30 ], 'returns expected value' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected value' ); t.end(); function fcn( v, f ) { 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 index 04bb3e2a17f1..6b6c0a6bb93e 100644 --- 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 @@ -115,7 +115,7 @@ tape( 'the method returns an iterator protocol-compliant object which iterates o t.end(); }); -tape( 'the returned iterator has a `return` method for closing an iterator', function test( t ) { +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { var Point; var iter; var v; @@ -129,15 +129,17 @@ tape( 'the returned iterator has a `return` method for closing an iterator', fun 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 `return` method supports providing a value', function test( t ) { +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { var Point; var iter; var v; @@ -151,10 +153,11 @@ tape( 'the returned iterator `return` method supports providing a value', functi t.strictEqual( v.done, false, 'returns expected value' ); v = iter.return( 'finished' ); - t.strictEqual( v.done, true, 'returns expected value' ); 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(); 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 index 1cd58523c0d6..2d928e399deb 100644 --- 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 @@ -136,7 +136,7 @@ tape( 'the method returns a new tuple with mapped values', function test( t ) { } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -153,12 +153,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.map( 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.of.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.of.js index 4818a1a29310..04dfff3534fc 100644 --- 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 @@ -76,25 +76,27 @@ tape( 'the method throws an error if invoked with a `this` context which is not }); 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' ] ); - t.throws( tooFew, RangeError, 'throws an error' ); - t.throws( tooMany, RangeError, 'throws an error' ); - t.throws( none, RangeError, 'throws an error' ); - t.end(); - - function tooFew() { - return Point.of( 1 ); - } - - function tooMany() { - return Point.of( 1, 2, 3 ); + 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 none() { - return Point.of(); + function badValue( args ) { + return function badValue() { + return Point.of.apply( Point, args ); + }; } }); 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 index 707a72a093b4..4683ea14f090 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method reduces tuple elements to a single value (initial value)', fun } }); -tape( 'the method provides the callback with five arguments: accumulator, value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with five arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with five arguments: accumulator, value, p = new Point( [ 1, 2, 3 ] ); p.reduce( fcn, 0 ); - 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(); @@ -197,8 +197,8 @@ tape( 'when no initial value is provided, the method uses the first element as t p = new Point( [ 1, 2, 3 ] ); p.reduce( fcn ); - t.deepEqual( values, [ 2, 3 ], 'returns expected values' ); - t.deepEqual( indices, [ 1, 2 ], 'returns expected indices' ); + t.deepEqual( values, [ 2, 3 ], 'returns expected value' ); + t.deepEqual( indices, [ 1, 2 ], 'returns expected value' ); t.end(); 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 index 109fa9ad7ce7..4b3863541218 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method reduces tuple elements from right to left to a single value (i } }); -tape( 'the method provides the callback with five arguments: accumulator, value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with five arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with five arguments: accumulator, value, p = new Point( [ 1, 2, 3 ] ); p.reduceRight( fcn, 0 ); - t.deepEqual( values, [ 3, 2, 1 ], 'returns expected values' ); - t.deepEqual( indices, [ 2, 1, 0 ], 'returns expected indices' ); - t.deepEqual( fieldNames, [ 'z', 'y', 'x' ], '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, [ 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(); @@ -197,8 +197,8 @@ tape( 'when no initial value is provided, the method uses the last element as th p = new Point( [ 1, 2, 3 ] ); p.reduceRight( fcn ); - t.deepEqual( values, [ 2, 1 ], 'returns expected values' ); - t.deepEqual( indices, [ 1, 0 ], 'returns expected indices' ); + t.deepEqual( values, [ 2, 1 ], 'returns expected value' ); + t.deepEqual( indices, [ 1, 0 ], 'returns expected value' ); t.end(); 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 index c0787636ee75..66c33ba4921f 100644 --- 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 @@ -86,41 +86,20 @@ tape( 'the method reverses a tuple in-place', function test( t ) { 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' ); - t.end(); -}); -tape( 'after reversal, field names still refer to the same values', function test( t ) { - var Point; - var p; - - Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); - p = new Point( [ 1, 2, 3 ] ); - p.reverse(); - - // Field accessors should still return the original values: + // 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(); -}); - -tape( 'the method updates the ordered fields', function test( t ) { - var Point; - var p; - - Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); - p = new Point( [ 1, 2, 3 ] ); - - t.deepEqual( p.orderedFields, [ 'x', 'y', 'z' ], 'returns expected value' ); - - p.reverse(); - t.deepEqual( p.orderedFields, [ 'z', 'y', 'x' ], '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 index 7e5ea8a7dfa0..330fd5073295 100644 --- 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 @@ -80,6 +80,32 @@ tape( 'the method throws an error if invoked with a `this` context which is not } }); +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; @@ -167,16 +193,3 @@ tape( 'the method updates values accessible via field names', function test( t ) t.strictEqual( p.z, 3, 'returns expected value' ); t.end(); }); - -tape( 'the method throws an error if the source array plus offset exceeds the tuple length', function test( t ) { - var Point; - var p; - - Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); - p = new Point( [ 1, 2, 3 ] ); - - t.throws( function badValue() { - p.set( [ 7, 8 ], 3 ); - }, RangeError, '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 index b7338577813e..2685cbf578ff 100644 --- 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 @@ -149,7 +149,7 @@ tape( 'the method returns `false` if no elements pass a test', function test( t } }); -tape( 'the method provides the callback with four arguments: value, index, field name, and tuple', function test( t ) { +tape( 'the method provides the callback with four arguments', function test( t ) { var fieldNames; var indices; var values; @@ -166,12 +166,12 @@ tape( 'the method provides the callback with four arguments: value, index, field p = new Point( [ 1, 2, 3 ] ); p.some( 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.sort.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.sort.js index 449631334cb6..992e99e7e1e5 100644 --- 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 @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var hasProp = require( '@stdlib/assert/has-property' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); var namedtypedtuple = require( './../lib' ); @@ -41,7 +41,7 @@ tape( 'a tuple has a `sort` method', function test( t ) { Point = namedtypedtuple( [ 'x', 'y' ] ); p = new Point(); - t.strictEqual( hasProp( p, 'sort' ), true, 'returns expected value' ); + t.strictEqual( hasOwnProp( p, 'sort' ), true, 'returns expected value' ); t.strictEqual( isFunction( p.sort ), true, 'returns expected value' ); t.end(); }); @@ -90,12 +90,11 @@ tape( 'the method throws an error if provided an argument which is not a functio values = [ '5', - 3.14, + 5, NaN, true, false, null, - void 0, {}, [] ]; @@ -118,12 +117,21 @@ tape( 'the method sorts a tuple in-place (default ascending)', function test( t 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(); }); @@ -142,24 +150,10 @@ tape( 'the method sorts a tuple in-place (custom comparator)', function test( t 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; } }); - -tape( 'the method updates the ordered fields', function test( t ) { - var Point; - var p; - - Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); - p = new Point( [ 3, 1, 2 ] ); - - t.deepEqual( p.orderedFields, [ 'x', 'y', 'z' ], 'returns expected value' ); - - p.sort(); - - t.deepEqual( p.orderedFields, [ 'y', 'z', 'x' ], 'returns expected value' ); - t.end(); -}); 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 index 1a18282e62a2..e2e7628f3a90 100644 --- 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 @@ -99,6 +99,7 @@ tape( 'the method returns a new typed array view over the same buffer', function 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(); }); @@ -120,6 +121,7 @@ tape( 'the method supports specifying a beginning index', function test( t ) { 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(); }); @@ -141,6 +143,7 @@ tape( 'the method supports specifying an end index', function test( t ) { 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(); }); @@ -162,6 +165,7 @@ tape( 'the method supports negative indices', function test( t ) { 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(); }); @@ -181,6 +185,7 @@ tape( 'the method returns an empty typed array if unable to resolve indices to a 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(); }); @@ -202,5 +207,6 @@ tape( 'the returned view shares the same underlying buffer', function test( t ) 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 index 2578bc923da2..11d75b25787d 100644 --- 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 @@ -43,6 +43,7 @@ tape( 'a tuple has a `subtuple` method', function test( t ) { t.strictEqual( hasOwnProp( p, 'subtuple' ), true, 'returns expected value' ); t.strictEqual( isFunction( p.subtuple ), true, 'returns expected value' ); + t.end(); }); From 230f41ecf80bcacac1ee078a13a9a365caa02a43 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 22 Mar 2026 19:32:05 +0500 Subject: [PATCH 4/4] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../named-typed-tuple/test/test.includes.js | 22 ----------- .../named-typed-tuple/test/test.index_of.js | 37 ------------------- .../named-typed-tuple/test/test.join.js | 12 ------ .../test/test.last_index_of.js | 26 ------------- .../named-typed-tuple/test/test.subarray.js | 25 ------------- .../test/test.to_locale_string.js | 3 +- .../named-typed-tuple/test/test.values.js | 8 ---- 7 files changed, 2 insertions(+), 131 deletions(-) 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 index 16a80d47e221..f20c3c09266d 100644 --- 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 @@ -96,10 +96,6 @@ tape( 'the method returns `true` if a tuple includes a search element', function bool = p.includes( 3 ); t.strictEqual( bool, true, '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(); }); @@ -114,10 +110,6 @@ tape( 'the method returns `false` if a tuple does not include a search element', bool = p.includes( 10 ); t.strictEqual( bool, false, '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(); }); @@ -135,10 +127,6 @@ tape( 'the method supports specifying a starting index', function test( t ) { bool = p.includes( 3, 1 ); t.strictEqual( bool, true, '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(); }); @@ -156,10 +144,6 @@ tape( 'the method supports specifying a negative starting index', function test( bool = p.includes( 3, -1 ); t.strictEqual( bool, true, '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(); }); @@ -177,9 +161,6 @@ tape( 'the method does not distinguish between signed and unsigned zero', functi bool = p.includes( 0.0 ); t.strictEqual( bool, true, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 0, 'returns expected value' ); - t.strictEqual( p.y, 1, 'returns expected value' ); t.end(); }); @@ -194,8 +175,5 @@ tape( 'the method can find NaN values', function test( t ) { bool = p.includes( NaN ); t.strictEqual( bool, true, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.y, 1, '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 index b4aecd17836e..ed33ae544a9f 100644 --- 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 @@ -96,11 +96,6 @@ tape( 'the method returns the index of the first element strictly equal to a sea idx = p.indexOf( 3 ); t.strictEqual( idx, 2, '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(); }); @@ -115,11 +110,6 @@ tape( 'the method returns `-1` if unable to locate a search element', function t idx = p.indexOf( 10 ); t.strictEqual( idx, -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.end(); }); @@ -134,11 +124,6 @@ tape( 'the method supports specifying a starting index', function test( t ) { idx = p.indexOf( 1, 1 ); t.strictEqual( idx, 2, '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, 1, 'returns expected value' ); - t.end(); }); @@ -153,11 +138,6 @@ tape( 'the method supports specifying a negative starting index', function test( idx = p.indexOf( 1, -2 ); t.strictEqual( idx, 2, '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, 1, 'returns expected value' ); - t.end(); }); @@ -172,11 +152,6 @@ tape( 'the method returns `-1` if the starting index exceeds the tuple length', idx = p.indexOf( 1, 10 ); t.strictEqual( idx, -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.end(); }); @@ -194,10 +169,6 @@ tape( 'the method does not distinguish between signed and unsigned zero', functi idx = p.indexOf( -0.0 ); t.strictEqual( idx, 0, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 0.0, 'returns expected value' ); - t.strictEqual( p.y, 0.0, 'returns expected value' ); - t.end(); }); @@ -212,11 +183,6 @@ tape( 'the method returns the index of the first occurrence when there are dupli idx = p.indexOf( 1 ); t.strictEqual( idx, 0, '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, 1, 'returns expected value' ); - t.end(); }); @@ -231,8 +197,5 @@ tape( 'the method returns `-1` when searching for NaN', function test( t ) { idx = p.indexOf( NaN ); t.strictEqual( idx, -1, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.y, 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 index ab94847e5a25..9207991e2e5c 100644 --- 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 @@ -91,10 +91,6 @@ tape( 'the method joins all tuple elements as a string using a comma as the defa t.strictEqual( str, '1,0,-1', 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 1, 'returns expected value' ); - t.strictEqual( p.y, 0, 'returns expected value' ); - t.strictEqual( p.z, -1, 'returns expected value' ); t.end(); }); @@ -110,10 +106,6 @@ tape( 'the method supports specifying a separator', function test( t ) { t.strictEqual( str, '1|0|-1', 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 1, 'returns expected value' ); - t.strictEqual( p.y, 0, 'returns expected value' ); - t.strictEqual( p.z, -1, 'returns expected value' ); t.end(); }); @@ -129,10 +121,6 @@ tape( 'the method supports an empty string separator', function test( t ) { t.strictEqual( str, '10-1', 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 1, 'returns expected value' ); - t.strictEqual( p.y, 0, 'returns expected value' ); - t.strictEqual( p.z, -1, '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 index e887c5164969..720405a6805d 100644 --- 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 @@ -93,10 +93,6 @@ tape( 'the method returns the index of the last element strictly equal to a sear idx = p.lastIndexOf( 2 ); t.strictEqual( idx, 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, 1, 'returns expected value' ); t.end(); }); @@ -111,10 +107,6 @@ tape( 'the method returns `-1` if unable to locate a search element', function t idx = p.lastIndexOf( 10 ); t.strictEqual( idx, -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.end(); }); @@ -129,10 +121,6 @@ tape( 'the method supports specifying a starting index', function test( t ) { idx = p.lastIndexOf( 1, 1 ); t.strictEqual( idx, 0, '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, 1, 'returns expected value' ); t.end(); }); @@ -147,10 +135,6 @@ tape( 'the method supports specifying a negative starting index', function test( idx = p.lastIndexOf( 1, -1 ); t.strictEqual( idx, 2, '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, 1, 'returns expected value' ); t.end(); }); @@ -165,10 +149,6 @@ tape( 'the method returns `-1` if the starting index resolves to an index less t idx = p.lastIndexOf( 1, -10 ); t.strictEqual( idx, -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.end(); }); @@ -186,9 +166,6 @@ tape( 'the method does not distinguish between signed and unsigned zero', functi idx = p.lastIndexOf( -0.0 ); t.strictEqual( idx, 1, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 0, 'returns expected value' ); - t.strictEqual( p.y, 0, 'returns expected value' ); t.end(); }); @@ -203,8 +180,5 @@ tape( 'the method returns `-1` when searching for NaN', function test( t ) { idx = p.lastIndexOf( NaN ); t.strictEqual( idx, -1, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.y, 1, 'returns expected value' ); - t.end(); }); 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 index e2e7628f3a90..9532dea18982 100644 --- 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 @@ -95,11 +95,6 @@ tape( 'the method returns a new typed array view over the same buffer', function t.strictEqual( arr[ 2 ], 3, 'returns expected value' ); t.strictEqual( arr.buffer, p.buffer, '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(); }); @@ -117,11 +112,6 @@ tape( 'the method supports specifying a beginning index', function test( t ) { t.strictEqual( arr[ 0 ], 2, 'returns expected value' ); t.strictEqual( arr[ 1 ], 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(); }); @@ -139,11 +129,6 @@ tape( 'the method supports specifying an end index', function test( t ) { t.strictEqual( arr[ 0 ], 1, 'returns expected value' ); t.strictEqual( arr[ 1 ], 2, '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(); }); @@ -161,11 +146,6 @@ tape( 'the method supports negative indices', function test( t ) { t.strictEqual( arr[ 0 ], 1, 'returns expected value' ); t.strictEqual( arr[ 1 ], 2, '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(); }); @@ -181,11 +161,6 @@ tape( 'the method returns an empty typed array if unable to resolve indices to a t.strictEqual( arr.length, 0, '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.to_locale_string.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js index a9cae2d6ef0c..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] ); 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 index ed0966620ecd..8f7e0ee67723 100644 --- 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 @@ -105,10 +105,6 @@ tape( 'the method returns an iterator for iterating over tuple elements', functi v = it.next(); t.strictEqual( v.done, true, '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(); }); @@ -135,9 +131,5 @@ tape( 'the method returns an iterator which yields values in index order', funct t.deepEqual( actual, expected, 'returns expected value' ); - // Field values remain unchanged: - t.strictEqual( p.x, 10, 'returns expected value' ); - t.strictEqual( p.y, 20, 'returns expected value' ); - t.strictEqual( p.z, 30, 'returns expected value' ); t.end(); });