diff --git a/lib/node_modules/@stdlib/stats/array/cumax/README.md b/lib/node_modules/@stdlib/stats/array/cumax/README.md new file mode 100644 index 000000000000..edd895707a95 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/README.md @@ -0,0 +1,112 @@ + + +# cumax + +> Calculate the cumulative maximum value of an array. + +
+ +
+ + + +
+ +## Usage + +```javascript +var cumax = require( '@stdlib/stats/array/cumax' ); +``` + +#### cumax( x, y ) + +Computes the cumulative maximum value of an array. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; +var y = [ 0.0, 0.0, 0.0 ]; + +cumax( x, y ); +// y => [ 1.0, 1.0, 2.0 ] +``` + +The function has the following parameters: + +- **x**: input array. +- **y**: output array. + +
+ + + +
+ +## Notes + +- 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cumax = require( '@stdlib/stats/array/cumax' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var y = new Float64Array( x.length ); +console.log( x ); +console.log( y ); + +cumax( x, y ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/array/cumax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/array/cumax/benchmark/benchmark.js new file mode 100644 index 000000000000..e01bdd291224 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var cumax = 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 x = uniform( len, -10, 10, options ); + var y = zeros( len, options.dtype ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + gfill( len, 0.0, y, 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 1.0; + v = cumax( x, y ); + 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/cumax/docs/repl.txt b/lib/node_modules/@stdlib/stats/array/cumax/docs/repl.txt new file mode 100644 index 000000000000..28964779f135 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}( x, y ) + Computes the cumulative maximum value of an array. + + Parameters + ---------- + x: Array|TypedArray + Input array. + + y: Array|TypedArray + Output array. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + > var x = [ 1.0, -2.0, 2.0 ]; + > var y = [ 0.0, 0.0, 0.0 ]; + > {{alias}}( x, y ) + [ 1.0, 1.0, 2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/array/cumax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/array/cumax/docs/types/index.d.ts new file mode 100644 index 000000000000..9f292575cf27 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/docs/types/index.d.ts @@ -0,0 +1,54 @@ +/* +* @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; + +/** +* Output array. +*/ +type OutputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Computes the cumulative maximum value of an array. +* +* @param x - input array +* @param y - output array +* @returns output array +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0 ]; +* +* cumax( x, y ); +* // y => [ 1.0, 1.0, 2.0 ] +*/ +declare function cumax( x: InputArray, y: T ): T; + + +// EXPORTS // + +export = cumax; diff --git a/lib/node_modules/@stdlib/stats/array/cumax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/array/cumax/docs/types/test.ts new file mode 100644 index 000000000000..ec7fb7d1138e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/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 cumax = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + cumax( x, y ); // $ExpectType Float64Array + cumax( new AccessorArray( x ), new AccessorArray( x ) ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + + cumax( 10, y ); // $ExpectError + cumax( '10', y ); // $ExpectError + cumax( true, y ); // $ExpectError + cumax( false, y ); // $ExpectError + cumax( null, y ); // $ExpectError + cumax( undefined, y ); // $ExpectError + cumax( {}, y ); // $ExpectError + cumax( ( x: number ): number => x, y ); // $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 ); + + cumax( x, 10 ); // $ExpectError + cumax( x, '10' ); // $ExpectError + cumax( x, true ); // $ExpectError + cumax( x, false ); // $ExpectError + cumax( x, null ); // $ExpectError + cumax( x, undefined ); // $ExpectError + cumax( x, {} ); // $ExpectError + cumax( 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 y = new Float64Array( 10 ); + + cumax(); // $ExpectError + cumax( x ); // $ExpectError + cumax( x, y, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/array/cumax/examples/index.js b/lib/node_modules/@stdlib/stats/array/cumax/examples/index.js new file mode 100644 index 000000000000..8ccfc6b562d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cumax = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var y = new Float64Array( x.length ); +console.log( x ); +console.log( y ); + +cumax( x, y ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/stats/array/cumax/lib/index.js b/lib/node_modules/@stdlib/stats/array/cumax/lib/index.js new file mode 100644 index 000000000000..c7bebacfaa88 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/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 cumulative maximum value of an array. +* +* @module @stdlib/stats/array/cumax +* +* @example +* var cumax = require( '@stdlib/stats/array/cumax' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0 ]; +* +* cumax( x, y ); +* // y => [ 1.0, 1.0, 2.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/array/cumax/lib/main.js b/lib/node_modules/@stdlib/stats/array/cumax/lib/main.js new file mode 100644 index 000000000000..429abbcf5b83 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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/cumax' ).ndarray; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var IDTYPES = dtypes( 'real_and_generic' ); +var GENERIC_DTYPE = 'generic'; + + +// MAIN // + +/** +* Computes the cumulative maximum value of an array. +* +* @param {NumericArray} x - input array +* @param {NumericArray} y - output 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 +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0 ]; +* +* cumax( x, y ); +* // y => [ 1.0, 1.0, 2.0 ] +*/ +function cumax( x, y ) { + 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( y ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', y ) ); + } + dt = dtype( y ) || 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 ) ); + } + return strided( x.length, x, 1, 0, y, 1, 0 ); +} + + +// EXPORTS // + +module.exports = cumax; diff --git a/lib/node_modules/@stdlib/stats/array/cumax/package.json b/lib/node_modules/@stdlib/stats/array/cumax/package.json new file mode 100644 index 000000000000..d1d3aaa7424b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/stats/array/cumax", + "version": "0.0.0", + "description": "Calculate the cumulative maximum value of an array.", + "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", + "range", + "extremes", + "domain", + "extent", + "accumulate", + "cumulative", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/array/cumax/test/test.js b/lib/node_modules/@stdlib/stats/array/cumax/test/test.js new file mode 100644 index 000000000000..b1d16ac4c633 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/cumax/test/test.js @@ -0,0 +1,365 @@ +/** +* @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 isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var cumax = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cumax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 2', function test( t ) { + t.strictEqual( cumax.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 i; + var y; + + y = [ 1.0, -2.0, 2.0 ]; + 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() { + cumax( value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which has an unsupported data type', function test( t ) { + var values; + var i; + var y; + + y = [ 1.0, -2.0, 2.0 ]; + 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() { + cumax( value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an array-like object', function test( t ) { + var values; + var i; + var x; + + x = [ 1.0, -2.0, 2.0 ]; + 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() { + cumax( 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 i; + var x; + + x = [ 1.0, -2.0, 2.0 ]; + 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() { + cumax( x, value ); + }; + } +}); + +tape( 'the function calculates the cumulative maximum value of an array', function test( t ) { + var expected; + var x; + var y; + var i; + + x = [ 1.0, -2.0, 3.0, -4.0, 5.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + cumax( x, y ); + + expected = [ + 1.0, + 1.0, + 3.0, + 3.0, + 5.0 + ]; + t.deepEqual( y, expected, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + y = [ 0.0, 0.0, 0.0 ]; + cumax( x, y ); + + expected = [ + -0.0, + 0.0, + 0.0 + ]; + for ( i = 0; i < y.length; i++ ) { + if ( isNegativeZero( expected[ i ] ) ) { + t.strictEqual( isNegativeZero( y[ i ] ), true, 'returns expected value. i: ' + i ); + } else { + t.strictEqual( y[ i ], expected[ i ], true, 'returns expected value. i: ' + i ); + } + } + + x = [ NaN ]; + y = [ 0.0 ]; + cumax( x, y ); + + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isnan( y[ i ] ), true, 'returns expected value. i: ' + i ); + } + + x = [ NaN, NaN ]; + y = [ 0.0, 0.0 ]; + cumax( x, y ); + + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isnan( y[ i ] ), true, 'returns expected value. i: ' + i ); + } + + x = [ 1.0, NaN, 3.0, NaN ]; + y = [ 0.0, 0.0, 0.0, 0.0 ]; + cumax( x, y ); + + expected = [ + 1.0, + NaN, + NaN, + NaN + ]; + for ( i = 0; i < y.length; i++ ) { + if ( isnan( expected[ i ] ) ) { + t.strictEqual( isnan( y[ i ] ), true, 'returns expected value. i: ' + i ); + } else { + t.strictEqual( y[ i ], expected[ i ], true, 'returns expected value. i: ' + i ); + } + } + t.end(); +}); + +tape( 'the function calculates the cumulative maximum value of an array (accessors)', function test( t ) { + var expected; + var x; + var y; + var i; + + x = [ 1.0, -2.0, 3.0, -4.0, 5.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + cumax( toAccessorArray( x ), toAccessorArray( y ) ); + + expected = [ + 1.0, + 1.0, + 3.0, + 3.0, + 5.0 + ]; + t.deepEqual( y, expected, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + y = [ 0.0, 0.0, 0.0 ]; + cumax( toAccessorArray( x ), toAccessorArray( y ) ); + + expected = [ + -0.0, + 0.0, + 0.0 + ]; + for ( i = 0; i < y.length; i++ ) { + if ( isNegativeZero( expected[ i ] ) ) { + t.strictEqual( isNegativeZero( y[ i ] ), true, 'returns expected value. i: ' + i ); + } else { + t.strictEqual( y[ i ], expected[ i ], true, 'returns expected value. i: ' + i ); + } + } + + x = [ NaN ]; + y = [ 0.0 ]; + cumax( toAccessorArray( x ), toAccessorArray( y ) ); + + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isnan( y[ i ] ), true, 'returns expected value. i: ' + i ); + } + + x = [ NaN, NaN ]; + y = [ 0.0, 0.0 ]; + cumax( toAccessorArray( x ), toAccessorArray( y ) ); + + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isnan( y[ i ] ), true, 'returns expected value. i: ' + i ); + } + + x = [ 1.0, NaN, 3.0, NaN ]; + y = [ 0.0, 0.0, 0.0, 0.0 ]; + cumax( toAccessorArray( x ), toAccessorArray( y ) ); + + expected = [ + 1.0, + NaN, + NaN, + NaN + ]; + for ( i = 0; i < y.length; i++ ) { + if ( isnan( expected[ i ] ) ) { + t.strictEqual( isnan( y[ i ] ), true, 'returns expected value. i: ' + i ); + } else { + t.strictEqual( y[ i ], expected[ i ], true, 'returns expected value. i: ' + i ); + } + } + t.end(); +}); + +tape( 'the function calculates the cumulative maximum value of an array (array-like object)', function test( t ) { + var expected; + var x; + var y; + + x = { + 'length': 5, + '0': 1.0, + '1': -2.0, + '2': 3.0, + '3': -4.0, + '4': 5.0 + }; + y = { + 'length': 5, + '0': 0.0, + '1': 0.0, + '2': 0.0, + '3': 0.0, + '4': 0.0 + }; + cumax( x, y ); + + expected = { + 'length': 5, + '0': 1.0, + '1': 1.0, + '2': 3.0, + '3': 3.0, + '4': 5.0 + }; + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = cumax( x, y ); + t.strictEqual( out, y, 'same reference' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array (accessors)', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = cumax( x, y ); + t.strictEqual( out, y, 'same reference' ); + + t.end(); +}); + +tape( 'if provided an empty array, the function returns empty array', function test( t ) { + var v = cumax( [], [] ); + t.deepEqual( v, [], 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty array, the function returns empty array (accessors)', function test( t ) { + var v = cumax( toAccessorArray( [] ), toAccessorArray( [] ) ); + t.deepEqual( v, toAccessorArray( [] ), 'returns expected value' ); + t.end(); +});