Skip to content

Commit 0cb00da

Browse files
authored
test: migrate math/base/special/cbrtf to ULP-based testing
PR-URL: #13552 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #11352
1 parent f25221d commit 0cb00da

2 files changed

Lines changed: 30 additions & 144 deletions

File tree

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

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
2626
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
2727
var PINF = require( '@stdlib/constants/float32/pinf' );
2828
var NINF = require( '@stdlib/constants/float32/ninf' );
29-
var EPS = require( '@stdlib/constants/float32/eps' );
30-
var abs = require( '@stdlib/math/base/special/abs' );
29+
var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
3130
var cbrtf = require( './../lib' );
3231

3332

@@ -59,8 +58,6 @@ tape( 'main export is a function', function test( t ) {
5958

6059
tape( 'the function evaluates the cubic root of `x` on the interval `[-50,-500]', function test( t ) {
6160
var expected;
62-
var delta;
63-
var tol;
6461
var x;
6562
var y;
6663
var i;
@@ -72,18 +69,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-50,-500]'
7269
if ( y === expected[i] ) {
7370
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
7471
} else {
75-
delta = abs( y - expected[ i ] );
76-
tol = EPS * abs( expected[ i ] );
77-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
72+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
7873
}
7974
}
8075
t.end();
8176
});
8277

8378
tape( 'the function evaluates the cubic root of `x` on the interval `[50,500]`', function test( t ) {
8479
var expected;
85-
var delta;
86-
var tol;
8780
var x;
8881
var y;
8982
var i;
@@ -95,18 +88,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[50,500]`',
9588
if ( y === expected[i] ) {
9689
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
9790
} else {
98-
delta = abs( y - expected[ i ] );
99-
tol = EPS * abs( expected[ i ] );
100-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
91+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
10192
}
10293
}
10394
t.end();
10495
});
10596

10697
tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-50]`', function test( t ) {
10798
var expected;
108-
var delta;
109-
var tol;
11099
var x;
111100
var y;
112101
var i;
@@ -118,18 +107,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-50]`'
118107
if ( y === expected[i] ) {
119108
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
120109
} else {
121-
delta = abs( y - expected[ i ] );
122-
tol = EPS * abs( expected[ i ] );
123-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
110+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
124111
}
125112
}
126113
t.end();
127114
});
128115

129116
tape( 'the function evaluates the cubic root of `x` on the interval `[20,50]`', function test( t ) {
130117
var expected;
131-
var delta;
132-
var tol;
133118
var x;
134119
var y;
135120
var i;
@@ -141,18 +126,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[20,50]`',
141126
if ( y === expected[i] ) {
142127
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
143128
} else {
144-
delta = abs( y - expected[ i ] );
145-
tol = EPS * abs( expected[ i ] );
146-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
129+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
147130
}
148131
}
149132
t.end();
150133
});
151134

152135
tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-3]`', function test( t ) {
153136
var expected;
154-
var delta;
155-
var tol;
156137
var x;
157138
var y;
158139
var i;
@@ -164,18 +145,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-3]`',
164145
if ( y === expected[i] ) {
165146
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
166147
} else {
167-
delta = abs( y - expected[ i ] );
168-
tol = EPS * abs( expected[ i ] );
169-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
148+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
170149
}
171150
}
172151
t.end();
173152
});
174153

175154
tape( 'the function evaluates the cubic root of `x` on the interval `[3,20]`', function test( t ) {
176155
var expected;
177-
var delta;
178-
var tol;
179156
var x;
180157
var y;
181158
var i;
@@ -187,18 +164,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[3,20]`', f
187164
if ( y === expected[i] ) {
188165
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
189166
} else {
190-
delta = abs( y - expected[ i ] );
191-
tol = EPS * abs( expected[ i ] );
192-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
167+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
193168
}
194169
}
195170
t.end();
196171
});
197172

198173
tape( 'the function evaluates the cubic root of `x` on the interval `[-3,-0.8]`', function test( t ) {
199174
var expected;
200-
var delta;
201-
var tol;
202175
var x;
203176
var y;
204177
var i;
@@ -210,18 +183,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-3,-0.8]`'
210183
if ( y === expected[i] ) {
211184
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
212185
} else {
213-
delta = abs( y - expected[ i ] );
214-
tol = EPS * abs( expected[ i ] );
215-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
186+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
216187
}
217188
}
218189
t.end();
219190
});
220191

221192
tape( 'the function evaluates the cubic root of `x` on the interval `[0.8,3]`', function test( t ) {
222193
var expected;
223-
var delta;
224-
var tol;
225194
var x;
226195
var y;
227196
var i;
@@ -233,18 +202,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[0.8,3]`',
233202
if ( y === expected[i] ) {
234203
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
235204
} else {
236-
delta = abs( y - expected[ i ] );
237-
tol = EPS * abs( expected[ i ] );
238-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
205+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
239206
}
240207
}
241208
t.end();
242209
});
243210

244211
tape( 'the function evaluates cubic root of `x` on the interval `[-0.8,0.8]`', function test( t ) {
245212
var expected;
246-
var delta;
247-
var tol;
248213
var x;
249214
var y;
250215
var i;
@@ -256,18 +221,14 @@ tape( 'the function evaluates cubic root of `x` on the interval `[-0.8,0.8]`', f
256221
if ( y === expected[i] ) {
257222
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
258223
} else {
259-
delta = abs( y - expected[ i ] );
260-
tol = EPS * abs( expected[ i ] );
261-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
224+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
262225
}
263226
}
264227
t.end();
265228
});
266229

267230
tape( 'the function evaluates the cubic root of `x` on the interval `[-1e-300,-1e-308]`', function test( t ) {
268231
var expected;
269-
var delta;
270-
var tol;
271232
var x;
272233
var y;
273234
var i;
@@ -279,18 +240,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-1e-300,-1
279240
if ( y === expected[i] ) {
280241
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
281242
} else {
282-
delta = abs( y - expected[ i ] );
283-
tol = EPS * abs( expected[ i ] );
284-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
243+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
285244
}
286245
}
287246
t.end();
288247
});
289248

290249
tape( 'the function evaluates the cubic root of `x` on the interval `[1e-300,1e-308]`', function test( t ) {
291250
var expected;
292-
var delta;
293-
var tol;
294251
var x;
295252
var y;
296253
var i;
@@ -302,18 +259,14 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[1e-300,1e-
302259
if ( y === expected[i] ) {
303260
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
304261
} else {
305-
delta = abs( y - expected[ i ] );
306-
tol = EPS * abs( expected[ i ] );
307-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
262+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
308263
}
309264
}
310265
t.end();
311266
});
312267

313268
tape( 'the function evaluates the cubic root of subnormal `x`', function test( t ) {
314269
var expected;
315-
var delta;
316-
var tol;
317270
var x;
318271
var y;
319272
var i;
@@ -325,18 +278,14 @@ tape( 'the function evaluates the cubic root of subnormal `x`', function test( t
325278
if ( y === expected[i] ) {
326279
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
327280
} else {
328-
delta = abs( y - expected[ i ] );
329-
tol = EPS * abs( expected[ i ] );
330-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
281+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
331282
}
332283
}
333284
t.end();
334285
});
335286

336287
tape( 'the function evaluates the cubic root of `x` (huge negative)', function test( t ) {
337288
var expected;
338-
var delta;
339-
var tol;
340289
var x;
341290
var y;
342291
var i;
@@ -349,18 +298,14 @@ tape( 'the function evaluates the cubic root of `x` (huge negative)', function t
349298
if ( y === expected[i] ) {
350299
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
351300
} else {
352-
delta = abs( y - expected[ i ] );
353-
tol = EPS * abs( expected[ i ] );
354-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
301+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
355302
}
356303
}
357304
t.end();
358305
});
359306

360307
tape( 'the function evaluates the cubic root of `x` (huge positive)', function test( t ) {
361308
var expected;
362-
var delta;
363-
var tol;
364309
var x;
365310
var y;
366311
var i;
@@ -373,9 +318,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t
373318
if ( y === expected[i] ) {
374319
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
375320
} else {
376-
delta = abs( y - expected[ i ] );
377-
tol = EPS * abs( expected[ i ] );
378-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
321+
t.strictEqual( isAlmostSameValuef( y, expected[i], 1 ), true, 'returns expected value' );
379322
}
380323
}
381324
t.end();

0 commit comments

Comments
 (0)