Skip to content

Commit d4a3c9c

Browse files
test: migrate math/base/special/acos to ULP-based testing
PR-URL: #11505 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #11352
1 parent c064029 commit d4a3c9c

File tree

2 files changed

+8
-56
lines changed

2 files changed

+8
-56
lines changed

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

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var randu = require( '@stdlib/random/base/randu' );
26-
var abs = require( '@stdlib/math/base/special/abs' );
26+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2727
var EPS = require( '@stdlib/constants/float64/eps' );
2828
var isPositiveZero = require( '@stdlib/assert/is-positive-zero' );
2929
var acos = require( './../lib' );
@@ -46,8 +46,6 @@ tape( 'main export is a function', function test( t ) {
4646

4747
tape( 'the function computes the arccosine', function test( t ) {
4848
var expected;
49-
var delta;
50-
var tol;
5149
var x;
5250
var y;
5351
var i;
@@ -57,21 +55,13 @@ tape( 'the function computes the arccosine', function test( t ) {
5755

5856
for ( i = 0; i < x.length; i++ ) {
5957
y = acos( 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]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
66-
}
58+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
6759
}
6860
t.end();
6961
});
7062

7163
tape( 'the function computes the arccosine (small negative numbers)', function test( t ) {
7264
var expected;
73-
var delta;
74-
var tol;
7565
var x;
7666
var y;
7767
var i;
@@ -81,21 +71,13 @@ tape( 'the function computes the arccosine (small negative numbers)', function t
8171

8272
for ( i = 0; i < x.length; i++ ) {
8373
y = acos( 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]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
90-
}
74+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
9175
}
9276
t.end();
9377
});
9478

9579
tape( 'the function computes the arccosine (small positive numbers)', function test( t ) {
9680
var expected;
97-
var delta;
98-
var tol;
9981
var x;
10082
var y;
10183
var i;
@@ -105,13 +87,7 @@ tape( 'the function computes the arccosine (small positive numbers)', function t
10587

10688
for ( i = 0; i < x.length; i++ ) {
10789
y = acos( 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]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
114-
}
90+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
11591
}
11692
t.end();
11793
});

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

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var randu = require( '@stdlib/random/base/randu' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
28-
var abs = require( '@stdlib/math/base/special/abs' );
28+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2929
var EPS = require( '@stdlib/constants/float64/eps' );
3030
var isPositiveZero = require( '@stdlib/assert/is-positive-zero' );
3131

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

5656
tape( 'the function computes the arccosine', opts, function test( t ) {
5757
var expected;
58-
var delta;
59-
var tol;
6058
var x;
6159
var y;
6260
var i;
@@ -66,21 +64,13 @@ tape( 'the function computes the arccosine', opts, function test( t ) {
6664

6765
for ( i = 0; i < x.length; i++ ) {
6866
y = acos( 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]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
75-
}
67+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
7668
}
7769
t.end();
7870
});
7971

8072
tape( 'the function computes the arccosine (small negative numbers)', opts, function test( t ) {
8173
var expected;
82-
var delta;
83-
var tol;
8474
var x;
8575
var y;
8676
var i;
@@ -90,21 +80,13 @@ tape( 'the function computes the arccosine (small negative numbers)', opts, func
9080

9181
for ( i = 0; i < x.length; i++ ) {
9282
y = acos( 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]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
99-
}
83+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
10084
}
10185
t.end();
10286
});
10387

10488
tape( 'the function computes the arccosine (small positive numbers)', opts, function test( t ) {
10589
var expected;
106-
var delta;
107-
var tol;
10890
var x;
10991
var y;
11092
var i;
@@ -114,13 +96,7 @@ tape( 'the function computes the arccosine (small positive numbers)', opts, func
11496

11597
for ( i = 0; i < x.length; i++ ) {
11698
y = acos( 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]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
123-
}
99+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
124100
}
125101
t.end();
126102
});

0 commit comments

Comments
 (0)