From 94faa5da63bf22964df3bb75d2baed1092d14b8c Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 27 Sep 2026 06:36:26 +0000 Subject: [PATCH] test: migrate `stats/incr/mpcorr2` to ULP-based assertions Migrate the tests for `stats/incr/mpcorr2` from relative tolerance testing to ULP difference testing. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_0115kn1XuFqPA3zGnm3S2J8U --- 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/incr/mpcorr2/test/test.js | 57 +++---------------- 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mpcorr2/test/test.js b/lib/node_modules/@stdlib/stats/incr/mpcorr2/test/test.js index ceaea3e9e355..64380a71eb9f 100644 --- a/lib/node_modules/@stdlib/stats/incr/mpcorr2/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/mpcorr2/test/test.js @@ -21,12 +21,11 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var randu = require( '@stdlib/random/base/randu' ); -var abs = require( '@stdlib/math/base/special/abs' ); var pow = require( '@stdlib/math/base/special/pow' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var zeros = require( '@stdlib/array/base/zeros' ); var incrmpcorr2 = require( './../lib' ); @@ -331,12 +330,10 @@ tape( 'the function returns an accumulator function (known means)', function tes tape( 'the accumulator function computes a moving squared sample Pearson product-moment correlation coefficient incrementally', function test( t ) { var expected; var actual; - var delta; var means; var data; var acc; var arr; - var tol; var d; var N; var M; @@ -365,13 +362,7 @@ tape( 'the accumulator function computes a moving squared sample Pearson product } means = mean( [ 0.0, 0.0 ], arr ); expected = pcorr2( arr, means[ 0 ], means[ 1 ], false ); - if ( actual === expected ) { - t.strictEqual( actual, expected, 'returns expected value. dataset: '+i+'. window: '+j+'.' ); - } else { - delta = abs( actual - expected ); - tol = 5.0e5 * EPS * abs( expected ); - t.strictEqual( delta < tol, true, 'dataset: '+i+'. window: '+j+'. expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( actual, expected, 10425 ), true, 'returns expected value' ); } } t.end(); @@ -381,11 +372,9 @@ tape( 'the accumulator function computes a moving squared sample Pearson product var expected; var actual; var means; - var delta; var data; var acc; var arr; - var tol; var d; var N; var M; @@ -413,13 +402,7 @@ tape( 'the accumulator function computes a moving squared sample Pearson product arr = d.slice( j-W+1, j+1 ); } expected = pcorr2( arr, means[ 0 ], means[ 1 ], true ); - if ( actual === expected ) { - t.strictEqual( actual, expected, 'returns expected value. dataset: '+i+'. window: '+j+'.' ); - } else { - delta = abs( actual - expected ); - tol = 5.0e5 * EPS * abs( expected ); - t.strictEqual( delta < tol, true, 'dataset: '+i+'. window: '+j+'. expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( actual, expected, 3415 ), true, 'returns expected value' ); } } t.end(); @@ -429,9 +412,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr var expected; var actual; var means; - var delta; var data; - var tol; var acc; var W; var N; @@ -460,13 +441,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr } means = mean( [ 0.0, 0.0 ], d ); expected = pcorr2( d, means[ 0 ], means[ 1 ], false ); - if ( actual === expected ) { - t.strictEqual( actual, expected, 'returns expected value. window: '+i+'.' ); - } else { - delta = abs( actual - expected ); - tol = 2.0 * EPS * abs( expected ); - t.strictEqual( delta < tol, true, 'window: '+i+'. expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( actual, expected, 2 ), true, 'returns expected value' ); } t.end(); }); @@ -475,9 +450,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr var expected; var actual; var means; - var delta; var data; - var tol; var acc; var W; var N; @@ -506,13 +479,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr d = data.slice( i-W+1, i+1 ); } expected = pcorr2( d, means[ 0 ], means[ 1 ], true ); - if ( actual === expected ) { - t.strictEqual( actual, expected, 'returns expected value. window: '+i+'.' ); - } else { - delta = abs( actual - expected ); - tol = 1.0 * EPS * abs( expected ); - t.strictEqual( delta < tol, true, 'window: '+i+'. expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( actual, expected, 0 ), true, 'returns expected value' ); } t.end(); }); @@ -571,10 +538,8 @@ tape( 'if the window size is `1` and the means are known, the accumulator functi tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invocations (unknown means)', function test( t ) { var expected; - var delta; var data; var acc; - var tol; var v; var i; @@ -633,12 +598,8 @@ tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invoca if ( isnan( expected[ i ] ) ) { t.strictEqual( isnan( v ), true, 'returns expected value for window '+i ); t.strictEqual( isnan( acc() ), true, 'returns expected value for window '+i ); - } else if ( v === expected[ i ] ) { - t.strictEqual( v, expected[ i ], 'returns expected value for window: '+i ); } else { - delta = abs( v - expected[ i ] ); - tol = EPS * abs( expected[ i ] ); - t.strictEqual( delta <= tol, true, 'window: '+i+'. expected: '+expected[ i ]+'. actual: '+v+'. tol: '+tol+'. delta: '+delta+'.' ); + t.strictEqual( isAlmostSameValue( v, expected[ i ], 2 ), true, 'returns expected value' ); t.strictEqual( acc(), v, 'returns expected value for window '+i ); } } @@ -674,12 +635,8 @@ tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invoca if ( isnan( expected[ i ] ) ) { t.strictEqual( isnan( v ), true, 'returns expected value for window '+i ); t.strictEqual( isnan( acc() ), true, 'returns expected value for window '+i ); - } else if ( v === expected[ i ] ) { - t.strictEqual( v, expected[ i ], 'returns expected value for window: '+i ); } else { - delta = abs( v - expected[ i ] ); - tol = EPS * abs( expected[ i ] ); - t.strictEqual( delta <= tol, true, 'window: '+i+'. expected: '+expected[ i ]+'. actual: '+v+'. tol: '+tol+'. delta: '+delta+'.' ); + t.strictEqual( isAlmostSameValue( v, expected[ i ], 2 ), true, 'returns expected value' ); t.strictEqual( acc(), v, 'returns expected value for window '+i ); } }