Skip to content

Commit

Permalink
test: update to test for exact equality
Browse files Browse the repository at this point in the history
PR-URL: stdlib-js#2864
Ref: stdlib-js#2039
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
aman-095 authored Sep 7, 2024
1 parent 7edbd56 commit 4ca068f
Show file tree
Hide file tree
Showing 20 changed files with 482 additions and 1,028 deletions.
69 changes: 26 additions & 43 deletions lib/node_modules/@stdlib/blas/base/dgemv/test/test.dgemv.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

var tape = require( 'tape' );
var Float64Array = require( '@stdlib/array/float64' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var dgemv = require( './../lib/dgemv.js' );


Expand All @@ -46,35 +44,6 @@ var rxnyp = require( './fixtures/row_major_xnyp.json' );
var rxpyp = require( './fixtures/row_major_xpyp.json' );


// FUNCTIONS //

/**
* Tests for element-wise approximate equality.
*
* @private
* @param {Object} t - test object
* @param {Collection} actual - actual values
* @param {Collection} expected - expected values
* @param {number} rtol - relative tolerance
*/
function isApprox( t, actual, expected, rtol ) {
var delta;
var tol;
var i;

t.strictEqual( actual.length, expected.length, 'returns expected value' );
for ( i = 0; i < expected.length; i++ ) {
if ( actual[ i ] === expected[ i ] ) {
t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' );
} else {
delta = abs( actual[ i ] - expected[ i ] );
tol = rtol * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' );
}
}
}


// TESTS //

tape( 'main export is a function', function test( t ) {
Expand Down Expand Up @@ -253,8 +222,9 @@ tape( 'the function performs one of the matrix-vector operations `y = α*A*x +
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -275,8 +245,9 @@ tape( 'the function performs one of the matrix-vector operations `y = α*A*x +
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -297,8 +268,9 @@ tape( 'the function performs one of the matrix-vector operations `y = α*A*x +
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -319,8 +291,9 @@ tape( 'the function performs one of the matrix-vector operations `y = α*A*x +
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -339,6 +312,7 @@ tape( 'the function returns a reference to the second input vector (row-major)',

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
t.strictEqual( out, y, 'returns expected value' );

t.end();
});

Expand All @@ -357,6 +331,7 @@ tape( 'the function returns a reference to the second input vector (column-major

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
t.strictEqual( out, y, 'returns expected value' );

t.end();
});

Expand Down Expand Up @@ -523,8 +498,9 @@ tape( 'the function supports specifying `x` and `y` strides (row-major)', functi
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -545,8 +521,9 @@ tape( 'the function supports specifying `x` and `y` strides (column-major)', fun
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -567,8 +544,9 @@ tape( 'the function supports specifying a negative `x` stride (row-major)', func
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -589,8 +567,9 @@ tape( 'the function supports specifying a negative `x` stride (column-major)', f
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -611,8 +590,9 @@ tape( 'the function supports specifying a negative `y` stride (row-major)', func
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -633,8 +613,9 @@ tape( 'the function supports specifying a negative `y` stride (column-major)', f
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -655,8 +636,9 @@ tape( 'the function supports complex access patterns (row-major)', function test
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

Expand All @@ -677,7 +659,8 @@ tape( 'the function supports complex access patterns (column-major)', function t
expected = new Float64Array( data.y_out );

out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY );
isApprox( t, y, expected, 2.0 );
t.strictEqual( out, y, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});
Loading

0 comments on commit 4ca068f

Please sign in to comment.