test: migrate `blas/base/wasm/zdrot` to ULP-based assertions · stdlib-js/stdlib@f9aa9fb · GitHub
Skip to content

Commit f9aa9fb

Browse files
authored
test: migrate blas/base/wasm/zdrot to ULP-based assertions
PR-URL: #16159 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #11352
1 parent a31e89e commit f9aa9fb

4 files changed

Lines changed: 66 additions & 102 deletions

File tree

‎lib/node_modules/@stdlib/blas/base/wasm/zdrot/test/test.main.js‎

Lines changed: 16 additions & 25 deletions

‎lib/node_modules/@stdlib/blas/base/wasm/zdrot/test/test.module.main.js‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ var tape = require( 'tape' );
2626
var Memory = require( '@stdlib/wasm/memory' );
2727
var Float64Array = require( '@stdlib/array/float64' );
2828
var Complex128Array = require( '@stdlib/array/complex128' );
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 Module = require( './../lib' ).Module;
3231

3332

@@ -40,22 +39,14 @@ var Module = require( './../lib' ).Module;
4039
* @param {Object} t - test object
4140
* @param {Collection} actual - actual values
4241
* @param {Collection} expected - expected values
43-
* @param {number} rtol - relative tolerance
42+
* @param {NonNegativeInteger} ulp - maximum allowed ULP difference
4443
*/
45-
function isApprox( t, actual, expected, rtol ) {
46-
var delta;
47-
var tol;
44+
function isApprox( t, actual, expected, ulp ) {
4845
var i;
4946

5047
t.strictEqual( actual.length, expected.length, 'returns expected value' );
5148
for ( i = 0; i < expected.length; i++ ) {
52-
if ( actual[ i ] === expected[ i ] ) {
53-
t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' );
54-
} else {
55-
delta = abs( actual[ i ] - expected[ i ] );
56-
tol = rtol * EPS * abs( expected[ i ] );
57-
t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' );
58-
}
49+
t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' );
5950
}
6051
}
6152

@@ -112,12 +103,12 @@ tape( 'a module instance has a `main` method which applies a plane rotation', fu
112103
actualX = new Complex128Array( 4 );
113104
mod.read( zxp, actualX );
114105
viewX = new Float64Array( actualX.buffer );
115-
isApprox( t, viewX, zxe, 2.0 );
106+
isApprox( t, viewX, zxe, 1 );
116107

117108
actualY = new Complex128Array( 4 );
118109
mod.read( zyp, actualY );
119110
viewY = new Float64Array( actualY.buffer );
120-
isApprox( t, viewY, zye, 2.0 );
111+
isApprox( t, viewY, zye, 1 );
121112

122113
t.end();
123114
});
@@ -199,12 +190,12 @@ tape( 'a module instance has a `main` method which supports an `x` stride', func
199190
actualX = new Complex128Array( 4 );
200191
mod.read( zxp, actualX );
201192
viewX = new Float64Array( actualX.buffer );
202-
isApprox( t, viewX, zxe, 2.0 );
193+
isApprox( t, viewX, zxe, 1 );
203194

204195
actualY = new Complex128Array( 4 );
205196
mod.read( zyp, actualY );
206197
viewY = new Float64Array( actualY.buffer );
207-
isApprox( t, viewY, zye, 2.0 );
198+
isApprox( t, viewY, zye, 1 );
208199

209200
t.end();
210201
});
@@ -286,12 +277,12 @@ tape( 'a module instance has a `main` method which supports a `y` stride', funct
286277
actualX = new Complex128Array( 4 );
287278
mod.read( zxp, actualX );
288279
viewX = new Float64Array( actualX.buffer );
289-
isApprox( t, viewX, zxe, 2.0 );
280+
isApprox( t, viewX, zxe, 1 );
290281

291282
actualY = new Complex128Array( 4 );
292283
mod.read( zyp, actualY );
293284
viewY = new Float64Array( actualY.buffer );
294-
isApprox( t, viewY, zye, 2.0 );
285+
isApprox( t, viewY, zye, 1 );
295286

296287
t.end();
297288
});
@@ -448,12 +439,12 @@ tape( 'a module instance has a `main` method which supports negative strides', f
448439
actualX = new Complex128Array( 4 );
449440
mod.read( zxp, actualX );
450441
viewX = new Float64Array( actualX.buffer );
451-
isApprox( t, viewX, zxe, 2.0 );
442+
isApprox( t, viewX, zxe, 1 );
452443

453444
actualY = new Complex128Array( 4 );
454445
mod.read( zyp, actualY );
455446
viewY = new Float64Array( actualY.buffer );
456-
isApprox( t, viewY, zye, 2.0 );
447+
isApprox( t, viewY, zye, 1 );
457448

458449
t.end();
459450
});
@@ -535,12 +526,12 @@ tape( 'a module instance has a `main` method which supports complex access patte
535526
actualX = new Complex128Array( 4 );
536527
mod.read( zxp, actualX );
537528
viewX = new Float64Array( actualX.buffer );
538-
isApprox( t, viewX, zxe, 2.0 );
529+
isApprox( t, viewX, zxe, 1 );
539530

540531
actualY = new Complex128Array( 4 );
541532
mod.read( zyp, actualY );
542533
viewY = new Float64Array( actualY.buffer );
543-
isApprox( t, viewY, zye, 2.0 );
534+
isApprox( t, viewY, zye, 1 );
544535

545536
t.end();
546537
});

‎lib/node_modules/@stdlib/blas/base/wasm/zdrot/test/test.module.ndarray.js‎

Lines changed: 18 additions & 27 deletions

0 commit comments

Comments
 (0)