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
15 changes: 3 additions & 12 deletions lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

var tape = require( 'tape' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var absf = require( '@stdlib/math/base/special/absf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var binomcoeff = require( './../lib' );

Expand Down Expand Up @@ -54,8 +53,6 @@ tape( 'the function returns `NaN` if provided `NaN` for any parameter', function

tape( 'the function evaluates the binomial coefficient for integers `n` and `k`', function test( t ) {
var expected;
var delta;
var tol;
var n;
var k;
var v;
Expand All @@ -67,15 +64,9 @@ tape( 'the function evaluates the binomial coefficient for integers `n` and `k`'
for ( i = 0; i < n.length; i++ ) {
v = binomcoeff( n[ i ], k[ i ] );
expected[ i ] = float64ToFloat32( expected[ i ] );
if ( expected[ i ] === v ) {
t.strictEqual( v, expected[ i ], 'returns expected value' );
continue;
}
delta = absf( v - expected[ i ] );

// NOTE: Exact comparison fails for large values due to single-precision floating-point rounding errors when intermediate results exceed the maximum safe integer for a 32-bit float.
Comment thread
kgryte marked this conversation as resolved.
Comment thread
kgryte marked this conversation as resolved.
tol = 1.25 * EPS * absf( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. n: ' + n[ i ] + '. k: ' + k[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
t.strictEqual( isAlmostSameValue( v, expected[ i ], 2 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -93,7 +84,7 @@ tape( 'the function evaluates the binomial coefficient for integers `n` and `k`
for ( i = 0; i < n.length; i++ ) {
v = binomcoeff( n[ i ], k[ i ] );
expected[ i ] = float64ToFloat32( expected[ i ] );
t.strictEqual( v, expected[ i ], 'returns expected value. actual: '+v+'. expected: '+expected[i]+'. n: '+n[i]+'. k: '+k[i]+'.' );
Comment thread
kgryte marked this conversation as resolved.
t.strictEqual( v, expected[ i ], 'returns expected value' );
}
t.end();
});
Expand Down