diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/README.md b/lib/node_modules/@stdlib/stats/array/mskrange/README.md new file mode 100644 index 000000000000..d2776b057060 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/README.md @@ -0,0 +1,118 @@ + + +# mskrange + +> Calculate the [range][range] of an array according to a mask. + +
+ +
+ + + +
+ +## Usage + +```javascript +var mskrange = require( '@stdlib/stats/array/mskrange' ); +``` + +#### mskrange( x, mask ) + +Computes the [range][range] of an array according to a mask. + +```javascript +var x = [ 1.0, -2.0, 4.0, 2.0 ]; +var mask = [ 0, 0, 1, 0 ]; + +var v = mskrange( x, mask ); +// returns 4.0 +``` + +The function has the following parameters: + +- **x**: input array. +- **mask**: mask array. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and **excluded** from computation. + +
+ + + +
+ +## Notes + +- If provided an empty array, the function returns `NaN`. +- The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskrange = require( '@stdlib/stats/array/mskrange' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +console.log( x ); + +var mask = bernoulli( x.length, 0.2, { + 'dtype': 'uint8' +}); +console.log( mask ); + +var v = mskrange( x, mask ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/array/mskrange/benchmark/benchmark.js new file mode 100644 index 000000000000..983cc5fe7039 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/benchmark/benchmark.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var mskrange = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask = bernoulli( len, 0.2, options ); + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mskrange( x, mask ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/array/mskrange/docs/repl.txt new file mode 100644 index 000000000000..1939587fc6ba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( x, mask ) + Computes the range of an array according to a mask. + + If a `mask` array element is `0`, the corresponding element in `x` is + considered valid and included in computation. + + If a `mask` array element is `1`, the corresponding element in `x` is + considered invalid/missing and excluded from computation. + + If provided an empty array, the function returns `NaN`. + + Parameters + ---------- + x: Array|TypedArray + Input array. + + mask: Array|TypedArray + Mask array. + + Returns + ------- + out: number + Range. + + Examples + -------- + > var x = [ 1.0, -2.0, 4.0, 2.0 ]; + > var msk = [ 0, 0, 1, 0 ]; + > {{alias}}( x, msk ) + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/array/mskrange/docs/types/index.d.ts new file mode 100644 index 000000000000..db50b86a8f73 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/docs/types/index.d.ts @@ -0,0 +1,49 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Computes the range of an array according to a mask. +* +* @param x - input array +* @param mask - mask array +* @returns range +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskrange( x, mask ); +* // returns 4.0 +*/ +declare function mskrange( x: InputArray, mask: InputArray ): number; + + +// EXPORTS // + +export = mskrange; diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/docs/types/test.ts b/lib/node_modules/@stdlib/stats/array/mskrange/docs/types/test.ts new file mode 100644 index 000000000000..b4de82e16980 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import mskrange = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + mskrange( x, mask ); // $ExpectType number + mskrange( new AccessorArray( x ), mask ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a numeric array... +{ + const mask = new Uint8Array( 10 ); + + mskrange( 10, mask ); // $ExpectError + mskrange( '10', mask ); // $ExpectError + mskrange( true, mask ); // $ExpectError + mskrange( false, mask ); // $ExpectError + mskrange( null, mask ); // $ExpectError + mskrange( undefined, mask ); // $ExpectError + mskrange( {}, mask ); // $ExpectError + mskrange( ( x: number ): number => x, mask ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + mskrange( x, 10 ); // $ExpectError + mskrange( x, '10' ); // $ExpectError + mskrange( x, true ); // $ExpectError + mskrange( x, false ); // $ExpectError + mskrange( x, null ); // $ExpectError + mskrange( x, undefined ); // $ExpectError + mskrange( x, {} ); // $ExpectError + mskrange( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + mskrange(); // $ExpectError + mskrange( x ); // $ExpectError + mskrange( x, mask, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/examples/index.js b/lib/node_modules/@stdlib/stats/array/mskrange/examples/index.js new file mode 100644 index 000000000000..7e43f1eb0be4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskrange = require( './../lib' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +console.log( x ); + +var mask = bernoulli( x.length, 0.2, { + 'dtype': 'uint8' +}); +console.log( mask ); + +var v = mskrange( x, mask ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/lib/index.js b/lib/node_modules/@stdlib/stats/array/mskrange/lib/index.js new file mode 100644 index 000000000000..ef846f78fc4d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Compute the range of an array according to a mask. +* +* @module @stdlib/stats/array/mskrange +* +* @example +* var mskrange = require( '@stdlib/stats/array/mskrange' ); +* +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskrange( x, mask ); +* // returns 4.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/lib/main.js b/lib/node_modules/@stdlib/stats/array/mskrange/lib/main.js new file mode 100644 index 000000000000..448ced6bbb91 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/lib/main.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isCollection = require( '@stdlib/assert/is-collection' ); +var dtypes = require( '@stdlib/array/dtypes' ); +var dtype = require( '@stdlib/array/dtype' ); +var contains = require( '@stdlib/array/base/assert/contains' ); +var join = require( '@stdlib/array/base/join' ); +var strided = require( '@stdlib/stats/base/mskrange' ).ndarray; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var IDTYPES = dtypes( 'real_and_generic' ); // note: applicable for both the input and mask arrays +var GENERIC_DTYPE = 'generic'; + + +// MAIN // + +/** +* Computes the range of an array according to a mask. +* +* @param {NumericArray} x - input array +* @param {NumericArray} mask - mask array +* @throws {TypeError} first argument must be an array-like object +* @throws {TypeError} first argument must have a supported data type +* @throws {TypeError} second argument must be an array-like object +* @throws {TypeError} second argument must have a supported data type +* @throws {RangeError} first and second arguments must have the same length +* @returns {number} range +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskrange( x, mask ); +* // returns 4.0 +*/ +function mskrange( x, mask ) { + var dt; + if ( !isCollection( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + } + dt = dtype( x ) || GENERIC_DTYPE; + if ( !contains( IDTYPES, dt ) ) { + throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( IDTYPES, '", "' ), dt ) ); + } + if ( !isCollection( mask ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', mask ) ); + } + dt = dtype( mask ) || GENERIC_DTYPE; + if ( !contains( IDTYPES, dt ) ) { + throw new TypeError( format( 'invalid argument. Second argument must have one of the following data types: "%s". Data type: `%s`.', join( IDTYPES, '", "' ), dt ) ); + } + if ( x.length !== mask.length ) { + throw new RangeError( format( 'invalid arguments. First and second arguments must have the same length.' ) ); + } + return strided( x.length, x, 1, 0, mask, 1, 0 ); +} + + +// EXPORTS // + +module.exports = mskrange; diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/package.json b/lib/node_modules/@stdlib/stats/array/mskrange/package.json new file mode 100644 index 000000000000..ec2b6c7ba0f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/stats/array/mskrange", + "version": "0.0.0", + "description": "Calculate the range of an array according to a mask.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "maximum", + "max", + "minimum", + "min", + "range", + "extremes", + "domain", + "extent", + "array", + "masked", + "mask", + "masked array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/array/mskrange/test/test.js b/lib/node_modules/@stdlib/stats/array/mskrange/test/test.js new file mode 100644 index 000000000000..69dbc629b766 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/mskrange/test/test.js @@ -0,0 +1,327 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var mskrange = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskrange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 2', function test( t ) { + t.strictEqual( mskrange.length, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { + var values; + var mask; + var i; + + mask = [ 1, 0, 1, 1 ]; + + 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() { + mskrange( value, mask ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which has an unsupported data type', function test( t ) { + var values; + var mask; + var i; + + mask = [ 1, 0, 1, 1 ]; + + values = [ + new BooleanArray( 4 ), + new Complex128Array( 4 ) + ]; + 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() { + mskrange( value, mask ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an array-like object', function test( t ) { + var values; + var x; + var i; + + x = [ 1, 0, 1, 1 ]; + + 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() { + mskrange( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which has an unsupported data type', function test( t ) { + var values; + var x; + var i; + + x = [ 1, 0, 1, 1 ]; + + values = [ + new BooleanArray( 4 ), + new Complex128Array( 4 ) + ]; + 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() { + mskrange( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided unequal length arrays', function test( t ) { + var values; + var x; + var i; + + x = [ 1, 0, 1 ]; + + values = [ + [], + [ 1 ], + [ 1, 0 ], + [ 1, 0, 1, 0 ], + [ 1, 0, 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskrange( x, value ); + }; + } +}); + +tape( 'the function calculates the range of an array', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskrange( x, mask ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 0, 1, 0 ]; + v = mskrange( x, mask ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskrange( x, mask ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 0, 0, 0, 0 ]; + v = mskrange( x, mask ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskrange( x, mask ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = mskrange( x, mask ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = mskrange( x, mask ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = mskrange( x, mask ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = mskrange( x, mask ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the range of an array (accessors)', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 0, 1, 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 0, 0, 0, 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = mskrange( toAccessorArray( x ), toAccessorArray( mask ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the range of an array (array-like object)', function test( t ) { + var mask; + var x; + var v; + + mask = [ 0, 0, 0, 1, 0, 0, 0 ]; + x = { + 'length': 7, + '0': 1.0, + '1': -2.0, + '2': -4.0, + '3': NaN, + '4': 5.0, + '5': 0.0, + '6': 3.0 + }; + v = mskrange( x, mask ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty array, the function returns `NaN`', function test( t ) { + var v = mskrange( [], [] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty array, the function returns `NaN` (accessors)', function test( t ) { + var v = mskrange( toAccessorArray( [] ), toAccessorArray( [] ) ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an array containing a single element, the function returns `0`', function test( t ) { + var v = mskrange( [ 1.0 ], [ 0 ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an array containing a single element, the function returns `0` (accessors)', function test( t ) { + var v = mskrange( toAccessorArray( [ 1.0 ] ), toAccessorArray( [ 0 ] ) ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +});