Skip to content

Commit 06dbaf0

Browse files
test: migrate math/base/special/erfc to ULP base testing
PR-URL: #11360 Reviewed-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Karan Anand <anandkarancompsci@gmail.com>
1 parent c722d47 commit 06dbaf0

File tree

2 files changed

+21
-175
lines changed

2 files changed

+21
-175
lines changed

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

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var NINF = require( '@stdlib/constants/float64/ninf' );
2626
var PINF = require( '@stdlib/constants/float64/pinf' );
27-
var EPS = require( '@stdlib/constants/float64/eps' );
28-
var abs = require( '@stdlib/math/base/special/abs' );
27+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2928
var erfc = require( './../lib' );
3029

3130

@@ -55,8 +54,6 @@ tape( 'main export is a function', function test( t ) {
5554

5655
tape( 'the function evaluates the complementary error function for `x` on the interval `[-5,-100]', function test( t ) {
5756
var expected;
58-
var delta;
59-
var tol;
6057
var x;
6158
var y;
6259
var i;
@@ -65,21 +62,13 @@ tape( 'the function evaluates the complementary error function for `x` on the in
6562
x = largerNegative.x;
6663
for ( i = 0; i < x.length; i++ ) {
6764
y = erfc( x[i] );
68-
if ( y === expected[i] ) {
69-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
70-
} else {
71-
delta = abs( y - expected[ i ] );
72-
tol = EPS * abs( expected[ i ] );
73-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
74-
}
65+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
7566
}
7667
t.end();
7768
});
7869

7970
tape( 'the function evaluates the complementary error function for `x` on the interval `[5,100]`', function test( t ) {
8071
var expected;
81-
var delta;
82-
var tol;
8372
var x;
8473
var y;
8574
var i;
@@ -88,21 +77,13 @@ tape( 'the function evaluates the complementary error function for `x` on the in
8877
x = largerPositive.x;
8978
for ( i = 0; i < x.length; i++ ) {
9079
y = erfc( x[i] );
91-
if ( y === expected[i] ) {
92-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
93-
} else {
94-
delta = abs( y - expected[ i ] );
95-
tol = EPS * abs( expected[ i ] );
96-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
97-
}
80+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
9881
}
9982
t.end();
10083
});
10184

10285
tape( 'the function evaluates the complementary error function for `x` on the interval `[-2.5,-28]`', function test( t ) {
10386
var expected;
104-
var delta;
105-
var tol;
10687
var x;
10788
var y;
10889
var i;
@@ -111,21 +92,13 @@ tape( 'the function evaluates the complementary error function for `x` on the in
11192
x = largeNegative.x;
11293
for ( i = 0; i < x.length; i++ ) {
11394
y = erfc( x[i] );
114-
if ( y === expected[i] ) {
115-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
116-
} else {
117-
delta = abs( y - expected[ i ] );
118-
tol = EPS * abs( expected[ i ] );
119-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
120-
}
95+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
12196
}
12297
t.end();
12398
});
12499

125100
tape( 'the function evaluates the complementary error function for `x` on the interval `[2.5,28]`', function test( t ) {
126101
var expected;
127-
var delta;
128-
var tol;
129102
var x;
130103
var y;
131104
var i;
@@ -134,21 +107,13 @@ tape( 'the function evaluates the complementary error function for `x` on the in
134107
x = largePositive.x;
135108
for ( i = 0; i < x.length; i++ ) {
136109
y = erfc( x[i] );
137-
if ( y === expected[i] ) {
138-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
139-
} else {
140-
delta = abs( y - expected[ i ] );
141-
tol = EPS * abs( expected[ i ] );
142-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
143-
}
110+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
144111
}
145112
t.end();
146113
});
147114

148115
tape( 'the function evaluates the complementary error function for `x` on the interval `[-1,-3]`', function test( t ) {
149116
var expected;
150-
var delta;
151-
var tol;
152117
var x;
153118
var y;
154119
var i;
@@ -157,21 +122,13 @@ tape( 'the function evaluates the complementary error function for `x` on the in
157122
x = mediumNegative.x;
158123
for ( i = 0; i < x.length; i++ ) {
159124
y = erfc( x[i] );
160-
if ( y === expected[i] ) {
161-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
162-
} else {
163-
delta = abs( y - expected[ i ] );
164-
tol = EPS * abs( expected[ i ] );
165-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
166-
}
125+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
167126
}
168127
t.end();
169128
});
170129

171130
tape( 'the function evaluates the complementary error function for `x` on the interval `[1,3]`', function test( t ) {
172131
var expected;
173-
var delta;
174-
var tol;
175132
var x;
176133
var y;
177134
var i;
@@ -180,21 +137,13 @@ tape( 'the function evaluates the complementary error function for `x` on the in
180137
x = mediumPositive.x;
181138
for ( i = 0; i < x.length; i++ ) {
182139
y = erfc( x[i] );
183-
if ( y === expected[i] ) {
184-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
185-
} else {
186-
delta = abs( y - expected[ i ] );
187-
tol = EPS * abs( expected[ i ] );
188-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
189-
}
140+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
190141
}
191142
t.end();
192143
});
193144

194145
tape( 'the function evaluates the complementary error function for `x` on the interval `[-0.8,-1]`', function test( t ) {
195146
var expected;
196-
var delta;
197-
var tol;
198147
var x;
199148
var y;
200149
var i;
@@ -203,13 +152,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
203152
x = smallNegative.x;
204153
for ( i = 0; i < x.length; i++ ) {
205154
y = erfc( x[i] );
206-
if ( y === expected[i] ) {
207-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
208-
} else {
209-
delta = abs( y - expected[ i ] );
210-
tol = EPS * abs( expected[ i ] );
211-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
212-
}
155+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
213156
}
214157
t.end();
215158
});

0 commit comments

Comments
 (0)