Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions lib/node_modules/@stdlib/stats/incr/mgmean/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPSILON = require( '@stdlib/constants/float64/eps' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var incrmgmean = require( './../lib' );


Expand Down Expand Up @@ -73,9 +71,7 @@ tape( 'the function returns an accumulator function', function test( t ) {
tape( 'the accumulator function computes a moving geometric mean incrementally', function test( t ) {
var expected;
var actual;
var delta;
var data;
var tol;
var acc;
var N;
var i;
Expand All @@ -100,24 +96,16 @@ tape( 'the accumulator function computes a moving geometric mean incrementally',
];

for ( i = 0; i < N; i++ ) {
if ( actual[ i ] === expected[ i ] ) {
t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' );
} else {
delta = abs( expected[ i ] - actual[ i ] );
tol = 1.2 * EPSILON * abs( expected[ i ] );
t.strictEqual( delta <= tol, true, 'within tolerance. Expected: '+expected[ i ]+'. Actual: '+actual[ i ]+'. Delta: '+delta+'. Tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], 2 ), true, 'returns expected value' );
}
t.end();
});

tape( 'if not provided an input value, the accumulator function returns the current geometric mean', function test( t ) {
var expected;
var actual;
var delta;
var data;
var acc;
var tol;
var i;

data = [ 2.0, 3.0, 5.0 ];
Expand All @@ -127,9 +115,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr
}
actual = acc();
expected = 3.872983346207417; // Note: computed by hand using textbook formula
delta = abs( expected - actual );
tol = 1.0 * EPSILON * abs( expected );
t.strictEqual( delta <= tol, true, 'within tolerance. Expected: '+expected+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' );
t.strictEqual( isAlmostSameValue( actual, expected, 0 ), true, 'returns expected value' );
t.end();
});

Expand All @@ -141,10 +127,8 @@ tape( 'if data has yet to be provided, the accumulator function returns `null`',

tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invocations', function test( t ) {
var expected;
var delta;
var data;
var acc;
var tol;
var v;
var i;

Expand Down Expand Up @@ -194,15 +178,7 @@ tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invoca
];
for ( i = 0; i < data.length; i++ ) {
v = acc( data[ i ] );
if ( isnan( expected[ i ] ) ) {
t.strictEqual( isnan( v ), true, 'returns expected value for window '+i );
} else if ( v === expected[ i ] ) {
t.strictEqual( v, expected[ i ], 'returns expected value for window '+i );
} else {
delta = abs( expected[ i ] - v );
tol = 1.0 * EPSILON * abs( expected[ i ] );
t.strictEqual( delta <= tol, true, 'within tolerance for window '+i+'. Expected: '+expected[ i ]+'. Actual: '+v+'. Delta: '+delta+'. Tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value for window '+i );
}
t.end();
});
Loading