Skip to content

Commit 87b7d3d

Browse files
test: migrate math/base/special/cosh to use ULP based testing
PR-URL: #11285 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 9394280 commit 87b7d3d

2 files changed

Lines changed: 8 additions & 58 deletions

File tree

lib/node_modules/@stdlib/math/base/special/cosh/test/test.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var PINF = require( '@stdlib/constants/float64/pinf' );
2626
var NINF = require( '@stdlib/constants/float64/ninf' );
27-
var EPS = require( '@stdlib/constants/float64/eps' );
28-
var abs = require( '@stdlib/math/base/special/abs' );
27+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2928
var cosh = require( './../lib' );
3029

3130

@@ -46,8 +45,6 @@ tape( 'main export is a function', function test( t ) {
4645

4746
tape( 'the function computes the hyperbolic cosine', function test( t ) {
4847
var expected;
49-
var delta;
50-
var tol;
5148
var x;
5249
var y;
5350
var i;
@@ -57,21 +54,13 @@ tape( 'the function computes the hyperbolic cosine', function test( t ) {
5754

5855
for ( i = 0; i < x.length; i++ ) {
5956
y = cosh( x[i] );
60-
if ( y === expected[ i ] ) {
61-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
62-
} else {
63-
delta = abs( y - expected[i] );
64-
tol = EPS * abs( expected[i] );
65-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
66-
}
57+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
6758
}
6859
t.end();
6960
});
7061

7162
tape( 'the function computes the hyperbolic cosine (tiny values)', function test( t ) {
7263
var expected;
73-
var delta;
74-
var tol;
7564
var x;
7665
var y;
7766
var i;
@@ -81,21 +70,13 @@ tape( 'the function computes the hyperbolic cosine (tiny values)', function test
8170

8271
for ( i = 0; i < x.length; i++ ) {
8372
y = cosh( x[i] );
84-
if ( y === expected[ i ] ) {
85-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
86-
} else {
87-
delta = abs( y - expected[i] );
88-
tol = EPS * abs( expected[i] );
89-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
90-
}
73+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
9174
}
9275
t.end();
9376
});
9477

9578
tape( 'the function computes the hyperbolic cosine (large values)', function test( t ) {
9679
var expected;
97-
var delta;
98-
var tol;
9980
var x;
10081
var y;
10182
var i;
@@ -105,13 +86,7 @@ tape( 'the function computes the hyperbolic cosine (large values)', function tes
10586

10687
for ( i = 0; i < x.length; i++ ) {
10788
y = cosh( x[i] );
108-
if ( y === expected[ i ] ) {
109-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
110-
} else {
111-
delta = abs( y - expected[i] );
112-
tol = EPS * abs( expected[i] );
113-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
114-
}
89+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
11590
}
11691
t.end();
11792
});

lib/node_modules/@stdlib/math/base/special/cosh/test/test.native.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var PINF = require( '@stdlib/constants/float64/pinf' );
2727
var NINF = require( '@stdlib/constants/float64/ninf' );
28-
var EPS = require( '@stdlib/constants/float64/eps' );
29-
var abs = require( '@stdlib/math/base/special/abs' );
28+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
3029
var tryRequire = require( '@stdlib/utils/try-require' );
3130

3231

@@ -55,8 +54,6 @@ tape( 'main export is a function', opts, function test( t ) {
5554

5655
tape( 'the function computes the hyperbolic cosine', opts, function test( t ) {
5756
var expected;
58-
var delta;
59-
var tol;
6057
var x;
6158
var y;
6259
var i;
@@ -66,21 +63,13 @@ tape( 'the function computes the hyperbolic cosine', opts, function test( t ) {
6663

6764
for ( i = 0; i < x.length; i++ ) {
6865
y = cosh( x[i] );
69-
if ( y === expected[ i ] ) {
70-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
71-
} else {
72-
delta = abs( y - expected[i] );
73-
tol = EPS * abs( expected[i] );
74-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
75-
}
66+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
7667
}
7768
t.end();
7869
});
7970

8071
tape( 'the function computes the hyperbolic cosine (tiny values)', opts, function test( t ) {
8172
var expected;
82-
var delta;
83-
var tol;
8473
var x;
8574
var y;
8675
var i;
@@ -90,21 +79,13 @@ tape( 'the function computes the hyperbolic cosine (tiny values)', opts, functio
9079

9180
for ( i = 0; i < x.length; i++ ) {
9281
y = cosh( x[i] );
93-
if ( y === expected[ i ] ) {
94-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
95-
} else {
96-
delta = abs( y - expected[i] );
97-
tol = EPS * abs( expected[i] );
98-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
99-
}
82+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
10083
}
10184
t.end();
10285
});
10386

10487
tape( 'the function computes the hyperbolic cosine (large values)', opts, function test( t ) {
10588
var expected;
106-
var delta;
107-
var tol;
10889
var x;
10990
var y;
11091
var i;
@@ -114,13 +95,7 @@ tape( 'the function computes the hyperbolic cosine (large values)', opts, functi
11495

11596
for ( i = 0; i < x.length; i++ ) {
11697
y = cosh( x[i] );
117-
if ( y === expected[ i ] ) {
118-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
119-
} else {
120-
delta = abs( y - expected[i] );
121-
tol = EPS * abs( expected[i] );
122-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
123-
}
98+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
12499
}
125100
t.end();
126101
});

0 commit comments

Comments
 (0)