Skip to content

Commit 0eafdb6

Browse files
authored
test: migrate math/base/special/atan to ULP-based testing
PR-URL: #11657 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #11352
1 parent 1615c51 commit 0eafdb6

1 file changed

Lines changed: 14 additions & 119 deletions

File tree

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

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

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
26-
var EPS = require( '@stdlib/constants/float64/eps' );
25+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2726
var PINF = require( '@stdlib/constants/float64/pinf' );
2827
var NINF = require( '@stdlib/constants/float64/ninf' );
2928
var PI = require( '@stdlib/constants/float64/pi' );
@@ -59,8 +58,6 @@ tape( 'main export is a function', function test( t ) {
5958

6059
tape( 'the function computes the arctangent on the interval `[-1e-308,-1e-300]`', function test( t ) {
6160
var expected;
62-
var delta;
63-
var tol;
6461
var x;
6562
var y;
6663
var i;
@@ -70,21 +67,13 @@ tape( 'the function computes the arctangent on the interval `[-1e-308,-1e-300]`'
7067

7168
for ( i = 0; i < x.length; i++ ) {
7269
y = atan( x[i] );
73-
if ( y === expected[ i ] ) {
74-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
75-
} else {
76-
delta = abs( y - expected[i] );
77-
tol = 1.0 * EPS * abs( expected[i] );
78-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
79-
}
70+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
8071
}
8172
t.end();
8273
});
8374

8475
tape( 'the function computes the arctangent on the interval `[1e-300,1e-308]`', function test( t ) {
8576
var expected;
86-
var delta;
87-
var tol;
8877
var x;
8978
var y;
9079
var i;
@@ -94,21 +83,13 @@ tape( 'the function computes the arctangent on the interval `[1e-300,1e-308]`',
9483

9584
for ( i = 0; i < x.length; i++ ) {
9685
y = atan( x[i] );
97-
if ( y === expected[ i ] ) {
98-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
99-
} else {
100-
delta = abs( y - expected[i] );
101-
tol = 1.0 * EPS * abs( expected[i] );
102-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
103-
}
86+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
10487
}
10588
t.end();
10689
});
10790

10891
tape( 'the function computes the arctangent on the interval `[-0.8,0.8]`', function test( t ) {
10992
var expected;
110-
var delta;
111-
var tol;
11293
var x;
11394
var y;
11495
var i;
@@ -118,21 +99,13 @@ tape( 'the function computes the arctangent on the interval `[-0.8,0.8]`', funct
11899

119100
for ( i = 0; i < x.length; i++ ) {
120101
y = atan( x[i] );
121-
if ( y === expected[ i ] ) {
122-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
123-
} else {
124-
delta = abs( y - expected[i] );
125-
tol = 1.0 * EPS * abs( expected[i] );
126-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
127-
}
102+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
128103
}
129104
t.end();
130105
});
131106

132107
tape( 'the function computes the arctangent on the interval `[-1.0,-0.8]`', function test( t ) {
133108
var expected;
134-
var delta;
135-
var tol;
136109
var x;
137110
var y;
138111
var i;
@@ -142,21 +115,13 @@ tape( 'the function computes the arctangent on the interval `[-1.0,-0.8]`', func
142115

143116
for ( i = 0; i < x.length; i++ ) {
144117
y = atan( x[i] );
145-
if ( y === expected[ i ] ) {
146-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
147-
} else {
148-
delta = abs( y - expected[i] );
149-
tol = 1.0 * EPS * abs( expected[i] );
150-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
151-
}
118+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
152119
}
153120
t.end();
154121
});
155122

156123
tape( 'the function computes the arctangent on the interval `[0.8,1.0]`', function test( t ) {
157124
var expected;
158-
var delta;
159-
var tol;
160125
var x;
161126
var y;
162127
var i;
@@ -166,21 +131,13 @@ tape( 'the function computes the arctangent on the interval `[0.8,1.0]`', functi
166131

167132
for ( i = 0; i < x.length; i++ ) {
168133
y = atan( x[i] );
169-
if ( y === expected[ i ] ) {
170-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
171-
} else {
172-
delta = abs( y - expected[i] );
173-
tol = 1.0 * EPS * abs( expected[i] );
174-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
175-
}
134+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
176135
}
177136
t.end();
178137
});
179138

180139
tape( 'the function computes the arctangent on the interval `[-3.0,-1.0]`', function test( t ) {
181140
var expected;
182-
var delta;
183-
var tol;
184141
var x;
185142
var y;
186143
var i;
@@ -190,21 +147,13 @@ tape( 'the function computes the arctangent on the interval `[-3.0,-1.0]`', func
190147

191148
for ( i = 0; i < x.length; i++ ) {
192149
y = atan( x[i] );
193-
if ( y === expected[ i ] ) {
194-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
195-
} else {
196-
delta = abs( y - expected[i] );
197-
tol = 1.0 * EPS * abs( expected[i] );
198-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
199-
}
150+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
200151
}
201152
t.end();
202153
});
203154

204155
tape( 'the function computes the arctangent on the interval `[1.0,3.0]`', function test( t ) {
205156
var expected;
206-
var delta;
207-
var tol;
208157
var x;
209158
var y;
210159
var i;
@@ -214,21 +163,13 @@ tape( 'the function computes the arctangent on the interval `[1.0,3.0]`', functi
214163

215164
for ( i = 0; i < x.length; i++ ) {
216165
y = atan( x[i] );
217-
if ( y === expected[ i ] ) {
218-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
219-
} else {
220-
delta = abs( y - expected[i] );
221-
tol = 1.0 * EPS * abs( expected[i] );
222-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
223-
}
166+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
224167
}
225168
t.end();
226169
});
227170

228171
tape( 'the function computes the arctangent on the interval `[3.0,100.0]`', function test( t ) {
229172
var expected;
230-
var delta;
231-
var tol;
232173
var x;
233174
var y;
234175
var i;
@@ -238,21 +179,13 @@ tape( 'the function computes the arctangent on the interval `[3.0,100.0]`', func
238179

239180
for ( i = 0; i < x.length; i++ ) {
240181
y = atan( x[i] );
241-
if ( y === expected[ i ] ) {
242-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
243-
} else {
244-
delta = abs( y - expected[i] );
245-
tol = 1.0 * EPS * abs( expected[i] );
246-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
247-
}
182+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
248183
}
249184
t.end();
250185
});
251186

252187
tape( 'the function computes the arctangent on the interval `[-100.0,-3.0]`', function test( t ) {
253188
var expected;
254-
var delta;
255-
var tol;
256189
var x;
257190
var y;
258191
var i;
@@ -262,21 +195,13 @@ tape( 'the function computes the arctangent on the interval `[-100.0,-3.0]`', fu
262195

263196
for ( i = 0; i < x.length; i++ ) {
264197
y = atan( x[i] );
265-
if ( y === expected[ i ] ) {
266-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
267-
} else {
268-
delta = abs( y - expected[i] );
269-
tol = 1.0 * EPS * abs( expected[i] );
270-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
271-
}
198+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
272199
}
273200
t.end();
274201
});
275202

276203
tape( 'the function computes the arctangent on the interval `[100.0,1000.0]`', function test( t ) {
277204
var expected;
278-
var delta;
279-
var tol;
280205
var x;
281206
var y;
282207
var i;
@@ -286,21 +211,13 @@ tape( 'the function computes the arctangent on the interval `[100.0,1000.0]`', f
286211

287212
for ( i = 0; i < x.length; i++ ) {
288213
y = atan( x[i] );
289-
if ( y === expected[ i ] ) {
290-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
291-
} else {
292-
delta = abs( y - expected[i] );
293-
tol = 1.0 * EPS * abs( expected[i] );
294-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
295-
}
214+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
296215
}
297216
t.end();
298217
});
299218

300219
tape( 'the function computes the arctangent on the interval `[-1000.0,-100.0]`', function test( t ) {
301220
var expected;
302-
var delta;
303-
var tol;
304221
var x;
305222
var y;
306223
var i;
@@ -310,21 +227,13 @@ tape( 'the function computes the arctangent on the interval `[-1000.0,-100.0]`',
310227

311228
for ( i = 0; i < x.length; i++ ) {
312229
y = atan( x[i] );
313-
if ( y === expected[ i ] ) {
314-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
315-
} else {
316-
delta = abs( y - expected[i] );
317-
tol = 1.0 * EPS * abs( expected[i] );
318-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
319-
}
230+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
320231
}
321232
t.end();
322233
});
323234

324235
tape( 'the function computes the arctangent on the interval `[-1e200,-1e208]`', function test( t ) {
325236
var expected;
326-
var delta;
327-
var tol;
328237
var x;
329238
var y;
330239
var i;
@@ -334,21 +243,13 @@ tape( 'the function computes the arctangent on the interval `[-1e200,-1e208]`',
334243

335244
for ( i = 0; i < x.length; i++ ) {
336245
y = atan( x[i] );
337-
if ( y === expected[ i ] ) {
338-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
339-
} else {
340-
delta = abs( y - expected[i] );
341-
tol = 1.0 * EPS * abs( expected[i] );
342-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
343-
}
246+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
344247
}
345248
t.end();
346249
});
347250

348251
tape( 'the function computes the arctangent on the interval `[1e300,1e308]`', function test( t ) {
349252
var expected;
350-
var delta;
351-
var tol;
352253
var x;
353254
var y;
354255
var i;
@@ -358,13 +259,7 @@ tape( 'the function computes the arctangent on the interval `[1e300,1e308]`', fu
358259

359260
for ( i = 0; i < x.length; i++ ) {
360261
y = atan( x[i] );
361-
if ( y === expected[ i ] ) {
362-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
363-
} else {
364-
delta = abs( y - expected[i] );
365-
tol = 1.0 * EPS * abs( expected[i] );
366-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
367-
}
262+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
368263
}
369264
t.end();
370265
});

0 commit comments

Comments
 (0)