Skip to content

test: add tests to achieve 100% code coverage #5638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
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 @@ -56,39 +56,39 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',

mgf = factory( 0.0, 1.0, 0.5 );
y = mgf( NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, 1.0, 0.5 );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 0.0, NaN, 0.5 );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 0.0, 1.0, NaN );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, NaN, NaN );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 0.0, NaN, NaN );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, 1.0, NaN );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, NaN, 0.5 );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, NaN, 0.5 );
y = mgf( NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -100,34 +100,49 @@ tape( 'if provided parameters not satisfying `a <= c <= b`, the created function
mgf = factory( 2.0, 1.0, 0.5 );

y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 0.0, NINF, 0.5 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( PINF, NINF, 0.5 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NINF, NINF, 0.5 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( -1.0, -2.0, 0.5 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( -10.0, 10.0, 12.0 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( -10.0, 10.0, -12.0 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});

tape( 'if provided valid `a`, `b`, and `c`, the function returns a function which returns `1` when provided `0` for `t`', function test( t ) {
var mgf;
var y;

mgf = factory( 0.0, 1.0, 0.5 );
y = mgf( 0.0 );
t.equal( y, 1.0, 'returns expected value' );

mgf = factory( -1.0, 1.0, 0.0 );
y = mgf( 0.0 );
t.equal( y, 1.0, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,48 @@ tape( 'main export is a function', function test( t ) {

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

tape( 'if provided parameters not satisfying `a <= c <= b`, the function returns `NaN`', function test( t ) {
var y;

y = mgf( 2.0, -1.0, -1.1, -1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0, 3.0, 2.0, 2.5 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0, 0.0, 1.0, -1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0, 0.0, 1.0, 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});

tape( 'if provided `0` for `t` and valid `a`, `b` and `c`, the function returns `1`', function test( t ) {
var y;

y = mgf( 0.0, -1.0, -1.0, -1.0 );
t.equal( y, 1.0, 'returns expected value' );

y = mgf( 0.0, 0.0, 1.0, 0.5 );
t.equal( y, 1.0, 'returns expected value' );

y = mgf( 0.0, 0.0, 1.0, 1.0 );
t.equal( y, 1.0, 'returns expected value' );

y = mgf( 0.0, 1.0, 1.0, 1.0 );
t.equal( y, 1.0, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@
t.end();
});

tape( 'if provided `0` for `t` and valid `a`, `b` and `c`, the function returns `1`', function test( t ) {
var y;

y = mgf( 0.0, -1.0, -1.0, -1.0 );
t.equal( y, 1.0, 'returns expected value' );

y = mgf( 0.0, 0.0, 1.0, 0.5 );
t.equal( y, 1.0, 'returns expected value' );

y = mgf( 0.0, 0.0, 1.0, 1.0 );
t.equal( y, 1.0, 'returns expected value' );

y = mgf( 0.0, 1.0, 1.0, 1.0 );
t.equal( y, 1.0, 'returns expected value' );

t.end();
});

tape( 'the function evaluates the MGF for `x` given a small range `b - a`', opts, function test( t ) {
var expected;
var delta;
Expand All @@ -104,7 +122,7 @@
} else {
delta = abs( y - expected[ i ] );

// FIXME: the tolerance for the C implementation is widely different from the JavaScript implementation, and it is not clear why.

Check warning on line 125 in lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: the tolerance for the C...'
tol = 1.0e7 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
Expand Down Expand Up @@ -135,7 +153,7 @@
} else {
delta = abs( y - expected[ i ] );

// FIXME: the tolerance for the C implementation is widely different from the JavaScript implementation, and it is not clear why.

Check warning on line 156 in lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: the tolerance for the C...'
tol = 1.0e7 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
Expand Down Expand Up @@ -166,7 +184,7 @@
} else {
delta = abs( y - expected[ i ] );

// FIXME: the tolerance for the C implementation is widely different from the JavaScript implementation, and it is not clear why.

Check warning on line 187 in lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: the tolerance for the C...'
tol = 1.0e7 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
Expand Down