From 1ce764589d53140038b4996c67ded8752d5bde9f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 6 Aug 2026 21:22:28 +0000 Subject: [PATCH] test: migrate `math/base/special/besselj1` to ULP-based testing Replaces relative-tolerance comparisons (delta <= EPS * multiplier) with isAlmostSameValue ULP-difference assertions, using the minimum ULP bound required to pass each fixture set. Resolves a part of #11352 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: skipped - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/besselj1/test/test.js | 113 ++---------------- .../base/special/besselj1/test/test.native.js | 113 ++---------------- 2 files changed, 24 insertions(+), 202 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js b/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js index 0b03f5afac1b..4ed4092ca44b 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js @@ -25,8 +25,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var randu = require( '@stdlib/random/base/randu' ); 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 j1 = require( './../lib' ); @@ -55,8 +54,6 @@ tape( 'main export is a function', function test( t ) { tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (very large positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -65,21 +62,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = veryLargePositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 600.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 885 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (large positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -88,21 +77,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = largePositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 300.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 302 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (medium positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -111,21 +92,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = mediumPositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 2600.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2870 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (small positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -134,21 +107,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = smallPositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 5.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 8 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (small negative values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -157,21 +122,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = smallNegative.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 5.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 8 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates Bessel function of the first kind of order one (J_1) (smaller positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -180,21 +137,13 @@ tape( 'the function evaluates Bessel function of the first kind of order one (J_ x = smaller.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 3.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 5 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (tiny positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -203,21 +152,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = tinyPositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (subnormal values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -226,21 +167,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = subnormal.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 5.0e-324; - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (huge positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -249,21 +182,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = hugePositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 3000.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 4054 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) for positive x over a wide range of magnitudes', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -272,21 +197,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = positiveGamut.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 18.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 31 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) for negative x over a wide range of magnitudes', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -295,13 +212,7 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = negativeGamut.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 18.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 31 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.native.js index 720cf46f180c..bd66432e13bc 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.native.js @@ -26,8 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var randu = require( '@stdlib/random/base/randu' ); 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 tryRequire = require( '@stdlib/utils/try-require' ); @@ -64,8 +63,6 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (very large positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -74,21 +71,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = veryLargePositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 600.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 885 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (large positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -97,21 +86,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = largePositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 300.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 302 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (medium positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -120,21 +101,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = mediumPositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 2600.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2870 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (small positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -143,21 +116,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = smallPositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 5.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 8 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (small negative values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -166,21 +131,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = smallNegative.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 5.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 8 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates Bessel function of the first kind of order one (J_1) (smaller positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -189,21 +146,13 @@ tape( 'the function evaluates Bessel function of the first kind of order one (J_ x = smaller.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 3.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 5 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (tiny positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -212,21 +161,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = tinyPositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (subnormal values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -235,21 +176,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = subnormal.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 5.0e-324; - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) (huge positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -258,21 +191,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = hugePositive.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 3000.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 4054 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) for positive x over a wide range of magnitudes', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -281,21 +206,13 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = positiveGamut.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 18.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 31 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the first kind of order one (J_1) for negative x over a wide range of magnitudes', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -304,13 +221,7 @@ tape( 'the function evaluates the Bessel function of the first kind of order one x = negativeGamut.x; for ( i = 0; i < x.length; i++ ) { y = j1( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 18.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 31 ), true, 'returns expected value' ); } t.end(); });