From 91423cfdca5ef7d40e50e78b699d016f9b387a2c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 25 Jul 2026 09:08:17 +0000 Subject: [PATCH] test: migrate `math/base/special/tanh` to ULP-based testing Ref: https://github.com/stdlib-js/stdlib/issues/11352 --- .../math/base/special/tanh/test/test.js | 53 +++---------------- .../base/special/tanh/test/test.native.js | 53 +++---------------- 2 files changed, 12 insertions(+), 94 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/tanh/test/test.js b/lib/node_modules/@stdlib/math/base/special/tanh/test/test.js index 2ff5824f9c92..6d77a20c78cb 100644 --- a/lib/node_modules/@stdlib/math/base/special/tanh/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/tanh/test/test.js @@ -26,8 +26,7 @@ var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var tanh = require( './../lib' ); @@ -50,8 +49,6 @@ tape( 'main export is a function', function test( t ) { tape( 'the function computes the hyperbolic tangent', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -61,21 +58,13 @@ tape( 'the function computes the hyperbolic tangent', function test( t ) { for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 1.7 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (tiny negative)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -85,21 +74,13 @@ tape( 'the function computes the hyperbolic tangent (tiny negative)', function t for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (tiny positive)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -109,21 +90,13 @@ tape( 'the function computes the hyperbolic tangent (tiny positive)', function t for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (large negative)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -133,21 +106,13 @@ tape( 'the function computes the hyperbolic tangent (large negative)', function for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (large positive)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -157,13 +122,7 @@ tape( 'the function computes the hyperbolic tangent (large positive)', function for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/tanh/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/tanh/test/test.native.js index c4adb678540a..3cd5a9aaf649 100644 --- a/lib/node_modules/@stdlib/math/base/special/tanh/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/tanh/test/test.native.js @@ -28,8 +28,7 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var tryRequire = require( '@stdlib/utils/try-require' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); // FIXTURES // @@ -59,8 +58,6 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'the function computes the hyperbolic tangent', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -70,21 +67,13 @@ tape( 'the function computes the hyperbolic tangent', opts, function test( t ) { for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 1.7 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (tiny negative)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -94,21 +83,13 @@ tape( 'the function computes the hyperbolic tangent (tiny negative)', opts, func for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (tiny positive)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -118,21 +99,13 @@ tape( 'the function computes the hyperbolic tangent (tiny positive)', opts, func for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (large negative)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -142,21 +115,13 @@ tape( 'the function computes the hyperbolic tangent (large negative)', opts, fun for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); }); tape( 'the function computes the hyperbolic tangent (large positive)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -166,13 +131,7 @@ tape( 'the function computes the hyperbolic tangent (large positive)', opts, fun for ( i = 0; i < x.length; i++ ) { y = tanh( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( y, expected[ i ], 'returns expected value' ); } t.end(); });