From 15cee6232eabec94fdc1469f99dc2f6530b5dba8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 25 Sep 2026 09:14:16 +0000 Subject: [PATCH] test: migrate `stats/base/dists/bradford/variance` to ULP-based assertions Replace relative tolerance comparisons with `isAlmostSameValue` ULP-based assertions, tightened to the minimum ULP bound that still passes across the full fixture set. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_011jtHegiyumowZHcu4H1ofX --- 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 --- --- .../base/dists/bradford/variance/test/test.js | 37 +++++-------------- .../bradford/variance/test/test.native.js | 37 +++++-------------- 2 files changed, 20 insertions(+), 54 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.js index 699332b3574a..048937b8f680 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/dists/bradford/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 NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var variance = require( './../lib' ); @@ -65,38 +64,28 @@ tape( 'if provided `c <= 0`, the function returns `NaN`', function test( t ) { tape( 'the function returns the variance of a Bradford distribution given small parameter `c`', function test( t ) { var expected; - var delta; - var tol; var i; var c; var y; expected = smallC.expected; c = smallC.c; + + /* + * NOTE: the ULP bound is set high in this case due to: + * + * 1. The shape parameter being very small which causes differences in the `ln` calculations when compared to the test fixtures by SciPy. + * 2. The expected values being very small. + */ for ( i = 0; i < expected.length; i++ ) { y = variance( c[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - - /* - * NOTE: the tolerance is set high in this case due to: - * - * 1. The shape parameter being very small which causes differences in the `ln` calculations when compared to the test fixtures by SciPy. - * 2. The expected values being very small. - */ - tol = 643.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 856 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function returns the variance of a Bradford distribution given large parameter `c`', function test( t ) { var expected; - var delta; - var tol; var i; var c; var y; @@ -105,13 +94,7 @@ tape( 'the function returns the variance of a Bradford distribution given large c = largeC.c; for ( i = 0; i < expected.length; i++ ) { y = variance( c[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 15.2 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 20 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.native.js index 7995823c63fd..f252ccee3b27 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.native.js @@ -22,10 +22,9 @@ 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 abs = require( '@stdlib/math/base/special/abs' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -74,38 +73,28 @@ tape( 'if provided `c <= 0`, the function returns `NaN`', opts, function test( t tape( 'the function returns the variance of a Bradford distribution given small parameter `c`', opts, function test( t ) { var expected; - var delta; - var tol; var i; var c; var y; expected = smallC.expected; c = smallC.c; + + /* + * NOTE: the ULP bound is set high in this case due to: + * + * 1. The shape parameter being very small which causes differences in the `ln` calculations when compared to the test fixtures by SciPy. + * 2. The expected values being very small. + */ for ( i = 0; i < expected.length; i++ ) { y = variance( c[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - - /* - * NOTE: the tolerance is set high in this case due to: - * - * 1. The shape parameter being very small which causes differences in the `ln` calculations when compared to the test fixtures by SciPy. - * 2. The expected values being very small. - */ - tol = 643.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 856 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function returns the variance of a Bradford distribution given large parameter `c`', opts, function test( t ) { var expected; - var delta; - var tol; var i; var c; var y; @@ -114,13 +103,7 @@ tape( 'the function returns the variance of a Bradford distribution given large c = largeC.c; for ( i = 0; i < expected.length; i++ ) { y = variance( c[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'c: '+c[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. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 20 ), true, 'returns expected value' ); } t.end(); });