From 781389663cb9740782e04b031df74fe30bbb525f Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 18 Aug 2026 06:21:37 +0000 Subject: [PATCH] test: migrate `stats/base/dists/hypergeometric/variance` to ULP-based assertions Replace computed relative-tolerance comparisons with `isAlmostSameValue` ULP-based assertions in the fixture loops. The JavaScript and C implementations evaluate the same variance formula using different associations, so they require different bounds. The JavaScript implementation computes `n*(K/N)*((N-K)/N)*((N-n)/(N-1))`, whereas the C implementation computes `n*p*(1-p)*((N-n)/(N-1))`, the latter matching the association used by the Julia reference implementation which generated the fixtures. Bounds are the measured minima over the full fixture set: 29 ULP for test.js and 1 ULP for test.native.js. One lower fails in each case. Ref: https://github.com/stdlib-js/stdlib/issues/11352 --- .../base/dists/hypergeometric/variance/test/test.js | 13 ++----------- .../hypergeometric/variance/test/test.native.js | 13 ++----------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.js index bfdf1fe386ba..8ff9c0b139ad 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.js @@ -21,10 +21,9 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); var PINF = require( '@stdlib/constants/float64/pinf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var variance = require( './../lib' ); @@ -119,8 +118,6 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur tape( 'the function returns the variance of a hypergeometric distribution', function test( t ) { var expected; - var delta; - var tol; var N; var K; var n; @@ -133,13 +130,7 @@ tape( 'the function returns the variance of a hypergeometric distribution', func n = data.n; for ( i = 0; i < n.length; i++ ) { y = variance( N[i], K[i], n[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'N: '+N[i]+', K: '+K[i]+', n: '+n[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 18.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. N: '+N[i]+'. K: '+K[i]+'. n: '+n[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 29 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js index b4a3375fd6ee..1a6b84f0f6c2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js @@ -23,9 +23,8 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var tryRequire = require( '@stdlib/utils/try-require' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var EPS = require( '@stdlib/constants/float64/eps' ); // VARIABLES // @@ -87,8 +86,6 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur tape( 'the function returns the variance of a hypergeometric distribution', opts, function test( t ) { var expected; - var delta; - var tol; var N; var K; var n; @@ -101,13 +98,7 @@ tape( 'the function returns the variance of a hypergeometric distribution', opts n = data.n; for ( i = 0; i < n.length; i++ ) { y = variance( N[i], K[i], n[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'N: '+N[i]+', K: '+K[i]+', n: '+n[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 18.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. N: '+N[i]+'. K: '+K[i]+'. n: '+n[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); });