Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

// MODULES //

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var abs = require( '@stdlib/math/base/special/abs' );

Check failure on line 27 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'abs' is assigned a value but never used
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );

Check failure on line 29 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'EPS' is assigned a value but never used
var quantile = require( './../lib' );


Expand All @@ -34,31 +36,39 @@
var largeP = require( './fixtures/julia/large_p.json' );


// VARIABLES //

var mgf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( mgf instanceof Error )
};


// TESTS //

tape( 'main export is a function', function test( t ) {
tape( 'main export is a function', opts, function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof quantile, 'function', 'main export is a function' );
t.end();
});

tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
var y = quantile( NaN, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
y = quantile( 0.0, NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.end();
});

tape( 'if provided a number outside `[0,1]` for `r` and a valid `p`, the function returns `NaN`', function test( t ) {
tape( 'if provided a number outside `[0,1]` for `r` and a valid `p`, the function returns `NaN`', opts, function test( t ) {
var y = quantile( 2.2, 0.8 );
t.equal( isnan( y ), true, 'returns true' );
y = quantile( -0.2, 0.8 );
t.equal( isnan( y ), true, 'returns true' );
t.end();
});

tape( 'if provided a success probability `p` outside `[0,1]`, the function returns `NaN`', function test( t ) {
tape( 'if provided a success probability `p` outside `[0,1]`, the function returns `NaN`', opts, function test( t ) {
var y;

y = quantile( 0.8, 1.5 );
Expand All @@ -73,52 +83,28 @@
t.end();
});

tape( 'the function evaluates the quantile for `r` given small parameter `p`', function test( t ) {
var expected;
var delta;
var tol;
var r;
var p;
var y;
var i;

expected = smallP.expected;
r = smallP.r;
p = smallP.p;
for ( i = 0; i < r.length; i++ ) {
y = quantile( r[i], p[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'r: '+r[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. r: '+r[ i ]+'. p: '+p[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
tape( 'the function evaluates the quantile for `r` given small parameter `p`', opts, function test( t ) {
var expected = smallP.expected;

Check failure on line 87 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces
var r = smallP.r;

Check failure on line 88 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces
var p = smallP.p;

Check failure on line 89 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces
var y;

Check failure on line 90 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces

Check failure on line 91 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Trailing spaces not allowed
for ( var i = 0; i < r.length; i++ ) {

Check failure on line 92 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

All 'var' declarations must be at the top of the function scope

Check failure on line 92 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Move variable declaration to function body root

Check failure on line 92 in lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces
y = quantile( r[i], p[i] );
t.equal( y, expected[i], 'r: ' + r[i] + ', p: ' + p[i] + ', y: ' + y + ', expected: ' + expected[i] );
}
t.end();
});

tape( 'the function evaluates the quantile for `r` given large parameter `p`', function test( t ) {
var expected;
var delta;
var tol;
var r;
var p;
var y;
var i;

expected = largeP.expected;
r = largeP.r;
p = largeP.p;
for ( i = 0; i < r.length; i++ ) {
y = quantile( r[i], p[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'r: '+r[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. r: '+r[ i ]+'. p: '+p[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
}
t.end();
});
tape( 'the function evaluates the quantile for `r` given large parameter `p`', opts, function test( t ) {
var expected = largeP.expected;
var r = largeP.r;
var p = largeP.p;
var y;

for ( var i = 0; i < r.length; i++ ) {
y = quantile( r[i], p[i] );
t.equal( y, expected[i], 'r: ' + r[i] + ', p: ' + p[i] + ', y: ' + y + ', expected: ' + expected[i] );
}
t.end();
});
Loading