From 8982ef9ab7aa9a49ff5ee1febb03e852783760a8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 18 Sep 2026 18:13:11 +0000 Subject: [PATCH] test: migrate `stats/kde2d` to ULP-based assertions Replace relative tolerance assertions in the `stats/kde2d` tests with ULP-based assertions using `@stdlib/assert/is-almost-same-value`. ULP bounds were tightened to the measured minimum which passes over the full fixture set. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_012oJYd2qY2kvRKBr7pDJbkz --- .../@stdlib/stats/kde2d/test/test.js | 81 +++---------------- 1 file changed, 10 insertions(+), 71 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/kde2d/test/test.js b/lib/node_modules/@stdlib/stats/kde2d/test/test.js index ccc349cd0685..27af7aad6a9f 100644 --- a/lib/node_modules/@stdlib/stats/kde2d/test/test.js +++ b/lib/node_modules/@stdlib/stats/kde2d/test/test.js @@ -21,8 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var kde2d = require( './../lib' ); var dataX = require( './fixtures/r/datax.json' ); @@ -235,8 +234,6 @@ tape( 'the function computes the same values with `ndarray` and numeric array in tape( 'the function correctly computes 2 dimensional normal KDE for a small dataset', function test( t ) { var actual; - var delta; - var tol; var i; var j; @@ -244,36 +241,18 @@ tape( 'the function correctly computes 2 dimensional normal KDE for a small data // Check x for ( i = 0; i < actual.x.length; i++ ) { - if ( actual.x[i] === expectedSmall.x[i] ) { - t.strictEqual( actual.x[i], expectedSmall.x[i], 'x: '+actual.x[i]+', expected: '+expectedSmall.x[i] ); - } else { - delta = abs( actual.x[i] - expectedSmall.x[ i ] ); - tol = 200.0 * EPS * abs( expectedSmall.x[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+actual.x[ i ]+'. E: '+expectedSmall.x[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.x[ i ], expectedSmall.x[ i ], 0 ), true, 'returns expected value' ); } // Check y for ( i = 0; i < actual.y.length; i++ ) { - if ( actual.y[i] === expectedSmall.y[i] ) { - t.strictEqual( actual.y[i], expectedSmall.y[i], 'x: '+actual.y[i]+', expected: '+expectedSmall.y[i] ); - } else { - delta = abs( actual.y[i] - expectedSmall.y[ i ] ); - tol = 200.0 * EPS * abs( expectedSmall.y[ i ] ); - t.ok( delta <= tol, 'within tolerance. y: '+actual.y[ i ]+'. E: '+expectedSmall.y[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.y[ i ], expectedSmall.y[ i ], 0 ), true, 'returns expected value' ); } // Check z for ( i = 0; i < actual.x.length; i++ ) { for ( j = 0; j < actual.y.length; j++ ) { - if ( actual.z.get(i, j) === expectedSmall.z[i][j] ) { - t.strictEqual( actual.z.get(i, j), expectedSmall.z[i][j], 'z: '+actual.z.get(i, j)+', expected: '+expectedSmall.z[i][j] ); - } else { - delta = abs( actual.z.get(i, j) - expectedSmall.z[i][j] ); - tol = 1500.0 * EPS * abs( expectedSmall.z[i][j] ); - t.ok( delta <= tol, 'within tolerance. z: '+actual.z.get(i, j)+'. E: '+expectedSmall.z[i][j]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.z.get( i, j ), expectedSmall.z[ i ][ j ], 4 ), true, 'returns expected value' ); } } @@ -282,8 +261,6 @@ tape( 'the function correctly computes 2 dimensional normal KDE for a small data tape( 'the function correctly computes 2 dimensional normal KDE for a medium dataset', function test( t ) { var actual; - var delta; - var tol; var i; var j; @@ -291,36 +268,18 @@ tape( 'the function correctly computes 2 dimensional normal KDE for a medium dat // Check x for ( i = 0; i < actual.x.length; i++ ) { - if ( actual.x[i] === expected.x[i] ) { - t.strictEqual( actual.x[i], expected.x[i], 'x: '+actual.x[i]+', expected: '+expected.x[i] ); - } else { - delta = abs( actual.x[i] - expected.x[ i ] ); - tol = 500.0 * EPS * abs( expected.x[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+actual.x[ i ]+'. E: '+expected.x[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.x[ i ], expected.x[ i ], 0 ), true, 'returns expected value' ); } // Check y for ( i = 0; i < actual.y.length; i++ ) { - if ( actual.y[i] === expected.y[i] ) { - t.strictEqual( actual.y[i], expected.y[i], 'x: '+actual.y[i]+', expected: '+expected.y[i] ); - } else { - delta = abs( actual.y[i] - expected.y[ i ] ); - tol = 200.0 * EPS * abs( expected.y[ i ] ); - t.ok( delta <= tol, 'within tolerance. y: '+actual.y[ i ]+'. E: '+expected.y[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.y[ i ], expected.y[ i ], 0 ), true, 'returns expected value' ); } // Check z for ( i = 0; i < actual.x.length; i++ ) { for ( j = 0; j < actual.y.length; j++ ) { - if ( actual.z.get(i, j) === expected.z[i][j] ) { - t.strictEqual( actual.z.get(i, j), expected.z[i][j], 'z: '+actual.z.get(i, j)+', expected: '+expected.z[i][j] ); - } else { - delta = abs( actual.z.get(i, j) - expected.z[i][j] ); - tol = 2000.0 * EPS * abs( expected.z[i][j] ); - t.ok( delta <= tol, 'within tolerance. z: '+actual.z.get(i, j)+'. E: '+expected.z[i][j]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.z.get( i, j ), expected.z[ i ][ j ], 28 ), true, 'returns expected value' ); } } @@ -329,8 +288,6 @@ tape( 'the function correctly computes 2 dimensional normal KDE for a medium dat tape( 'the function correctly computes 2 dimensional normal KDE for a large dataset', function test( t ) { var actual; - var delta; - var tol; var i; var j; @@ -338,36 +295,18 @@ tape( 'the function correctly computes 2 dimensional normal KDE for a large data // Check x for ( i = 0; i < actual.x.length; i++ ) { - if ( actual.x[i] === expected2.x[i] ) { - t.strictEqual( actual.x[i], expected2.x[i], 'x: '+actual.x[i]+', expected2: '+expected2.x[i] ); - } else { - delta = abs( actual.x[i] - expected2.x[ i ] ); - tol = 250.0 * EPS * abs( expected2.x[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+actual.x[ i ]+'. E: '+expected2.x[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.x[ i ], expected2.x[ i ], 0 ), true, 'returns expected value' ); } // Check y for ( i = 0; i < actual.y.length; i++ ) { - if ( actual.y[i] === expected2.y[i] ) { - t.strictEqual( actual.y[i], expected2.y[i], 'x: '+actual.y[i]+', expected2: '+expected2.y[i] ); - } else { - delta = abs( actual.y[i] - expected2.y[ i ] ); - tol = 500.0 * EPS * abs( expected2.y[ i ] ); - t.ok( delta <= tol, 'within tolerance. y: '+actual.y[ i ]+'. E: '+expected2.y[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.y[ i ], expected2.y[ i ], 0 ), true, 'returns expected value' ); } // Check z for ( i = 0; i < actual.x.length; i++ ) { for ( j = 0; j < actual.y.length; j++ ) { - if ( actual.z.get(i, j) === expected2.z[i][j] ) { - t.strictEqual( actual.z.get(i, j), expected2.z[i][j], 'z: '+actual.z.get(i, j)+', expected2: '+expected2.z[i][j] ); - } else { - delta = abs( actual.z.get(i, j) - expected2.z[i][j] ); - tol = 2000.0 * EPS * abs( expected2.z[i][j] ); - t.ok( delta <= tol, 'within tolerance. z: '+actual.z.get(i, j)+'. E: '+expected2.z[i][j]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual.z.get( i, j ), expected2.z[ i ][ j ], 17 ), true, 'returns expected value' ); } }