From 0825182dcdc2ba85a0c6d7716a86166d96c63d81 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 16 Oct 2026 14:31:40 +0000 Subject: [PATCH] test: migrate `stats/pcorrtest` to ULP-based assertions Replace computed relative tolerance comparisons with `@stdlib/assert/is-almost-same-value` checks using the minimum required ULP bounds, as measured over the existing R fixtures. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01ViMiodafCBgA7gPyrVsJ4p --- .../@stdlib/stats/pcorrtest/test/test.js | 45 +++++-------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/pcorrtest/test/test.js b/lib/node_modules/@stdlib/stats/pcorrtest/test/test.js index 6946282330b2..953ea2fa45b3 100644 --- a/lib/node_modules/@stdlib/stats/pcorrtest/test/test.js +++ b/lib/node_modules/@stdlib/stats/pcorrtest/test/test.js @@ -21,9 +21,8 @@ // 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 EPS = require( '@stdlib/constants/float64/eps' ); var pcorrtest = require( './../lib' ); @@ -177,9 +176,7 @@ tape( 'the function throws an error if provided arrays with less than four obser tape( 'the function by default performs a two-sided t-test for the Pearson correlation between paired samples', function test( t ) { var expected; - var delta; var out; - var tol; var i; var x; var y; @@ -190,29 +187,21 @@ tape( 'the function by default performs a two-sided t-test for the Pearson corre // Tested against R: expected = twosided.pValue; - delta = abs( out.pValue - expected ); - tol = 1e-6 * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 167809046 ), true, 'returns expected value' ); expected = twosided.statistic; - delta = abs( out.statistic - expected ); - tol = 10.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); expected = twosided.ci; for ( i = 0; i < 2; i++ ) { - delta = abs( out.ci[ i ] - expected[ i ]); - tol = 20.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. CI['+i+']: '+out.ci[ i ]+'. E: '+expected[ i ]+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[ i ], expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function performs a one-sided t-test for the Pearson correlation between paired samples (when alternative is `less`)', function test( t ) { var expected; - var delta; var out; - var tol; var i; var x; var y; @@ -225,29 +214,21 @@ tape( 'the function performs a one-sided t-test for the Pearson correlation betw // Tested against R: expected = less.pValue; - delta = abs( out.pValue - expected ); - tol = 100 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' ); expected = less.statistic; - delta = abs( out.statistic - expected ); - tol = 10.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); expected = less.ci; for ( i = 0; i < 2; i++ ) { - delta = abs( out.ci[ i ] - expected[ i ]); - tol = 10.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. CI['+i+']: '+out.ci[ i ]+'. E: '+expected[ i ]+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[ i ], expected[ i ], 3 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function performs a one-sided t-test for the Pearson correlation between paired samples (when alternative is `greater`)', function test( t ) { var expected; - var delta; var out; - var tol; var i; var x; var y; @@ -260,20 +241,14 @@ tape( 'the function performs a one-sided t-test for the Pearson correlation betw // Tested against R: expected = greater.pValue; - delta = abs( out.pValue - expected ); - tol = 100 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' ); expected = greater.statistic; - delta = abs( out.statistic - expected ); - tol = 10.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 2 ), true, 'returns expected value' ); expected = greater.ci; for ( i = 0; i < 2; i++ ) { - delta = abs( out.ci[ i ] - expected[ i ]); - tol = 10.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. CI['+i+']: '+out.ci[ i ]+'. E: '+expected[ i ]+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.ci[ i ], expected[ i ], 3 ), true, 'returns expected value' ); } t.end(); });