From 6e7706237c9a1eff990b11daa282176200ffa081 Mon Sep 17 00:00:00 2001 From: AaryaBalwadkarPHC Date: Fri, 21 Mar 2025 20:18:50 +0530 Subject: [PATCH] feat(stats): add nanmmidrange package --- .../@stdlib/stats/incr/nanmmidrange/README.md | 166 ++++++++ .../incr/nanmmidrange/benchmark/benchmark.js | 69 ++++ .../stats/incr/nanmmidrange/docs/repl.txt | 51 +++ .../incr/nanmmidrange/docs/types/index.d.ts | 76 ++++ .../incr/nanmmidrange/docs/types/test.ts | 68 ++++ .../stats/incr/nanmmidrange/examples/index.js | 38 ++ .../stats/incr/nanmmidrange/lib/index.js | 60 +++ .../stats/incr/nanmmidrange/lib/main.js | 75 ++++ .../stats/incr/nanmmidrange/package.json | 75 ++++ .../stats/incr/nanmmidrange/test/test.js | 371 ++++++++++++++++++ 10 files changed, 1049 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmidrange/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/README.md new file mode 100644 index 000000000000..d5d9955b93f3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/README.md @@ -0,0 +1,166 @@ + + +# incrnanmmidrange + +> Compute a moving [mid-range][mid-range] incrementally, ignoring `NaN` values. + +
+ +The [**mid-range**][mid-range], or **mid-extreme**, is the arithmetic mean of maximum and minimum values. Accordingly, the [mid-range][mid-range] is the midpoint of the [range][range] and a measure of central tendency. + +
+ + + +
+ +## Usage + +```javascript +var incrnanmmidrange = require( '@stdlib/stats/incr/nanmmidrange' ); +``` + +#### incrnanmmidrange( window ) + +Returns an accumulator `function` which incrementally computes a moving [mid-range][mid-range], ignoring `NaN` values. The `window` parameter defines the number of values over which to compute the moving [mid-range][mid-range]. + +```javascript +var accumulator = incrnanmmidrange( 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated [mid-range][mid-range]. If not provided an input value `x`, the accumulator function returns the current [mid-range][mid-range]. + +```javascript +var accumulator = incrnanmmidrange( 3 ); + +var mr = accumulator(); +// returns null + +// Fill the window... +mr = accumulator( 2.0 ); // [2.0] +// returns 2.0 + +mr = accumulator( 1.0 ); // [2.0, 1.0] +// returns 1.5 + +mr = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns 2.0 + +// Window begins sliding... +mr = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns -2.0 + +mr = accumulator( NaN ); // [1.0, 3.0, -7.0] +// returns -2.0 + +mr = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns -2.0 + +mr = accumulator(); +// returns -2.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrmmidrange = require( '@stdlib/stats/incr/mmidrange' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrmmidrange( 5 ); + +// For each simulated datum, update the moving mid-range... +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/benchmark/benchmark.js new file mode 100644 index 000000000000..9d04684d81b6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanmmidrange = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmmidrange( (i%5)+1 ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmmidrange( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/repl.txt new file mode 100644 index 000000000000..10e350a23013 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving mid- + range, ignoring `NaN` values. + + The mid-range is the arithmetic mean of maximum and minimum values. + Accordingly, the mid-range is the midpoint of the range and a measure of + central tendency. + + The `W` parameter defines the number of values over which to compute + the moving mid-range. + + If provided a value, the accumulator function returns an updated moving mid- + range. If not provided a value, the accumulator function returns the current + moving mid-range. + + As `W` values are needed to fill the window buffer, the first `W-1` returned + values are calculated from smaller sample sizes. Until the window is full, + each returned value is calculated from all provided values. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var mr = accumulator() + null + > mr = accumulator( 2.0 ) + 2.0 + > mr = accumulator( -5.0 ) + -1.5 + > mr = accumulator( 3.0 ) + -1.0 + > mr = accumulator( 5.0 ) + 0.0 + mr = accumulator( NaN ) + 0.0 + > mr = accumulator() + 0.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/index.d.ts new file mode 100644 index 000000000000..f02116273b22 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/index.d.ts @@ -0,0 +1,76 @@ +/* +* @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 + +/// + +/** +* If provided a value, returns an updated mid-range; otherwise, returns the current mid-range. +* +* ## Notes +* +* - The mid-range is the arithmetic mean of maximum and minimum values. Accordingly, the mid-range is the midpoint of the range and a measure of central tendency. +* +* @param x - value +* @returns mid-range +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving mid-range. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving mid-range. +* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmmidrange( 3 ); +* +* var mr = accumulator(); +* // returns null +* +* mr = accumulator( 2.0 ); +* // returns 2.0 +* +* mr = accumulator( -5.0 ); +* // returns -1.5 +* +* mr = accumulator( 3.0 ); +* // returns -1.0 +* +* mr = accumulator( 5.0 ); +* // returns 0.0 +* +* mr = accumulator( NaN ); +* // returns 0.0 +* +* mr = accumulator(); +* // returns 0.0 +*/ +declare function incrnanmmidrange( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmmidrange; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/test.ts new file mode 100644 index 000000000000..2ea6d39dc3dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/docs/types/test.ts @@ -0,0 +1,68 @@ +/* +* @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 incrnanmmidrange = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmmidrange( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrnanmmidrange( '5' ); // $ExpectError + incrnanmmidrange( true ); // $ExpectError + incrnanmmidrange( false ); // $ExpectError + incrnanmmidrange( null ); // $ExpectError + incrnanmmidrange( undefined ); // $ExpectError + incrnanmmidrange( [] ); // $ExpectError + incrnanmmidrange( {} ); // $ExpectError + incrnanmmidrange( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmmidrange(); // $ExpectError + incrnanmmidrange( 2, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmmidrange( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null + acc( 5 ); // $ExpectType number | null + acc( -2 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmmidrange( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/examples/index.js new file mode 100644 index 000000000000..f3d796e81c76 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var incrnanmmidrange = require( './../lib' ); + +var accumulator; +var mr; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmidrange( 5 ); + +// For each simulated datum, update the moving mid-range... +console.log( '\nValue\tMid-Range\n' ); +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + mr = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), mr.toFixed( 4 ) ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/index.js new file mode 100644 index 000000000000..50a60b3111ca --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/index.js @@ -0,0 +1,60 @@ +/** +* @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 a moving mid-range incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmmidrange +* +* @example +* var incrnanmmidrange = require( '@stdlib/stats/incr/nanmmidrange' ); +* +* var accumulator = incrnanmmidrange( 3 ); +* +* var mr = accumulator(); +* // returns null +* +* mr = accumulator( 2.0 ); +* // returns 2.0 +* +* mr = accumulator( -5.0 ); +* // returns -1.5 +* +* mr = accumulator( 3.0 ); +* // returns -1.0 +* +* mr = accumulator( 5.0 ); +* // returns 0.0 +* +* mr = accumulator( NaN ); +* // returns 0.0 +* +* mr = accumulator(); +* // returns 0.0 +*/ + +// MODULES // + +var main = require( '@stdlib/stats/incr/nanmmidrange/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/main.js new file mode 100644 index 000000000000..aa76ecc188d5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/lib/main.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrmmidrange = require( '@stdlib/stats/incr/mmidrange' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving mid-range. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrmmidrange( 3 ); +* +* var mr = accumulator(); +* // returns null +* +* mr = accumulator( 2.0 ); +* // returns 2.0 +* +* mr = accumulator( -5.0 ); +* // returns -1.5 +* +* mr = accumulator( 3.0 ); +* // returns -1.0 +* +* mr = accumulator( 5.0 ); +* // returns 0.0 +* +* mr = accumulator( NaN ); +* // returns 0.0 +* +* mr = accumulator(); +* // returns 0.0 +*/ +function incrnanmmidrange( W ) { + var nanmmidrange = incrmmidrange( W ); + return accumulator; + + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return nanmmidrange(); + } + return nanmmidrange( x ); + }; +} + + +// EXPORTS // + +module.exports = incrnanmmidrange; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/package.json new file mode 100644 index 000000000000..3dbbe39aead5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/stats/incr/mmidrange", + "version": "0.0.0", + "description": "Compute a moving mid-range incrementally.", + "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", + "mid", + "range", + "mid-range", + "mid-extreme", + "mean", + "central tendency", + "incremental", + "accumulator", + "sliding window", + "sliding", + "window", + "moving" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmidrange/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/test/test.js new file mode 100644 index 000000000000..e732ed7f674c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmidrange/test/test.js @@ -0,0 +1,371 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanmmidrange = require( '@stdlib/stats/incr/nanmmidrange/lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmmidrange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + false, + null, + void 0, + NaN, + [], + {}, + 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() { + incrnanmmidrange( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmmidrange( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving mid-range incrementally', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, 2.0, 4.0, 3.0, NaN, 4.0, NaN, 2.0, 2.0, 2.0, NaN, 1.0, 0.0, 4.0, -1.0 ]; + N = data.length; + + acc = incrnanmmidrange( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ + 2.0, + 2.5, + 2.5, + 3.0, + 3.0, + 3.0, + 3.5, + 3.5, + 3.0, + 3.0, + 2.0, + 2.0, + 1.5, + 1.0, + 2.0, + 1.5 + ]; + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current mid-range', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 5.0, 4.0 ]; + acc = incrnanmmidrange( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 4.5, 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmmidrange( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function correctly handles signed zeros', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmmidrange( 3 ); + + data = [ + 0.0, // 0 => min: 0.0, max: 0.0 (0) + -0.0, // 0, -0 => min: -0.0, max: 0.0 (1) + 0.0, // 0, -0, 0 => min: -0.0, max: 0.0 (2) + 0.0, // -0, 0, 0 => min: -0.0, max: 0.0 (3) + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 (4) + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 (5) + 0.0, // 0, -0, 0 => min: -0.0, max: 0.0 (6) + 0.0, // -0, 0, 0 => min: -0.0, max: 0.0 (7) + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 (8) + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 (9) + -0.0, // 0, -0, -0 => min: -0.0, max: 0.0 (10) + -0.0, // -0, -0, -0 => min: -0.0, max: -0.0 (11) + 0.0, // -0, -0, 0 => min: -0.0, max: 0.0 (12) + + -0.0, // -0, 0, -0 => min: -0.0, max: 0.0 (13) + 0.0, // 0, -0, 0 => min: -0.0, max: 0.0 (14) + -0.0, // -0, 0, -0 => min: -0.0, max: 0.0 (15) + -0.0, // 0, -0, -0 => min: -0.0, max: 0.0 (16) + -0.0, // -0, -0, -0 => min: -0.0, max: -0.0 (17) + 0.0, // -0, -0, 0 => min: -0.0, max: 0.0 (18) + -0.0, // -0, 0, -0 => min: -0.0, max: 0.0 (19) + -0.0, // 0, -0, -0 => min: -0.0, max: 0.0 (20) + -0.0, // -0, -0, -0 => min: -0.0, max: -0.0 (21) + 0.0, // -0, -0, 0 => min: -0.0, max: 0.0 (22) + 0.0, // -0, 0, 0 => min: -0.0, max: 0.0 (23) + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 (24) + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 (25) + + // Case 1: out: -0, in: +0, cnt: 1 + 3.14, // 0, -0, 3.14 => min: -0.0, max: 3.14 + 3.14, // -0, 3.14, 3.14 => min: -0.0, max: 3.14 + 0.0, // 3.14, 3.14, 0 => min: 0.0, max: 3.14 + + // Case 2: out: +0, in: -0, cnt: 1 + 3.14, // 3.14, 0, 3.14 => min: 0.0, max: 3.14 + 3.14, // 0, 3.14, 3.14 => min: 0.0, max: 3.14 + -0.0, // 3.14, 3.14, -0 => min: -0.0, max: 3.14 + + // Case 3: out: -0, in: -0, cnt: 1 + 3.14, // 3.14, -0, 3.14 => min: -0.0, max: 3.14 + 3.14, // -0, 3.14, 3.14 => min: -0.0, max: 3.14 + -0.0, // 3.14, 3.14, -0 => min: -0.0, max: 3.14 + + // Case 4: out: -0, in: +0, cnt: 2 + 3.14, // 3.14, -0, 3.14 => min: -0.0, max: 3.14 + -0.0, // -0, 3.14, -0 => min: -0.0, max: 3.14 + 0.0, // 3.14, -0, 0 => min: -0.0, max: 3.14 + + // Case 5: out: +0, in: +0, cnt: 1 + 3.14, // -0, 0, 3.14 => min: -0.0, max: 3.14 + 3.14, // 0, 3.14, 3.14 => min: 0.0, max: 3.14 + 0.0, // 3.14, 3.14, 0 => min: 0.0, max: 3.14 + + // Case 6: out: +0, in: -0, cnt: 2 + 3.14, // 3.14, 0, 3.14 => min: 0.0, max: 3.14 + -0.0, // 0, 3.14, -0 => min: -0.0, max: 3.14 + 0.0, // 3.14, -0, 0 => min: -0.0, max: 3.14 + + // Case 7: out: +0, in: +0, cnt: 2 + 3.14, // -0, 0, 3.14 => min: -0.0, max: 3.14 + 0.0, // 0, 3.14, 0 => min: 0.0, max: 3.14 + 0.0, // 3.14, 0, 0 => min: 0.0, max: 3.14 + + // Reset: + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 + + // Case 8: out: -0, in: +0, cnt: 1 + -3.14, // 0, -0, -3.14 => min: -3.14, max: 0.0 + -3.14, // 0, -3.14, -3.14 => min: -3.14, max: 0.0 + 0.0, // -3.14, -3.14, 0 => min: -3.14, max: 0.0 + + // Case 9: out: +0, in: -0, cnt: 1 + -3.14, // -3.14, 0, 3.14 => min: -3.14, max: 0.0 + -3.14, // 0, -3.14, -3.14 => min: -3.14, max: 0.0 + -0.0, // -3.14, -3.14, -0 => min: -3.14, max: -0.0 + + // Case 10: out: -0, in: -0, cnt: 1 + -3.14, // -3.14, -0, -3.14 => min: -3.14, max: -0.0 + -3.14, // -0, -3.14, -3.14 => min: -3.14, max: -0.0 + -0.0, // -3.14, -3.14, -0 => min: -3.14, max: -0.0 + + // Case 11: out: -0, in: +0, cnt: 2 + -3.14, // -3.14, -0, -3.14 => min: -3.14, max: -0.0 + -0.0, // -0, -3.14, -0 => min: -3.14, max: -0.0 + 0.0, // -3.14, -0, 0 => min: -3.14, max: 0.0 + + // Case 12: out: +0, in: +0, cnt: 1 + -3.14, // -0, 0, -3.14 => min: -3.14, max: 0.0 + -3.14, // 0, -3.14, -3.14 => min: -3.14, max: 0.0 + 0.0, // -3.14, -3.14, 0 => min: -3.14, max: 0.0 + + // Case 13: out: +0, in: -0, cnt: 2 + -3.14, // -3.14, 0, -3.14 => min: -3.14, max: 0.0 + -0.0, // 0, -3.14, -0 => min: -3.14, max: 0.0 + 0.0, // -3.14, -0, 0 => min: -3.14, max: 0.0 + + // Case 14: out: +0, in: +0, cnt: 2 + -3.14, // -0, 0, -3.14 => min: -3.14, max: 0.0 + 0.0, // 0, -3.14, 0 => min: -3.14, max: 0.0 + 0.0, // -3.14, 0, 0 => min: -3.14, max: 0.0 + + // Reset: + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 + + // Case 15: out: +0, in: -0, cnt: 2 + -3.14, // 0, 0, -3.14 => min: -3.14, max: 0.0 + 0.0, // 0, -3.14, 0 => min: -3.14, max: 0.0 + -0.0 // -3.14, 0, -0 => min: -3.14, max: 0.0 + ]; + expected = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + + // Case 1: + 1.57, + 1.57, + 1.57, + + // Case 2: + 1.57, + 1.57, + 1.57, + + // Case 3: + 1.57, + 1.57, + 1.57, + + // Case 4: + 1.57, + 1.57, + 1.57, + + // Case 5: + 1.57, + 1.57, + 1.57, + + // Case 6: + 1.57, + 1.57, + 1.57, + + // Case 7: + 1.57, + 1.57, + 1.57, + + // Reset: + 0.0, + + // Case 8: + -1.57, + -1.57, + -1.57, + + // Case 9: + -1.57, + -1.57, + -1.57, + + // Case 10: + -1.57, + -1.57, + -1.57, + + // Case 11: + -1.57, + -1.57, + -1.57, + + // Case 12: + -1.57, + -1.57, + -1.57, + + // Case 13: + -1.57, + -1.57, + -1.57, + + // Case 14: + -1.57, + -1.57, + -1.57, + + // Reset: + 0.0, + + // Case 15: + -1.57, + -1.57, + -1.57 + ]; + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( expected[ i ] === 0.0 ) { + t.equal( isNegativeZero( v ), isNegativeZero( expected[ i ] ), 'returns expected value for window '+i ); + } else { + t.equal( v, expected[ i ], 'returns expected value for window '+i ); + } + } + t.end(); +});