From f68162e2709e5a57cd58bb6510ac93999094486c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Aug 2026 02:25:53 +0000 Subject: [PATCH] test: migrate `math/base/special/coversin` to ULP-based assertions Migrate the relative tolerance test cases to ULP difference testing via `@stdlib/assert/is-almost-same-value`, as proposed in the tracking issue. Both the JavaScript and C implementations match the Julia fixtures exactly across all 24000 values, so the minimum required ULP value is zero. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_014wMuenVCso7e5Sw1pvi4Aj --- .../math/base/special/coversin/test/test.js | 63 +++---------------- .../base/special/coversin/test/test.native.js | 63 +++---------------- 2 files changed, 14 insertions(+), 112 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/coversin/test/test.js b/lib/node_modules/@stdlib/math/base/special/coversin/test/test.js index 42d14af0ac18..7667c1e08cb1 100644 --- a/lib/node_modules/@stdlib/math/base/special/coversin/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/coversin/test/test.js @@ -21,11 +21,10 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); var coversin = require( './../lib' ); @@ -49,8 +48,6 @@ tape( 'main export is a function', function test( t ) { tape( 'the function computes the coversine (for -256*pi < x < 0)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -60,21 +57,13 @@ tape( 'the function computes the coversine (for -256*pi < x < 0)', function test for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for 0 < x < 256*pi)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -84,21 +73,13 @@ tape( 'the function computes the coversine (for 0 < x < 256*pi)', function test( for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for -2**60 (pi/2) < x < -2**20 (pi/2))', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -108,21 +89,13 @@ tape( 'the function computes the coversine (for -2**60 (pi/2) < x < -2**20 (pi/2 for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for 2**20 (pi/2) < x < 2**60 (pi/2))', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -132,21 +105,13 @@ tape( 'the function computes the coversine (for 2**20 (pi/2) < x < 2**60 (pi/2)) for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for x <= -2**60 (PI/2))', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -156,21 +121,13 @@ tape( 'the function computes the coversine (for x <= -2**60 (PI/2))', function t for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for x >= 2**60 (PI/2))', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -180,13 +137,7 @@ tape( 'the function computes the coversine (for x >= 2**60 (PI/2))', function te for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/coversin/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/coversin/test/test.native.js index 7c03682b9a28..00a20912d6a8 100644 --- a/lib/node_modules/@stdlib/math/base/special/coversin/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/coversin/test/test.native.js @@ -22,11 +22,10 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -58,8 +57,6 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'the function computes the coversine (for -256*pi < x < 0)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -69,21 +66,13 @@ tape( 'the function computes the coversine (for -256*pi < x < 0)', opts, functio for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 2.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for 0 < x < 256*pi)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -93,21 +82,13 @@ tape( 'the function computes the coversine (for 0 < x < 256*pi)', opts, function for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 4.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for -2**60 (pi/2) < x < -2**20 (pi/2))', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -117,21 +98,13 @@ tape( 'the function computes the coversine (for -2**60 (pi/2) < x < -2**20 (pi/2 for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 4.6 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for 2**20 (pi/2) < x < 2**60 (pi/2))', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -141,21 +114,13 @@ tape( 'the function computes the coversine (for 2**20 (pi/2) < x < 2**60 (pi/2)) for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 1.7 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for x <= -2**60 (PI/2))', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -165,21 +130,13 @@ tape( 'the function computes the coversine (for x <= -2**60 (PI/2))', opts, func for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 2.3 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the coversine (for x >= 2**60 (PI/2))', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -189,13 +146,7 @@ tape( 'the function computes the coversine (for x >= 2**60 (PI/2))', opts, funct for ( i = 0; i < x.length; i++ ) { y = coversin( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 3.6 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); });