Skip to content

Commit 82ee225

Browse files
authored
test: migrate blas/base/wasm/csrot to ULP-based assertions
PR-URL: #15871 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #11352
1 parent 8c05bc6 commit 82ee225

4 files changed

Lines changed: 66 additions & 102 deletions

File tree

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
var tape = require( 'tape' );
2424
var Float32Array = require( '@stdlib/array/float32' );
2525
var Complex64Array = require( '@stdlib/array/complex64' );
26-
var EPS = require( '@stdlib/constants/float32/eps' );
27-
var abs = require( '@stdlib/math/base/special/abs' );
26+
var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
2827
var csrot = require( './../lib' );
2928

3029

@@ -37,22 +36,14 @@ var csrot = require( './../lib' );
3736
* @param {Object} t - test object
3837
* @param {Collection} actual - actual values
3938
* @param {Collection} expected - expected values
40-
* @param {number} rtol - relative tolerance
39+
* @param {NonNegativeInteger} ulp - maximum allowed ULP difference
4140
*/
42-
function isApprox( t, actual, expected, rtol ) {
43-
var delta;
44-
var tol;
41+
function isApprox( t, actual, expected, ulp ) {
4542
var i;
4643

4744
t.strictEqual( actual.length, expected.length, 'returns expected value' );
4845
for ( i = 0; i < expected.length; i++ ) {
49-
if ( actual[ i ] === expected[ i ] ) {
50-
t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' );
51-
} else {
52-
delta = abs( actual[ i ] - expected[ i ] );
53-
tol = rtol * EPS * abs( expected[ i ] );
54-
t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' );
55-
}
46+
t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' );
5647
}
5748
}
5849

@@ -125,8 +116,8 @@ tape( 'the `main` method applies a plane rotation', function test( t ) {
125116
]);
126117

127118
out = csrot.main( cx.length, cx, 1, cy, 1, 0.8, 0.6 );
128-
isApprox( t, viewX, cxe, 2.0 );
129-
isApprox( t, viewY, cye, 2.0 );
119+
isApprox( t, viewX, cxe, 0 );
120+
isApprox( t, viewY, cye, 1 );
130121
t.strictEqual( out, cy, 'returns expected value' );
131122
t.end();
132123
});
@@ -186,8 +177,8 @@ tape( 'the `main` method supports an `x` stride', function test( t ) {
186177
]);
187178

188179
out = csrot.main( 2, cx, 2, cy, 1, 0.8, 0.6 );
189-
isApprox( t, viewX, cxe, 2.0 );
190-
isApprox( t, viewY, cye, 2.0 );
180+
isApprox( t, viewX, cxe, 0 );
181+
isApprox( t, viewY, cye, 1 );
191182
t.strictEqual( out, cy, 'returns expected value' );
192183
t.end();
193184
});
@@ -247,8 +238,8 @@ tape( 'the `main` method supports a `y` stride', function test( t ) {
247238
]);
248239

249240
out = csrot.main( 2, cx, 1, cy, 2, 0.8, 0.6 );
250-
isApprox( t, viewX, cxe, 2.0 );
251-
isApprox( t, viewY, cye, 2.0 );
241+
isApprox( t, viewX, cxe, 0 );
242+
isApprox( t, viewY, cye, 1 );
252243
t.strictEqual( out, cy, 'returns expected value' );
253244
t.end();
254245
});
@@ -350,8 +341,8 @@ tape( 'the `main` method supports negative strides', function test( t ) {
350341
]);
351342

352343
out = csrot.main( 2, cx, -1, cy, -2, 0.8, 0.6 );
353-
isApprox( t, viewX, cxe, 2.0 );
354-
isApprox( t, viewY, cye, 2.0 );
344+
isApprox( t, viewX, cxe, 0 );
345+
isApprox( t, viewY, cye, 1 );
355346
t.strictEqual( out, cy, 'returns expected value' );
356347
t.end();
357348
});
@@ -411,8 +402,8 @@ tape( 'the `main` method supports complex access patterns', function test( t ) {
411402
]);
412403

413404
out = csrot.main( 2, cx, 2, cy, -1, 0.8, 0.6 );
414-
isApprox( t, viewX, cxe, 2.0 );
415-
isApprox( t, viewY, cye, 2.0 );
405+
isApprox( t, viewX, cxe, 0 );
406+
isApprox( t, viewY, cye, 1 );
416407
t.strictEqual( out, cy, 'returns expected value' );
417408
t.end();
418409
});
@@ -479,8 +470,8 @@ tape( 'the `main` method supports view offsets', function test( t ) {
479470
]);
480471

481472
out = csrot.main( 2, cx1, -2, cy1, 1, 0.8, 0.6 );
482-
isApprox( t, viewX, cxe, 2.0 );
483-
isApprox( t, viewY, cye, 2.0 );
473+
isApprox( t, viewX, cxe, 0 );
474+
isApprox( t, viewY, cye, 1 );
484475
t.strictEqual( out, cy1, 'returns expected value' );
485476
t.end();
486477
});

‎lib/node_modules/@stdlib/blas/base/wasm/csrot/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 Float32Array = require( '@stdlib/array/float32' );
2828
var Complex64Array = require( '@stdlib/array/complex64' );
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 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( isAlmostSameValuef( 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 Complex64Array( 4 );
113104
mod.read( cxp, actualX );
114105
viewX = new Float32Array( actualX.buffer );
115-
isApprox( t, viewX, cxe, 2.0 );
106+
isApprox( t, viewX, cxe, 0 );
116107

117108
actualY = new Complex64Array( 4 );
118109
mod.read( cyp, actualY );
119110
viewY = new Float32Array( actualY.buffer );
120-
isApprox( t, viewY, cye, 2.0 );
111+
isApprox( t, viewY, cye, 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 Complex64Array( 4 );
200191
mod.read( cxp, actualX );
201192
viewX = new Float32Array( actualX.buffer );
202-
isApprox( t, viewX, cxe, 2.0 );
193+
isApprox( t, viewX, cxe, 0 );
203194

204195
actualY = new Complex64Array( 4 );
205196
mod.read( cyp, actualY );
206197
viewY = new Float32Array( actualY.buffer );
207-
isApprox( t, viewY, cye, 2.0 );
198+
isApprox( t, viewY, cye, 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 Complex64Array( 4 );
287278
mod.read( cxp, actualX );
288279
viewX = new Float32Array( actualX.buffer );
289-
isApprox( t, viewX, cxe, 2.0 );
280+
isApprox( t, viewX, cxe, 0 );
290281

291282
actualY = new Complex64Array( 4 );
292283
mod.read( cyp, actualY );
293284
viewY = new Float32Array( actualY.buffer );
294-
isApprox( t, viewY, cye, 2.0 );
285+
isApprox( t, viewY, cye, 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 Complex64Array( 4 );
449440
mod.read( cxp, actualX );
450441
viewX = new Float32Array( actualX.buffer );
451-
isApprox( t, viewX, cxe, 2.0 );
442+
isApprox( t, viewX, cxe, 0 );
452443

453444
actualY = new Complex64Array( 4 );
454445
mod.read( cyp, actualY );
455446
viewY = new Float32Array( actualY.buffer );
456-
isApprox( t, viewY, cye, 2.0 );
447+
isApprox( t, viewY, cye, 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 Complex64Array( 4 );
536527
mod.read( cxp, actualX );
537528
viewX = new Float32Array( actualX.buffer );
538-
isApprox( t, viewX, cxe, 2.0 );
529+
isApprox( t, viewX, cxe, 0 );
539530

540531
actualY = new Complex64Array( 4 );
541532
mod.read( cyp, actualY );
542533
viewY = new Float32Array( actualY.buffer );
543-
isApprox( t, viewY, cye, 2.0 );
534+
isApprox( t, viewY, cye, 1 );
544535

545536
t.end();
546537
});

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

Lines changed: 18 additions & 27 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 Float32Array = require( '@stdlib/array/float32' );
2828
var Complex64Array = require( '@stdlib/array/complex64' );
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 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( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' );
5950
}
6051
}
6152

@@ -112,12 +103,12 @@ tape( 'a module instance has an `ndarray` method which applies a plane rotation'
112103
actualX = new Complex64Array( 4 );
113104
mod.read( cxp, actualX );
114105
viewX = new Float32Array( actualX.buffer );
115-
isApprox( t, viewX, cxe, 2.0 );
106+
isApprox( t, viewX, cxe, 0 );
116107

117108
actualY = new Complex64Array( 4 );
118109
mod.read( cyp, actualY );
119110
viewY = new Float32Array( actualY.buffer );
120-
isApprox( t, viewY, cye, 2.0 );
111+
isApprox( t, viewY, cye, 1 );
121112

122113
t.end();
123114
});
@@ -199,12 +190,12 @@ tape( 'a module instance has an `ndarray` method which supports an `x` stride',
199190
actualX = new Complex64Array( 4 );
200191
mod.read( cxp, actualX );
201192
viewX = new Float32Array( actualX.buffer );
202-
isApprox( t, viewX, cxe, 2.0 );
193+
isApprox( t, viewX, cxe, 0 );
203194

204195
actualY = new Complex64Array( 4 );
205196
mod.read( cyp, actualY );
206197
viewY = new Float32Array( actualY.buffer );
207-
isApprox( t, viewY, cye, 2.0 );
198+
isApprox( t, viewY, cye, 1 );
208199

209200
t.end();
210201
});
@@ -286,12 +277,12 @@ tape( 'a module instance has an `ndarray` method which supports an `x` offset',
286277
actualX = new Complex64Array( 4 );
287278
mod.read( cxp, actualX );
288279
viewX = new Float32Array( actualX.buffer );
289-
isApprox( t, viewX, cxe, 2.0 );
280+
isApprox( t, viewX, cxe, 0 );
290281

291282
actualY = new Complex64Array( 4 );
292283
mod.read( cyp, actualY );
293284
viewY = new Float32Array( actualY.buffer );
294-
isApprox( t, viewY, cye, 2.0 );
285+
isApprox( t, viewY, cye, 1 );
295286

296287
t.end();
297288
});
@@ -373,12 +364,12 @@ tape( 'a module instance has an `ndarray` method which supports a `y` stride', f
373364
actualX = new Complex64Array( 4 );
374365
mod.read( cxp, actualX );
375366
viewX = new Float32Array( actualX.buffer );
376-
isApprox( t, viewX, cxe, 2.0 );
367+
isApprox( t, viewX, cxe, 0 );
377368

378369
actualY = new Complex64Array( 4 );
379370
mod.read( cyp, actualY );
380371
viewY = new Float32Array( actualY.buffer );
381-
isApprox( t, viewY, cye, 2.0 );
372+
isApprox( t, viewY, cye, 1 );
382373

383374
t.end();
384375
});
@@ -460,12 +451,12 @@ tape( 'a module instance has an `ndarray` method which supports a `y` offset', f
460451
actualX = new Complex64Array( 4 );
461452
mod.read( cxp, actualX );
462453
viewX = new Float32Array( actualX.buffer );
463-
isApprox( t, viewX, cxe, 2.0 );
454+
isApprox( t, viewX, cxe, 0 );
464455

465456
actualY = new Complex64Array( 4 );
466457
mod.read( cyp, actualY );
467458
viewY = new Float32Array( actualY.buffer );
468-
isApprox( t, viewY, cye, 2.0 );
459+
isApprox( t, viewY, cye, 1 );
469460

470461
t.end();
471462
});
@@ -622,12 +613,12 @@ tape( 'a module instance has an `ndarray` method which supports negative strides
622613
actualX = new Complex64Array( 4 );
623614
mod.read( cxp, actualX );
624615
viewX = new Float32Array( actualX.buffer );
625-
isApprox( t, viewX, cxe, 2.0 );
616+
isApprox( t, viewX, cxe, 0 );
626617

627618
actualY = new Complex64Array( 4 );
628619
mod.read( cyp, actualY );
629620
viewY = new Float32Array( actualY.buffer );
630-
isApprox( t, viewY, cye, 2.0 );
621+
isApprox( t, viewY, cye, 1 );
631622

632623
t.end();
633624
});
@@ -709,12 +700,12 @@ tape( 'a module instance has an `ndarray` method which supports complex access p
709700
actualX = new Complex64Array( 4 );
710701
mod.read( cxp, actualX );
711702
viewX = new Float32Array( actualX.buffer );
712-
isApprox( t, viewX, cxe, 2.0 );
703+
isApprox( t, viewX, cxe, 0 );
713704

714705
actualY = new Complex64Array( 4 );
715706
mod.read( cyp, actualY );
716707
viewY = new Float32Array( actualY.buffer );
717-
isApprox( t, viewY, cye, 2.0 );
708+
isApprox( t, viewY, cye, 1 );
718709

719710
t.end();
720711
});

0 commit comments

Comments
 (0)