Skip to content

Commit 8117e16

Browse files
authored
test: migrate math/base/special/haversin to ULP-based testing
PR-URL: #12752 Reviewed-by: Athan Reines <kgryte@gmail.com> Ref: #11352
1 parent 5956601 commit 8117e16

2 files changed

Lines changed: 25 additions & 112 deletions

File tree

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

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
2625
var PINF = require( '@stdlib/constants/float64/pinf' );
2726
var NINF = require( '@stdlib/constants/float64/ninf' );
28-
var EPS = require( '@stdlib/constants/float64/eps' );
2927
var haversin = require( './../lib' );
3028

3129

@@ -49,8 +47,6 @@ tape( 'main export is a function', function test( t ) {
4947

5048
tape( 'the function computes the half-value versed sine (for -256*pi < x < 0 )', function test( t ) {
5149
var expected;
52-
var delta;
53-
var tol;
5450
var x;
5551
var y;
5652
var i;
@@ -60,22 +56,14 @@ tape( 'the function computes the half-value versed sine (for -256*pi < x < 0 )',
6056

6157
for ( i = 0; i < x.length; i++ ) {
6258
y = haversin( x[i] );
63-
if ( y === expected[ i ] ) {
64-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
65-
} else {
66-
delta = abs( y - expected[i] );
67-
tol = EPS * abs( expected[i] );
68-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
69-
}
59+
t.strictEqual( y, expected[ i ], 'returns expected value' );
7060
}
7161

7262
t.end();
7363
});
7464

7565
tape( 'the function computes the half-value versed sine (for 0 < x < 256*pi )', function test( t ) {
7666
var expected;
77-
var delta;
78-
var tol;
7967
var x;
8068
var y;
8169
var i;
@@ -85,22 +73,14 @@ tape( 'the function computes the half-value versed sine (for 0 < x < 256*pi )',
8573

8674
for ( i = 0; i < x.length; i++ ) {
8775
y = haversin( x[i] );
88-
if ( y === expected[ i ] ) {
89-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
90-
} else {
91-
delta = abs( y - expected[i] );
92-
tol = EPS * abs( expected[i] );
93-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
94-
}
76+
t.strictEqual( y, expected[ i ], 'returns expected value' );
9577
}
9678

9779
t.end();
9880
});
9981

10082
tape( 'the function computes the half-value versed sine (for -2**60 (pi/2) < x < -2**20 (pi/2) )', function test( t ) {
10183
var expected;
102-
var delta;
103-
var tol;
10484
var x;
10585
var y;
10686
var i;
@@ -110,22 +90,14 @@ tape( 'the function computes the half-value versed sine (for -2**60 (pi/2) < x <
11090

11191
for ( i = 0; i < x.length; i++ ) {
11292
y = haversin( x[i] );
113-
if ( y === expected[ i ] ) {
114-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
115-
} else {
116-
delta = abs( y - expected[i] );
117-
tol = EPS * abs( expected[i] );
118-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
119-
}
93+
t.strictEqual( y, expected[ i ], 'returns expected value' );
12094
}
12195

12296
t.end();
12397
});
12498

12599
tape( 'the function computes the half-value versed sine (for 2**20 (pi/2) < x < 2**60 (pi/2) )', function test( t ) {
126100
var expected;
127-
var delta;
128-
var tol;
129101
var x;
130102
var y;
131103
var i;
@@ -135,22 +107,14 @@ tape( 'the function computes the half-value versed sine (for 2**20 (pi/2) < x <
135107

136108
for ( i = 0; i < x.length; i++ ) {
137109
y = haversin( x[i] );
138-
if ( y === expected[ i ] ) {
139-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
140-
} else {
141-
delta = abs( y - expected[i] );
142-
tol = EPS * abs( expected[i] );
143-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
144-
}
110+
t.strictEqual( y, expected[ i ], 'returns expected value' );
145111
}
146112

147113
t.end();
148114
});
149115

150116
tape( 'the function computes the half-value versed sine (for x <= -2**60 (PI/2) )', function test( t ) {
151117
var expected;
152-
var delta;
153-
var tol;
154118
var x;
155119
var y;
156120
var i;
@@ -160,22 +124,14 @@ tape( 'the function computes the half-value versed sine (for x <= -2**60 (PI/2)
160124

161125
for ( i = 0; i < x.length; i++ ) {
162126
y = haversin( x[i] );
163-
if ( y === expected[ i ] ) {
164-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
165-
} else {
166-
delta = abs( y - expected[i] );
167-
tol = EPS * abs( expected[i] );
168-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
169-
}
127+
t.strictEqual( y, expected[ i ], 'returns expected value' );
170128
}
171129

172130
t.end();
173131
});
174132

175133
tape( 'the function computes the half-value versed sine (for x >= 2**60 (PI/2) )', function test( t ) {
176134
var expected;
177-
var delta;
178-
var tol;
179135
var x;
180136
var y;
181137
var i;
@@ -185,13 +141,7 @@ tape( 'the function computes the half-value versed sine (for x >= 2**60 (PI/2) )
185141

186142
for ( i = 0; i < x.length; i++ ) {
187143
y = haversin( x[i] );
188-
if ( y === expected[ i ] ) {
189-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
190-
} else {
191-
delta = abs( y - expected[i] );
192-
tol = EPS * abs( expected[i] );
193-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
194-
}
144+
t.strictEqual( y, expected[ i ], 'returns expected value' );
195145
}
196146

197147
t.end();

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

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var abs = require( '@stdlib/math/base/special/abs' );
2726
var PINF = require( '@stdlib/constants/float64/pinf' );
2827
var NINF = require( '@stdlib/constants/float64/ninf' );
29-
var EPS = require( '@stdlib/constants/float64/eps' );
28+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
3029
var tryRequire = require( '@stdlib/utils/try-require' );
3130

3231

@@ -58,8 +57,6 @@ tape( 'main export is a function', opts, function test( t ) {
5857

5958
tape( 'the function computes the half-value versed sine (for -256*pi < x < 0 )', opts, function test( t ) {
6059
var expected;
61-
var delta;
62-
var tol;
6360
var x;
6461
var y;
6562
var i;
@@ -69,22 +66,16 @@ tape( 'the function computes the half-value versed sine (for -256*pi < x < 0 )',
6966

7067
for ( i = 0; i < x.length; i++ ) {
7168
y = haversin( x[i] );
72-
if ( y === expected[ i ] ) {
73-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
74-
} else {
75-
delta = abs( y - expected[i] );
76-
tol = 1.7 * EPS * abs( expected[i] );
77-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
78-
}
69+
70+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
71+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' );
7972
}
8073

8174
t.end();
8275
});
8376

8477
tape( 'the function computes the half-value versed sine (for 0 < x < 256*pi )', opts, function test( t ) {
8578
var expected;
86-
var delta;
87-
var tol;
8879
var x;
8980
var y;
9081
var i;
@@ -94,22 +85,16 @@ tape( 'the function computes the half-value versed sine (for 0 < x < 256*pi )',
9485

9586
for ( i = 0; i < x.length; i++ ) {
9687
y = haversin( x[i] );
97-
if ( y === expected[ i ] ) {
98-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
99-
} else {
100-
delta = abs( y - expected[i] );
101-
tol = 1.7 * EPS * abs( expected[i] );
102-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
103-
}
88+
89+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
90+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' );
10491
}
10592

10693
t.end();
10794
});
10895

10996
tape( 'the function computes the half-value versed sine (for -2**60 (pi/2) < x < -2**20 (pi/2) )', opts, function test( t ) {
11097
var expected;
111-
var delta;
112-
var tol;
11398
var x;
11499
var y;
115100
var i;
@@ -119,22 +104,16 @@ tape( 'the function computes the half-value versed sine (for -2**60 (pi/2) < x <
119104

120105
for ( i = 0; i < x.length; i++ ) {
121106
y = haversin( x[i] );
122-
if ( y === expected[ i ] ) {
123-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
124-
} else {
125-
delta = abs( y - expected[i] );
126-
tol = 1.7 * EPS * abs( expected[i] );
127-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
128-
}
107+
108+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
109+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' );
129110
}
130111

131112
t.end();
132113
});
133114

134115
tape( 'the function computes the half-value versed sine (for 2**20 (pi/2) < x < 2**60 (pi/2) )', opts, function test( t ) {
135116
var expected;
136-
var delta;
137-
var tol;
138117
var x;
139118
var y;
140119
var i;
@@ -144,22 +123,16 @@ tape( 'the function computes the half-value versed sine (for 2**20 (pi/2) < x <
144123

145124
for ( i = 0; i < x.length; i++ ) {
146125
y = haversin( x[i] );
147-
if ( y === expected[ i ] ) {
148-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
149-
} else {
150-
delta = abs( y - expected[i] );
151-
tol = 1.7 * EPS * abs( expected[i] );
152-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
153-
}
126+
127+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
128+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' );
154129
}
155130

156131
t.end();
157132
});
158133

159134
tape( 'the function computes the half-value versed sine (for x <= -2**60 (PI/2) )', opts, function test( t ) {
160135
var expected;
161-
var delta;
162-
var tol;
163136
var x;
164137
var y;
165138
var i;
@@ -169,22 +142,16 @@ tape( 'the function computes the half-value versed sine (for x <= -2**60 (PI/2)
169142

170143
for ( i = 0; i < x.length; i++ ) {
171144
y = haversin( x[i] );
172-
if ( y === expected[ i ] ) {
173-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
174-
} else {
175-
delta = abs( y - expected[i] );
176-
tol = 1.7 * EPS * abs( expected[i] );
177-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
178-
}
145+
146+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
147+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' );
179148
}
180149

181150
t.end();
182151
});
183152

184153
tape( 'the function computes the half-value versed sine (for x >= 2**60 (PI/2) )', opts, function test( t ) {
185154
var expected;
186-
var delta;
187-
var tol;
188155
var x;
189156
var y;
190157
var i;
@@ -194,13 +161,9 @@ tape( 'the function computes the half-value versed sine (for x >= 2**60 (PI/2) )
194161

195162
for ( i = 0; i < x.length; i++ ) {
196163
y = haversin( x[i] );
197-
if ( y === expected[ i ] ) {
198-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
199-
} else {
200-
delta = abs( y - expected[i] );
201-
tol = 1.7 * EPS * abs( expected[i] );
202-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. Expected: '+expected[i]+'. tol: '+tol+'. delta: '+delta+'.' );
203-
}
164+
165+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
166+
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' );
204167
}
205168

206169
t.end();

0 commit comments

Comments
 (0)