Skip to content

Commit 121f2c0

Browse files
authored
test: migrate math/base/special/hyp2f1 to ULP-based testing
PR-URL: #11297 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent e47ee45 commit 121f2c0

File tree

2 files changed

+14
-74
lines changed

2 files changed

+14
-74
lines changed

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

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24-
var abs = require( '@stdlib/math/base/special/abs' );
2524
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26-
var EPS = require( '@stdlib/constants/float64/eps' );
2725
var PINF = require( '@stdlib/constants/float64/pinf' );
26+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2827
var hyp2f1 = require( './../lib' );
2928

3029

@@ -111,8 +110,6 @@ tape( 'the function returns `PINF` when `c <= a + b`, `x === 1`, and neither `a`
111110

112111
tape( 'the function correctly evaluates the hypergeometric function', function test( t ) {
113112
var expected;
114-
var delta;
115-
var tol;
116113
var a;
117114
var b;
118115
var c;
@@ -132,17 +129,13 @@ tape( 'the function correctly evaluates the hypergeometric function', function t
132129
t.strictEqual( v, PINF, 'returns expected value' );
133130
continue;
134131
}
135-
delta = abs( v - expected[ i ] );
136-
tol = EPS * abs( expected[ i ] );
137-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
132+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' );
138133
}
139134
t.end();
140135
});
141136

142137
tape( 'the function correctly evaluates the hypergeometric function', function test( t ) {
143138
var expected;
144-
var delta;
145-
var tol;
146139
var a;
147140
var b;
148141
var c;
@@ -162,17 +155,13 @@ tape( 'the function correctly evaluates the hypergeometric function', function t
162155
t.strictEqual( v, PINF, 'returns expected value' );
163156
continue;
164157
}
165-
delta = abs( v - expected[ i ] );
166-
tol = EPS * abs( expected[ i ] );
167-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
158+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' );
168159
}
169160
t.end();
170161
});
171162

172163
tape( 'the function correctly evaluates the hypergeometric function', function test( t ) {
173164
var expected;
174-
var delta;
175-
var tol;
176165
var a;
177166
var b;
178167
var c;
@@ -192,17 +181,13 @@ tape( 'the function correctly evaluates the hypergeometric function', function t
192181
t.strictEqual( v, PINF, 'returns expected value' );
193182
continue;
194183
}
195-
delta = abs( v - expected[ i ] );
196-
tol = 7.0 * EPS * abs( expected[ i ] );
197-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
184+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 7 ), true, 'returns expected value' );
198185
}
199186
t.end();
200187
});
201188

202189
tape( 'the function correctly evaluates the hypergeometric function', function test( t ) {
203190
var expected;
204-
var delta;
205-
var tol;
206191
var a;
207192
var b;
208193
var c;
@@ -222,17 +207,13 @@ tape( 'the function correctly evaluates the hypergeometric function', function t
222207
t.strictEqual( v, PINF, 'returns expected value' );
223208
continue;
224209
}
225-
delta = abs( v - expected[ i ] );
226-
tol = 10.0 * EPS * abs( expected[ i ] );
227-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
210+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 18 ), true, 'returns expected value' );
228211
}
229212
t.end();
230213
});
231214

232215
tape( 'the function correctly evaluates the hypergeometric function', function test( t ) {
233216
var expected;
234-
var delta;
235-
var tol;
236217
var a;
237218
var b;
238219
var c;
@@ -252,17 +233,13 @@ tape( 'the function correctly evaluates the hypergeometric function', function t
252233
t.strictEqual( v, PINF, 'returns expected value' );
253234
continue;
254235
}
255-
delta = abs( v - expected[ i ] );
256-
tol = 17.0 * EPS * abs( expected[ i ] );
257-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
236+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 33 ), true, 'returns expected value' );
258237
}
259238
t.end();
260239
});
261240

262241
tape( 'the function correctly evaluates the hypergeometric function', function test( t ) {
263242
var expected;
264-
var delta;
265-
var tol;
266243
var a;
267244
var b;
268245
var c;
@@ -278,16 +255,14 @@ tape( 'the function correctly evaluates the hypergeometric function', function t
278255

279256
for ( i = 0; i < x.length; i++ ) {
280257
v = hyp2f1( a[ i ], b[ i ], c[ i ], x[ i ] );
281-
delta = abs( v - expected[ i ] );
282258

283259
/*
284260
* NOTE: the tolerance is set high in this case due to:
285261
*
286262
* 1. The expected values having a very large range, being either very small or very large.
287263
* 2. The function making a large number of internal calls, leading to accumulated numerical errors.
288264
*/
289-
tol = 260000.0 * EPS * abs( expected[ i ] );
290-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
265+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 294333 ), true, 'returns expected value' );
291266
}
292267
t.end();
293268
});

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

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
2625
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27-
var EPS = require( '@stdlib/constants/float64/eps' );
2826
var PINF = require( '@stdlib/constants/float64/pinf' );
27+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
3029

3130

@@ -123,8 +122,6 @@ tape( 'the function returns `PINF` when `c <= a + b`, `x === 1`, and neither `a`
123122

124123
tape( 'the function correctly evaluates the hypergeometric function', opts, function test( t ) {
125124
var expected;
126-
var delta;
127-
var tol;
128125
var a;
129126
var b;
130127
var c;
@@ -144,17 +141,13 @@ tape( 'the function correctly evaluates the hypergeometric function', opts, func
144141
t.strictEqual( v, PINF, 'returns expected value' );
145142
continue;
146143
}
147-
delta = abs( v - expected[ i ] );
148-
tol = EPS * abs( expected[ i ] );
149-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
144+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' );
150145
}
151146
t.end();
152147
});
153148

154149
tape( 'the function correctly evaluates the hypergeometric function', opts, function test( t ) {
155150
var expected;
156-
var delta;
157-
var tol;
158151
var a;
159152
var b;
160153
var c;
@@ -174,19 +167,13 @@ tape( 'the function correctly evaluates the hypergeometric function', opts, func
174167
t.strictEqual( v, PINF, 'returns expected value' );
175168
continue;
176169
}
177-
delta = abs( v - expected[ i ] );
178-
179-
// 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
180-
tol = 1.2 * EPS * abs( expected[ i ] );
181-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
170+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' );
182171
}
183172
t.end();
184173
});
185174

186175
tape( 'the function correctly evaluates the hypergeometric function', opts, function test( t ) {
187176
var expected;
188-
var delta;
189-
var tol;
190177
var a;
191178
var b;
192179
var c;
@@ -206,19 +193,13 @@ tape( 'the function correctly evaluates the hypergeometric function', opts, func
206193
t.strictEqual( v, PINF, 'returns expected value' );
207194
continue;
208195
}
209-
delta = abs( v - expected[ i ] );
210-
211-
// 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
212-
tol = 24.0 * EPS * abs( expected[ i ] );
213-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
196+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 7 ), true, 'returns expected value' );
214197
}
215198
t.end();
216199
});
217200

218201
tape( 'the function correctly evaluates the hypergeometric function', opts, function test( t ) {
219202
var expected;
220-
var delta;
221-
var tol;
222203
var a;
223204
var b;
224205
var c;
@@ -238,19 +219,13 @@ tape( 'the function correctly evaluates the hypergeometric function', opts, func
238219
t.strictEqual( v, PINF, 'returns expected value' );
239220
continue;
240221
}
241-
delta = abs( v - expected[ i ] );
242-
243-
// 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
244-
tol = 32.0 * EPS * abs( expected[ i ] );
245-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
222+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 18 ), true, 'returns expected value' );
246223
}
247224
t.end();
248225
});
249226

250227
tape( 'the function correctly evaluates the hypergeometric function', opts, function test( t ) {
251228
var expected;
252-
var delta;
253-
var tol;
254229
var a;
255230
var b;
256231
var c;
@@ -270,19 +245,13 @@ tape( 'the function correctly evaluates the hypergeometric function', opts, func
270245
t.strictEqual( v, PINF, 'returns expected value' );
271246
continue;
272247
}
273-
delta = abs( v - expected[ i ] );
274-
275-
// 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
276-
tol = 84.0 * EPS * abs( expected[ i ] );
277-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
248+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 33 ), true, 'returns expected value' );
278249
}
279250
t.end();
280251
});
281252

282253
tape( 'the function correctly evaluates the hypergeometric function', opts, function test( t ) {
283254
var expected;
284-
var delta;
285-
var tol;
286255
var a;
287256
var b;
288257
var c;
@@ -298,11 +267,7 @@ tape( 'the function correctly evaluates the hypergeometric function', opts, func
298267

299268
for ( i = 0; i < x.length; i++ ) {
300269
v = hyp2f1( a[ i ], b[ i ], c[ i ], x[ i ] );
301-
delta = abs( v - expected[ i ] );
302-
303-
// 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
304-
tol = 345877.0 * EPS * abs( expected[ i ] );
305-
t.ok( delta <= tol, 'within tolerance. a: ' + a[ i ] + ' b: ' + b[ i ] + ' c: ' + c[ i ] + ' x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
270+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 294333 ), true, 'returns expected value' );
306271
}
307272
t.end();
308273
});

0 commit comments

Comments
 (0)