From fce8e318b2025b2e8966d27497a826e1dccbe0f0 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 10:26:29 +0000 Subject: [PATCH] test: migrate `math/base/special/bessely0` to ULP-based assertions Ref: https://github.com/stdlib-js/stdlib/issues/11352 --- .../math/base/special/bessely0/test/test.js | 92 ++-------------- .../base/special/bessely0/test/test.native.js | 100 +++--------------- 2 files changed, 24 insertions(+), 168 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js b/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js index c96d7a646cd1..15dcb2a27fb9 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js @@ -21,12 +21,12 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); 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 y0 = require( './../lib' ); @@ -53,8 +53,6 @@ tape( 'main export is a function', function test( t ) { tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (very large positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -63,21 +61,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = veryLargePositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 680.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 ], 1127 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (large positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -86,21 +76,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = largePositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 2400.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 ], 3716 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (medium positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -109,21 +91,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = mediumPositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 850.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 ], 1626 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (small positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -132,21 +106,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = smallPositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 1000.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 ], 1510 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates Bessel function of the second kind of zero order (Y_0) (smaller positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -155,21 +121,13 @@ tape( 'the function evaluates Bessel function of the second kind of zero order ( x = smaller.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 4.5 * 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 ], 7 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (tiny positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -178,21 +136,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = tinyPositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 10.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 ], 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (subnormal positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -201,21 +151,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = subnormal.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 5000.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 ], 8678 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (huge positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -224,21 +166,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = hugePositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 4500.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 ], 4053 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of order zero (Y_0) for positive x over a wide range of magnitudes', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -247,13 +181,7 @@ tape( 'the function evaluates the Bessel function of the second kind of order ze x = positiveGamut.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 16.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 ], 25 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.native.js index e42f9c03b6a3..842cc40a7de6 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.native.js @@ -22,12 +22,12 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); 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 tryRequire = require( '@stdlib/utils/try-require' ); @@ -62,8 +62,6 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (very large positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -72,21 +70,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = veryLargePositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 680.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 ], 1127 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (large positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -95,21 +85,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = largePositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 2400.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 ], 3716 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (medium positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -118,23 +100,15 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = mediumPositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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] ); - - // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2774#discussion_r1712904184 - tol = 885.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2774#discussion_r1712904184 + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1693 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (small positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -143,21 +117,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = smallPositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 1000.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 ], 1510 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates Bessel function of the second kind of zero order (Y_0) (smaller positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -166,21 +132,13 @@ tape( 'the function evaluates Bessel function of the second kind of zero order ( x = smaller.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 4.5 * 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 ], 7 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (tiny positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -189,21 +147,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = tinyPositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 10.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 ], 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (subnormal positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -212,21 +162,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = subnormal.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 5000.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 ], 8678 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of zero order (Y_0) (huge positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -235,21 +177,13 @@ tape( 'the function evaluates the Bessel function of the second kind of zero ord x = hugePositive.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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 = 4500.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 ], 4053 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the Bessel function of the second kind of order zero (Y_0) 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; @@ -258,15 +192,9 @@ tape( 'the function evaluates the Bessel function of the second kind of order ze x = positiveGamut.x; for ( i = 0; i < x.length; i++ ) { y = y0( 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] ); - - // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2774#discussion_r1712904184 - tol = 130.0 * EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2774#discussion_r1712904184 + t.strictEqual( isAlmostSameValue( y, expected[ i ], 203 ), true, 'returns expected value' ); } t.end(); });