diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js index a34ee6a73e4f..f99144438e62 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js @@ -24,11 +24,36 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var cscal = require( './../lib/cscal.js' ); +// VARIABLES // + +var ULP = 5; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference +*/ +function isApprox( t, actual, expected, ulp ) { + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); + } +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -44,12 +69,9 @@ tape( 'the function has an arity of 4', function test( t ) { tape( 'the function scales elements from `x` by `alpha`', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.3, // 1 @@ -76,26 +98,15 @@ tape( 'the function scales elements from `x` by `alpha`', function test( t ) { 0.14, // 4 0.08 // 4 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); tape( 'the function supports specifying a `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 1 @@ -130,26 +141,15 @@ tape( 'the function supports specifying a `x` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); tape( 'the function supports specifying a negative `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 3 @@ -184,15 +184,7 @@ tape( 'the function supports specifying a negative `x` stride', function test( t 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); @@ -233,13 +225,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports view offsets', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var cx0; var cx1; - var k; // Initial arrays... cx0 = new Complex64Array([ @@ -274,14 +263,6 @@ tape( 'the function supports view offsets', function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js index 2efd7a94c0a2..8267b9ba6577 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js @@ -24,11 +24,36 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var cscal = require( './../lib/ndarray.js' ); +// VARIABLES // + +var ULP = 5; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference +*/ +function isApprox( t, actual, expected, ulp ) { + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); + } +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -44,12 +69,9 @@ tape( 'the function has an arity of 5', function test( t ) { tape( 'the function scales elements from `x` by `alpha`', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.3, // 1 @@ -84,26 +106,15 @@ tape( 'the function scales elements from `x` by `alpha`', function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); tape( 'the function supports specifying a `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 1 @@ -138,26 +149,15 @@ tape( 'the function supports specifying a `x` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); tape( 'the function supports specifying a negative `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 3 @@ -192,26 +192,15 @@ tape( 'the function supports specifying a negative `x` stride', function test( t 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); tape( 'the function supports a `x` offset', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, @@ -246,15 +235,7 @@ tape( 'the function supports a `x` offset', function test( t ) { 4.2, // 3 -4.1 // 3 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); }); @@ -295,12 +276,9 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports complex access patterns', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, @@ -339,14 +317,6 @@ tape( 'the function supports complex access patterns', function test( t ) { 2.9, // 2 -0.2 // 2 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, ULP ); t.end(); });