From 9f3d61cb01bb18c8f8e031eb356001ca32090e28 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 5 Aug 2026 10:23:11 +0000 Subject: [PATCH 1/2] test: migrate `math/base/special/ellipk` to ULP-based assertions Migrate the fixture-based tests from relative tolerance testing to ULP difference testing using `@stdlib/assert/is-almost-same-value`. The ULP bounds are the measured minimum over each full fixture set and are identical for the JavaScript and native implementations. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_014DdacVDaTqzaNwnp2NRFn7 --- .../math/base/special/ellipk/test/test.js | 47 ++++--------------- .../base/special/ellipk/test/test.native.js | 47 ++++--------------- 2 files changed, 18 insertions(+), 76 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js index 698eccfedda2..b188c25bec23 100644 --- a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js @@ -21,12 +21,11 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var HALF_PI = require( '@stdlib/constants/float64/half-pi' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); var ellipk = require( './../lib' ); @@ -48,92 +47,64 @@ tape( 'main export is a function', function test( t ) { tape( 'the function evaluates the complete elliptic integral of the first kind (medium positive values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = mediumPositive.expected; x = mediumPositive.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 25.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(); }); tape( 'the function evaluates the complete elliptic integral of the first kind (values close to positive unity)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = closeToUnity.expected; x = closeToUnity.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 8000.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 ], 12065 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the complete elliptic integral of the first kind (medium negative values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = mediumNegative.expected; x = mediumNegative.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 1.5 * 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 ], 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the complete elliptic integral of the first kind (large negative values)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = largeNegative.expected; x = largeNegative.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 1e9 * 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 ], 204773163 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js index 6d0e208696f8..8333b7a775d0 100644 --- a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js @@ -22,12 +22,11 @@ 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 PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var HALF_PI = require( '@stdlib/constants/float64/half-pi' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -57,92 +56,64 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'the function evaluates the complete elliptic integral of the first kind (medium positive values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = mediumPositive.expected; x = mediumPositive.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 25.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(); }); tape( 'the function evaluates the complete elliptic integral of the first kind (values close to positive unity)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = closeToUnity.expected; x = closeToUnity.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 8000.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 ], 12065 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the complete elliptic integral of the first kind (medium negative values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = mediumNegative.expected; x = mediumNegative.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 1.5 * 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 ], 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the complete elliptic integral of the first kind (large negative values)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; expected = largeNegative.expected; x = largeNegative.x; + for ( i = 0; i < x.length; i++ ) { y = ellipk( 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 = 1e9 * 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 ], 204773163 ), true, 'returns expected value' ); } t.end(); }); From af8d4a16887911ccfa59e8c4c87855a40ab1e9ad Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 6 Aug 2026 00:29:13 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/math/base/special/ellipk/test/test.js | 4 ++-- .../@stdlib/math/base/special/ellipk/test/test.native.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js index b188c25bec23..37a2d16e57de 100644 --- a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.js @@ -72,7 +72,7 @@ tape( 'the function evaluates the complete elliptic integral of the first kind ( for ( i = 0; i < x.length; i++ ) { y = ellipk( x[i] ); - t.strictEqual( isAlmostSameValue( y, expected[ i ], 12065 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 12065 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy } t.end(); }); @@ -104,7 +104,7 @@ tape( 'the function evaluates the complete elliptic integral of the first kind ( for ( i = 0; i < x.length; i++ ) { y = ellipk( x[i] ); - t.strictEqual( isAlmostSameValue( y, expected[ i ], 204773163 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 204773163 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js index 8333b7a775d0..de505efb136c 100644 --- a/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/ellipk/test/test.native.js @@ -81,7 +81,7 @@ tape( 'the function evaluates the complete elliptic integral of the first kind ( for ( i = 0; i < x.length; i++ ) { y = ellipk( x[i] ); - t.strictEqual( isAlmostSameValue( y, expected[ i ], 12065 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 12065 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy } t.end(); }); @@ -113,7 +113,7 @@ tape( 'the function evaluates the complete elliptic integral of the first kind ( for ( i = 0; i < x.length; i++ ) { y = ellipk( x[i] ); - t.strictEqual( isAlmostSameValue( y, expected[ i ], 204773163 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 204773163 ), true, 'returns expected value' ); // FIXME: investigate the reason for this large discrepancy } t.end(); });