Skip to content

Commit 41ff83e

Browse files
test: migrate math/base/special/erf to ULP base testing
PR-URL: #11355 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent d6c72a0 commit 41ff83e

File tree

2 files changed

+20
-166
lines changed

2 files changed

+20
-166
lines changed

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

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2626
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
2727
var NINF = require( '@stdlib/constants/float64/ninf' );
2828
var PINF = require( '@stdlib/constants/float64/pinf' );
29-
var EPS = require( '@stdlib/constants/float64/eps' );
30-
var abs = require( '@stdlib/math/base/special/abs' );
29+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
3130
var erf = require( './../lib' );
3231

3332

@@ -57,8 +56,6 @@ tape( 'main export is a function', function test( t ) {
5756

5857
tape( 'the function evaluates the error function for `x` on the interval `[-5,-100]', function test( t ) {
5958
var expected;
60-
var delta;
61-
var tol;
6259
var x;
6360
var y;
6461
var i;
@@ -67,21 +64,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[-5,-1
6764
x = veryLargeNegative.x;
6865
for ( i = 0; i < x.length; i++ ) {
6966
y = erf( x[i] );
70-
if ( y === expected[i] ) {
71-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
72-
} else {
73-
delta = abs( y - expected[ i ] );
74-
tol = EPS * abs( expected[ i ] );
75-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
76-
}
67+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
7768
}
7869
t.end();
7970
});
8071

8172
tape( 'the function evaluates the error function for `x` on the interval `[5,100]`', function test( t ) {
8273
var expected;
83-
var delta;
84-
var tol;
8574
var x;
8675
var y;
8776
var i;
@@ -90,21 +79,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[5,100
9079
x = veryLargePositive.x;
9180
for ( i = 0; i < x.length; i++ ) {
9281
y = erf( x[i] );
93-
if ( y === expected[i] ) {
94-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
95-
} else {
96-
delta = abs( y - expected[ i ] );
97-
tol = EPS * abs( expected[ i ] );
98-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
99-
}
82+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
10083
}
10184
t.end();
10285
});
10386

10487
tape( 'the function evaluates the error function for `x` on the interval `[-2.5,-5]`', function test( t ) {
10588
var expected;
106-
var delta;
107-
var tol;
10889
var x;
10990
var y;
11091
var i;
@@ -113,21 +94,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[-2.5,
11394
x = largeNegative.x;
11495
for ( i = 0; i < x.length; i++ ) {
11596
y = erf( x[i] );
116-
if ( y === expected[i] ) {
117-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
118-
} else {
119-
delta = abs( y - expected[ i ] );
120-
tol = EPS * abs( expected[ i ] );
121-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
122-
}
97+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
12398
}
12499
t.end();
125100
});
126101

127102
tape( 'the function evaluates the error function for `x` on the interval `[2.5,5]`', function test( t ) {
128103
var expected;
129-
var delta;
130-
var tol;
131104
var x;
132105
var y;
133106
var i;
@@ -136,21 +109,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[2.5,5
136109
x = largePositive.x;
137110
for ( i = 0; i < x.length; i++ ) {
138111
y = erf( x[i] );
139-
if ( y === expected[i] ) {
140-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
141-
} else {
142-
delta = abs( y - expected[ i ] );
143-
tol = EPS * abs( expected[ i ] );
144-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
145-
}
112+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
146113
}
147114
t.end();
148115
});
149116

150117
tape( 'the function evaluates the error function for `x` on the interval `[-1,-3]`', function test( t ) {
151118
var expected;
152-
var delta;
153-
var tol;
154119
var x;
155120
var y;
156121
var i;
@@ -159,21 +124,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[-1,-3
159124
x = mediumNegative.x;
160125
for ( i = 0; i < x.length; i++ ) {
161126
y = erf( x[i] );
162-
if ( y === expected[i] ) {
163-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
164-
} else {
165-
delta = abs( y - expected[ i ] );
166-
tol = EPS * abs( expected[ i ] );
167-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
168-
}
127+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
169128
}
170129
t.end();
171130
});
172131

173132
tape( 'the function evaluates the error function for `x` on the interval `[1,3]`', function test( t ) {
174133
var expected;
175-
var delta;
176-
var tol;
177134
var x;
178135
var y;
179136
var i;
@@ -182,13 +139,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[1,3]`
182139
x = mediumPositive.x;
183140
for ( i = 0; i < x.length; i++ ) {
184141
y = erf( x[i] );
185-
if ( y === expected[i] ) {
186-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
187-
} else {
188-
delta = abs( y - expected[ i ] );
189-
tol = EPS * abs( expected[ i ] );
190-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
191-
}
142+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
192143
}
193144
t.end();
194145
});

0 commit comments

Comments
 (0)