From 717ed66609900223bceb2ddde8d4dd2f4d1bba43 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 06:23:45 +0000 Subject: [PATCH] test: migrate `stats/vartest` to ULP-based assertions Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01KocjgCMG1pBSHfwYA2NQhR --- 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 --- --- .../@stdlib/stats/vartest/test/test.js | 61 +++++-------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/vartest/test/test.js b/lib/node_modules/@stdlib/stats/vartest/test/test.js index c2fb0c7d2cfc..222639e3dc06 100644 --- a/lib/node_modules/@stdlib/stats/vartest/test/test.js +++ b/lib/node_modules/@stdlib/stats/vartest/test/test.js @@ -21,10 +21,9 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var contains = require( '@stdlib/assert/contains' ); -var abs = require( '@stdlib/math/base/special/abs' ); var PINF = require( '@stdlib/constants/float64/pinf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var vartest = require( './../lib' ); @@ -155,9 +154,7 @@ tape( 'the function throws an error if the `alpha` option is a numeric value out tape( 'the function by default performs a two-sample F-test', function test( t ) { var expected; - var delta; var out; - var tol; var a; var b; @@ -167,33 +164,23 @@ tape( 'the function by default performs a two-sample F-test', function test( t ) // Tested against R: expected = twosided.pValue; - delta = abs( out.pValue - expected ); - tol = 250.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. pValue: '+out.pValue+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 253 ), true, 'returns expected value' ); expected = twosided.statistic; - delta = abs( out.statistic - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 1 ), true, 'returns expected value' ); expected = twosided.lower; - delta = abs( out.ci[0] - expected ); - tol = 5.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[0], expected, 8 ), true, 'returns expected value' ); expected = twosided.upper; - delta = abs( out.ci[1] - expected ); - tol = 10.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[1], expected, 9 ), true, 'returns expected value' ); t.end(); }); tape( 'the function performs a two-sample F-test assuming the true ratio of the population variances being equal to the value of the `ratio` option', function test( t ) { var expected; - var delta; var out; - var tol; var a; var b; @@ -207,28 +194,20 @@ tape( 'the function performs a two-sample F-test assuming the true ratio of the t.strictEqual( out.pValue, diff.pValue, 'returns correct p-value' ); expected = diff.statistic; - delta = abs( out.statistic - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 1 ), true, 'returns expected value' ); expected = diff.lower; - delta = abs( out.ci[0] - expected ); - tol = 6.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[0], expected, 8 ), true, 'returns expected value' ); expected = diff.upper; - delta = abs( out.ci[1] - expected ); - tol = 12.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[1], expected, 9 ), true, 'returns expected value' ); t.end(); }); tape( 'the function performs a one-sided two-sample F-test', function test( t ) { var expected; - var delta; var out; - var tol; var a; var b; @@ -240,21 +219,15 @@ tape( 'the function performs a one-sided two-sample F-test', function test( t ) // Tested against R: expected = less.pValue; - delta = abs( out.pValue - expected ); - tol = 5.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. direction: less. a: ['+a+']. b: ['+b+']. pValue: '+out.pValue+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 4 ), true, 'returns expected value' ); expected = less.statistic; - delta = abs( out.statistic - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. direction: less. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 1 ), true, 'returns expected value' ); t.strictEqual( out.ci[0], 0.0, 'returns 0 as lower bound of CI' ); expected = less.upper; - delta = abs( out.ci[1] - expected ); - tol = 5.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. direction: less. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[1], expected, 8 ), true, 'returns expected value' ); out = vartest( a, b, { 'alternative': 'greater' @@ -262,19 +235,13 @@ tape( 'the function performs a one-sided two-sample F-test', function test( t ) // Tested against R: expected = greater.pValue; - delta = abs( out.pValue - expected ); - tol = 250.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. direction: greater. a: ['+a+']. b: ['+b+']. pValue: '+out.pValue+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 253 ), true, 'returns expected value' ); expected = greater.statistic; - delta = abs( out.statistic - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. direction: greater. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 1 ), true, 'returns expected value' ); expected = greater.lower; - delta = abs( out.ci[0] - expected ); - tol = 1.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. direction: greater. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[0], expected, 1 ), true, 'returns expected value' ); t.strictEqual( out.ci[1], PINF, 'returns Infinity as upper bound of CI' );