Skip to content

Commit bbc7228

Browse files
committed
ulp-based test for the betainc
1 parent 187e141 commit bbc7228

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

  • lib/node_modules/@stdlib/math/base/special/betainc/test

lib/node_modules/@stdlib/math/base/special/betainc/test/test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var abs = require( '@stdlib/math/base/special/abs' );
26-
var EPS = require( '@stdlib/constants/float64/eps' );
26+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2727
var betainc = require( './../lib' );
2828

2929

@@ -71,83 +71,83 @@ tape( 'the function returns `NaN` negative `a` or `b`', function test( t ) {
7171

7272
tape( 'the function evaluates the lower regularized incomplete beta function', function test( t ) {
7373
var expected;
74-
var delta;
75-
var tol;
7674
var i;
7775
var y;
7876

7977
expected = lowerRegularized;
8078
for ( i = 0; i < x.length; i++ ) {
8179
y = betainc( x[i], a[i], b[i] );
82-
if ( y === expected[i] ) {
83-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+'. a: '+a[i]+'. b: '+b[i]+', expected: '+expected[i] );
80+
if ( isnan( expected[ i ] ) ) {
81+
t.strictEqual( isnan( y ), true, 'returns expected value' );
82+
} else if ( expected[ i ] === 0.0 ) {
83+
t.strictEqual( y, 0.0, 'returns expected value' );
84+
} else if ( abs( expected[ i ] ) < 1e-300 ) {
85+
t.ok( abs( y ) < 1e-300, 'returns expected value' );
8486
} else {
85-
delta = abs( y - expected[ i ] );
86-
tol = 50.0 * EPS * abs( expected[ i ] );
87-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. a: '+a[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
87+
t.strictEqual(isAlmostSameValue( y, expected[ i ], 120 ), true, 'returns expected value');
8888
}
8989
}
9090
t.end();
9191
});
9292

9393
tape( 'the function evaluates the lower unregularized incomplete beta function', function test( t ) {
9494
var expected;
95-
var delta;
96-
var tol;
9795
var i;
9896
var y;
9997

10098
expected = lowerUnregularized;
10199
for ( i = 0; i < x.length; i++ ) {
102100
y = betainc( x[i], a[i], b[i], false );
103-
if ( y === expected[i] ) {
104-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+'. a: '+a[i]+'. b: '+b[i]+', expected: '+expected[i] );
101+
if ( isnan( expected[ i ] ) ) {
102+
t.strictEqual( isnan( y ), true, 'returns expected value' );
103+
} else if ( abs( expected[ i ] ) < 1e-300 ) {
104+
t.ok( abs( y ) < 1e-300, 'returns expected value' );
105+
} else if ( expected[ i ] === Infinity || expected[ i ] === -Infinity ) {
106+
t.strictEqual( y, expected[ i ], 'returns expected value' );
105107
} else {
106-
delta = abs( y - expected[ i ] );
107-
tol = 80.0 * EPS * abs( expected[ i ] );
108-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. a: '+a[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
108+
t.strictEqual(isAlmostSameValue( y, expected[ i ], 128 ), true, 'returns expected value');
109109
}
110110
}
111111
t.end();
112112
});
113113

114114
tape( 'the function evaluates the upper regularized incomplete beta function', function test( t ) {
115115
var expected;
116-
var delta;
117-
var tol;
118116
var i;
119117
var y;
120118

121119
expected = upperRegularized;
122120
for ( i = 0; i < x.length; i++ ) {
123121
y = betainc( x[i], a[i], b[i], true, true );
124-
if ( y === expected[i] ) {
125-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+'. a: '+a[i]+'. b: '+b[i]+', expected: '+expected[i] );
122+
if ( isnan( expected[ i ] ) ) {
123+
t.strictEqual( isnan( y ), true, 'returns expected value' );
124+
} else if ( abs( expected[ i ] ) < 1e-300 ) {
125+
t.ok( abs( y ) < 1e-300, 'returns expected value' );
126+
} else if ( expected[ i ] === Infinity || expected[ i ] === -Infinity ) {
127+
t.strictEqual( y, expected[ i ], 'returns expected value' );
126128
} else {
127-
delta = abs( y - expected[ i ] );
128-
tol = 50.0 * EPS * abs( expected[ i ] );
129-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. a: '+a[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
129+
t.strictEqual(isAlmostSameValue( y, expected[ i ], 80 ), true, 'returns expected value');
130130
}
131131
}
132132
t.end();
133133
});
134134

135135
tape( 'the function evaluates the upper unregularized incomplete beta function', function test( t ) {
136136
var expected;
137-
var delta;
138-
var tol;
139137
var i;
140138
var y;
141139

142140
expected = upperUnregularized;
143141
for ( i = 0; i < x.length; i++ ) {
144142
y = betainc( x[i], a[i], b[i], false, true );
145-
if ( y === expected[i] ) {
146-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+'. a: '+a[i]+'. b: '+b[i]+', expected: '+expected[i] );
143+
if ( isnan( expected[ i ] ) ) {
144+
t.strictEqual( isnan( y ), true, 'returns expected value' );
145+
} else if ( abs( expected[ i ] ) < 1e-300 ) {
146+
t.ok( abs( y ) < 1e-300, 'returns expected value' );
147+
} else if ( expected[ i ] === Infinity || expected[ i ] === -Infinity ) {
148+
t.strictEqual( y, expected[ i ], 'returns expected value' );
147149
} else {
148-
delta = abs( y - expected[ i ] );
149-
tol = 80.0 * EPS * abs( expected[ i ] );
150-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. a: '+a[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
150+
t.strictEqual(isAlmostSameValue( y, expected[ i ], 120 ), true, 'returns expected value');
151151
}
152152
}
153153
t.end();

0 commit comments

Comments
 (0)