Skip to content
Merged
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
19 changes: 3 additions & 16 deletions lib/node_modules/@stdlib/stats/incr/nanmhmean/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// MODULES //

var tape = require( 'tape' );
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 incrnanmhmean = require( './../lib' );


Expand Down Expand Up @@ -72,9 +71,7 @@ tape( 'the function returns an accumulator function', function test( t ) {
tape( 'the accumulator function computes a moving harmonic mean incrementally', function test( t ) {
var expected;
var actual;
var delta;
var data;
var tol;
var acc;
var N;
var i;
Expand All @@ -101,24 +98,16 @@ tape( 'the accumulator function computes a moving harmonic 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 = EPSILON * abs( expected[ i ] );
t.equal( delta <= tol, true, 'within tolerance. Expected: '+expected[ i ]+'. Actual: '+actual[ i ]+'. Delta: '+delta+'. Tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

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

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

Expand Down