From 050e11d797fa2cb3aef091188f221c339c95e45e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 14 Oct 2026 14:27:36 +0000 Subject: [PATCH] test: migrate `stats/incr/mapcorr` to ULP-based assertions Replace the relative tolerance assertions in the test suite with ULP difference assertions via `@stdlib/assert/is-almost-same-value`. In order for the fixture-based assertions to be deterministic, the simulated datasets now use a fixed PRNG seed, as is done in `stats/incr/mpcorr`. The measured minimum ULP bounds are `6716` (moving coefficient, unknown means), `1623` (moving coefficient, known means), `1` and `0` (accumulated coefficient, unknown and known means, respectively), and `1` (NaN propagation). Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01ECS7suxhHt53frTb9zwh3T --- 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/mapcorr/test/test.js | 60 +++---------------- 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mapcorr/test/test.js b/lib/node_modules/@stdlib/stats/incr/mapcorr/test/test.js index 118da31bfa13..1f3665805e63 100644 --- a/lib/node_modules/@stdlib/stats/incr/mapcorr/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/mapcorr/test/test.js @@ -21,12 +21,12 @@ // 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 incrmapcorr = require( './../lib' ); @@ -329,12 +329,10 @@ tape( 'the function returns an accumulator function (known means)', function tes tape( 'the accumulator function computes a moving sample absolute 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; @@ -344,7 +342,7 @@ tape( 'the accumulator function computes a moving sample absolute Pearson produc N = 10; M = 100; - data = datasets( N, M, randu.seed ); + data = datasets( N, M, 123456 ); // Define the window size: W = 10; @@ -363,13 +361,7 @@ tape( 'the accumulator function computes a moving sample absolute Pearson produc } means = mean( [ 0.0, 0.0 ], arr ); expected = apcorr( 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, 6716 ), true, 'returns expected value' ); } } t.end(); @@ -379,11 +371,9 @@ tape( 'the accumulator function computes a moving sample absolute Pearson produc var expected; var actual; var means; - var delta; var data; var acc; var arr; - var tol; var d; var N; var M; @@ -393,7 +383,7 @@ tape( 'the accumulator function computes a moving sample absolute Pearson produc N = 10; M = 100; - data = datasets( N, M, randu.seed ); + data = datasets( N, M, 123456 ); // Define the window size: W = 10; @@ -411,13 +401,7 @@ tape( 'the accumulator function computes a moving sample absolute Pearson produc arr = d.slice( j-W+1, j+1 ); } expected = apcorr( 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, 1623 ), true, 'returns expected value' ); } } t.end(); @@ -427,9 +411,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; @@ -458,13 +440,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr } means = mean( [ 0.0, 0.0 ], d ); expected = apcorr( d, means[ 0 ], means[ 1 ], false ); - 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, 1 ), true, 'returns expected value' ); } t.end(); }); @@ -473,9 +449,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; @@ -504,13 +478,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr d = data.slice( i-W+1, i+1 ); } expected = apcorr( 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(); }); @@ -569,10 +537,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; @@ -631,12 +597,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 ], 1 ), true, 'returns expected value' ); t.strictEqual( acc(), v, 'returns expected value for window '+i ); } } @@ -672,12 +634,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 ], 1 ), true, 'returns expected value' ); t.strictEqual( acc(), v, 'returns expected value for window '+i ); } }