From 490480fbc35368a2432ec3c39fb0e8858e21dcc8 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 16 Sep 2026 22:16:42 +0000 Subject: [PATCH] test: migrate `stats/base/dists/cauchy/cdf` to ULP-based assertions Replace relative tolerance comparisons with `isAlmostSameValue` ULP difference assertions. Measured minimum ULP bounds over the full fixture sets: 1 (large gamma), 32 (`x0 < 0`), and 128 (`x0 > 0`). The native add-on was compiled locally and returns bit-identical results to the JavaScript implementation, both with and without floating-point contraction, so `test.native.js` uses the same bounds. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01DxU1LEKirAqLkJaBWboWad --- .../base/dists/cauchy/cdf/test/test.cdf.js | 33 ++-------------- .../dists/cauchy/cdf/test/test.factory.js | 33 ++-------------- .../base/dists/cauchy/cdf/test/test.native.js | 39 ++----------------- 3 files changed, 12 insertions(+), 93 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.cdf.js b/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.cdf.js index da208be61c30..3ae2d57872bd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.cdf.js +++ b/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.cdf.js @@ -22,10 +22,9 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var cdf = require( './../lib' ); @@ -95,9 +94,7 @@ tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', fu tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (large `gamma`)', function test( t ) { var expected; - var delta; var gamma; - var tol; var x0; var x; var y; @@ -109,22 +106,14 @@ tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (large `gam gamma = largeGamma.gamma; for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], x0[i], gamma[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 < 0`)', function test( t ) { var expected; - var delta; var gamma; - var tol; var x0; var x; var y; @@ -136,22 +125,14 @@ tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 < 0`)' gamma = negativeMedian.gamma; for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], x0[i], gamma[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 20.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 32 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 > 0`)', function test( t ) { var expected; - var delta; var gamma; - var tol; var x0; var x; var y; @@ -163,13 +144,7 @@ tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 > 0`)' gamma = positiveMedian.gamma; for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], x0[i], gamma[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 150.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 128 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.factory.js index b1327ce0675b..36863315f58a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.factory.js @@ -22,10 +22,9 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var factory = require( './../lib/factory.js' ); @@ -138,10 +137,8 @@ tape( 'if provided a nonpositive `gamma`, the created function always returns `N tape( 'the created function evaluates the cdf for `x` given `x0` and `gamma` (large gamma)', function test( t ) { var expected; - var delta; var gamma; var cdf; - var tol; var x0; var x; var y; @@ -154,23 +151,15 @@ tape( 'the created function evaluates the cdf for `x` given `x0` and `gamma` (la for ( i = 0; i < x.length; i++ ) { cdf = factory( x0[i], gamma[i] ); y = cdf( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the created function evaluates the cdf for `x` given `x0` and `gamma` (`x0 < 0`)', function test( t ) { var expected; - var delta; var gamma; var cdf; - var tol; var x0; var x; var y; @@ -183,23 +172,15 @@ tape( 'the created function evaluates the cdf for `x` given `x0` and `gamma` (`x for ( i = 0; i < x.length; i++ ) { cdf = factory( x0[i], gamma[i] ); y = cdf( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 20.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 32 ), true, 'returns expected value' ); } t.end(); }); tape( 'the created function evaluates the cdf for `x` given `x0` and `gamma` (`x0 > 0`)', function test( t ) { var expected; - var delta; var gamma; var cdf; - var tol; var x0; var x; var y; @@ -212,13 +193,7 @@ tape( 'the created function evaluates the cdf for `x` given `x0` and `gamma` (`x for ( i = 0; i < x.length; i++ ) { cdf = factory( x0[i], gamma[i] ); y = cdf( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 150.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 128 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.native.js index e2707c8fa0bf..b283b4175ffc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/cauchy/cdf/test/test.native.js @@ -24,10 +24,9 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var tryRequire = require( '@stdlib/utils/try-require' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); // FIXTURES // @@ -104,9 +103,7 @@ tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', op tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (large `gamma`)', opts, function test( t ) { var expected; - var delta; var gamma; - var tol; var x0; var x; var y; @@ -118,22 +115,14 @@ tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (large `gam gamma = largeGamma.gamma; for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], x0[i], gamma[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 < 0`)', opts, function test( t ) { var expected; - var delta; var gamma; - var tol; var x0; var x; var y; @@ -145,22 +134,14 @@ tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 < 0`)' gamma = negativeMedian.gamma; for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], x0[i], gamma[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 750.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 32 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 > 0`)', opts, function test( t ) { var expected; - var delta; var gamma; - var tol; var x0; var x; var y; @@ -172,19 +153,7 @@ tape( 'the function evaluates the cdf for `x` given `x0` and `gamma` (`x0 > 0`)' gamma = positiveMedian.gamma; for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], x0[i], gamma[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - /* - * Large tolerance needed to accommodate a single test case (x: -157.97952978936485, x0: 11.935806197690301, gamma: 0.006888823412234402), for which - * - the expected value is 0.00001290513644541802 - * - but the function returns 0.000012905136445441337 - * which is a difference of 2.3317e-17. - */ - tol = 8200.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 128 ), true, 'returns expected value' ); } t.end(); });