Skip to content

Commit f9aa653

Browse files
committed
test: use approximate equality for native addon tests
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5b3f1fe commit f9aa653

File tree

2 files changed

+106
-18
lines changed

2 files changed

+106
-18
lines changed

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ tape( 'the function evaluates the error function for `x` on the interval `[1,3]`
204204

205205
tape( 'the function evaluates the error function for `x` on the interval `[-0.8,-1]`', opts, function test( t ) {
206206
var expected;
207+
var delta;
208+
var tol;
207209
var x;
208210
var y;
209211
var i;
@@ -212,13 +214,21 @@ tape( 'the function evaluates the error function for `x` on the interval `[-0.8,
212214
x = smallNegative.x;
213215
for ( i = 0; i < x.length; i++ ) {
214216
y = erf( x[i] );
215-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
217+
if ( y === expected[i] ) {
218+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
219+
} else {
220+
delta = abs( y - expected[ i ] );
221+
tol = EPS * abs( expected[ i ] );
222+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
223+
}
216224
}
217225
t.end();
218226
});
219227

220228
tape( 'the function evaluates the error function for `x` on the interval `[0.8,1]`', opts, function test( t ) {
221229
var expected;
230+
var delta;
231+
var tol;
222232
var x;
223233
var y;
224234
var i;
@@ -227,13 +237,21 @@ tape( 'the function evaluates the error function for `x` on the interval `[0.8,1
227237
x = smallPositive.x;
228238
for ( i = 0; i < x.length; i++ ) {
229239
y = erf( x[i] );
230-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
240+
if ( y === expected[i] ) {
241+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
242+
} else {
243+
delta = abs( y - expected[ i ] );
244+
tol = EPS * abs( expected[ i ] );
245+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
246+
}
231247
}
232248
t.end();
233249
});
234250

235251
tape( 'the function evaluates the error function for `x` on the interval `[-0.8,0.8]`', opts, function test( t ) {
236252
var expected;
253+
var delta;
254+
var tol;
237255
var x;
238256
var y;
239257
var i;
@@ -242,13 +260,21 @@ tape( 'the function evaluates the error function for `x` on the interval `[-0.8,
242260
x = smaller.x;
243261
for ( i = 0; i < x.length; i++ ) {
244262
y = erf( x[i] );
245-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
263+
if ( y === expected[i] ) {
264+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
265+
} else {
266+
delta = abs( y - expected[ i ] );
267+
tol = EPS * abs( expected[ i ] );
268+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
269+
}
246270
}
247271
t.end();
248272
});
249273

250274
tape( 'the function evaluates the error function for `x` on the interval `[-1e-300,-1e-308]`', opts, function test( t ) {
251275
var expected;
276+
var delta;
277+
var tol;
252278
var x;
253279
var y;
254280
var i;
@@ -257,13 +283,21 @@ tape( 'the function evaluates the error function for `x` on the interval `[-1e-3
257283
x = tinyNegative.x;
258284
for ( i = 0; i < x.length; i++ ) {
259285
y = erf( x[i] );
260-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
286+
if ( y === expected[i] ) {
287+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
288+
} else {
289+
delta = abs( y - expected[ i ] );
290+
tol = EPS * abs( expected[ i ] );
291+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
292+
}
261293
}
262294
t.end();
263295
});
264296

265297
tape( 'the function evaluates the error function for `x` on the interval `[1e-300,1e-308]`', opts, function test( t ) {
266298
var expected;
299+
var delta;
300+
var tol;
267301
var x;
268302
var y;
269303
var i;
@@ -272,13 +306,21 @@ tape( 'the function evaluates the error function for `x` on the interval `[1e-30
272306
x = tinyPositive.x;
273307
for ( i = 0; i < x.length; i++ ) {
274308
y = erf( x[i] );
275-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
309+
if ( y === expected[i] ) {
310+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
311+
} else {
312+
delta = abs( y - expected[ i ] );
313+
tol = EPS * abs( expected[ i ] );
314+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
315+
}
276316
}
277317
t.end();
278318
});
279319

280320
tape( 'the function evaluates the error function for subnormal `x`', opts, function test( t ) {
281321
var expected;
322+
var delta;
323+
var tol;
282324
var x;
283325
var y;
284326
var i;
@@ -287,7 +329,13 @@ tape( 'the function evaluates the error function for subnormal `x`', opts, funct
287329
x = subnormal.x;
288330
for ( i = 0; i < x.length; i++ ) {
289331
y = erf( x[i] );
290-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
332+
if ( y === expected[i] ) {
333+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
334+
} else {
335+
delta = abs( y - expected[ i ] );
336+
tol = EPS * abs( expected[ i ] );
337+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
338+
}
291339
}
292340
t.end();
293341
});

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

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
7878
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
7979
} else {
8080
delta = abs( y - expected[ i ] );
81-
tol = EPS * abs( expected[ i ] );
81+
tol = 2.0 * EPS * abs( expected[ i ] );
8282
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
8383
}
8484
}
@@ -101,7 +101,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
101101
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
102102
} else {
103103
delta = abs( y - expected[ i ] );
104-
tol = EPS * abs( expected[ i ] );
104+
tol = 2.0 * EPS * abs( expected[ i ] );
105105
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
106106
}
107107
}
@@ -124,7 +124,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
124124
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
125125
} else {
126126
delta = abs( y - expected[ i ] );
127-
tol = EPS * abs( expected[ i ] );
127+
tol = 2.0 * EPS * abs( expected[ i ] );
128128
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
129129
}
130130
}
@@ -147,7 +147,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
147147
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
148148
} else {
149149
delta = abs( y - expected[ i ] );
150-
tol = EPS * abs( expected[ i ] );
150+
tol = 2.0 * EPS * abs( expected[ i ] );
151151
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
152152
}
153153
}
@@ -170,7 +170,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
170170
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
171171
} else {
172172
delta = abs( y - expected[ i ] );
173-
tol = EPS * abs( expected[ i ] );
173+
tol = 2.0 * EPS * abs( expected[ i ] );
174174
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
175175
}
176176
}
@@ -193,7 +193,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
193193
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
194194
} else {
195195
delta = abs( y - expected[ i ] );
196-
tol = EPS * abs( expected[ i ] );
196+
tol = 2.0 * EPS * abs( expected[ i ] );
197197
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
198198
}
199199
}
@@ -216,7 +216,7 @@ tape( 'the function evaluates the complementary error function for `x` on the in
216216
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
217217
} else {
218218
delta = abs( y - expected[ i ] );
219-
tol = EPS * abs( expected[ i ] );
219+
tol = 2.0 * EPS * abs( expected[ i ] );
220220
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
221221
}
222222
}
@@ -225,6 +225,8 @@ tape( 'the function evaluates the complementary error function for `x` on the in
225225

226226
tape( 'the function evaluates the complementary error function for `x` on the interval `[0.8,1]`', opts, function test( t ) {
227227
var expected;
228+
var delta;
229+
var tol;
228230
var x;
229231
var y;
230232
var i;
@@ -233,13 +235,21 @@ tape( 'the function evaluates the complementary error function for `x` on the in
233235
x = smallPositive.x;
234236
for ( i = 0; i < x.length; i++ ) {
235237
y = erfc( x[i] );
236-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
238+
if ( y === expected[i] ) {
239+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
240+
} else {
241+
delta = abs( y - expected[ i ] );
242+
tol = 2.0 * EPS * abs( expected[ i ] );
243+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
244+
}
237245
}
238246
t.end();
239247
});
240248

241249
tape( 'the function evaluates the complementary error function for `x` on the interval `[-0.8,0.8]`', opts, function test( t ) {
242250
var expected;
251+
var delta;
252+
var tol;
243253
var x;
244254
var y;
245255
var i;
@@ -248,13 +258,21 @@ tape( 'the function evaluates the complementary error function for `x` on the in
248258
x = smaller.x;
249259
for ( i = 0; i < x.length; i++ ) {
250260
y = erfc( x[i] );
251-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
261+
if ( y === expected[i] ) {
262+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
263+
} else {
264+
delta = abs( y - expected[ i ] );
265+
tol = 2.0 * EPS * abs( expected[ i ] );
266+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
267+
}
252268
}
253269
t.end();
254270
});
255271

256272
tape( 'the function evaluates the complementary error function for `x` on the interval `[-1e-300,-1e-308]`', opts, function test( t ) {
257273
var expected;
274+
var delta;
275+
var tol;
258276
var x;
259277
var y;
260278
var i;
@@ -263,13 +281,21 @@ tape( 'the function evaluates the complementary error function for `x` on the in
263281
x = tinyNegative.x;
264282
for ( i = 0; i < x.length; i++ ) {
265283
y = erfc( x[i] );
266-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
284+
if ( y === expected[i] ) {
285+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
286+
} else {
287+
delta = abs( y - expected[ i ] );
288+
tol = 1.0 * EPS * abs( expected[ i ] );
289+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
290+
}
267291
}
268292
t.end();
269293
});
270294

271295
tape( 'the function evaluates the complementary error function for `x` on the interval `[1e-300,1e-308]`', opts, function test( t ) {
272296
var expected;
297+
var delta;
298+
var tol;
273299
var x;
274300
var y;
275301
var i;
@@ -278,13 +304,21 @@ tape( 'the function evaluates the complementary error function for `x` on the in
278304
x = tinyPositive.x;
279305
for ( i = 0; i < x.length; i++ ) {
280306
y = erfc( x[i] );
281-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
307+
if ( y === expected[i] ) {
308+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
309+
} else {
310+
delta = abs( y - expected[ i ] );
311+
tol = 1.0 * EPS * abs( expected[ i ] );
312+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
313+
}
282314
}
283315
t.end();
284316
});
285317

286318
tape( 'the function evaluates the complementary error function for subnormal `x`', opts, function test( t ) {
287319
var expected;
320+
var delta;
321+
var tol;
288322
var x;
289323
var y;
290324
var i;
@@ -293,7 +327,13 @@ tape( 'the function evaluates the complementary error function for subnormal `x`
293327
x = subnormal.x;
294328
for ( i = 0; i < x.length; i++ ) {
295329
y = erfc( x[i] );
296-
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
330+
if ( y === expected[i] ) {
331+
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
332+
} else {
333+
delta = abs( y - expected[ i ] );
334+
tol = 1.0 * EPS * abs( expected[ i ] );
335+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
336+
}
297337
}
298338
t.end();
299339
});

0 commit comments

Comments
 (0)