Skip to content

Commit 08fc1fd

Browse files
committed
fix: ensure consistency between asechf and asech tests
1 parent 2e6403c commit 08fc1fd

4 files changed

Lines changed: 86 additions & 89 deletions

File tree

lib/node_modules/@stdlib/math/base/special/asechf/lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
// MODULES //
2222

2323
var acoshf = require( '@stdlib/math/base/special/acoshf' );
24-
var f32 = require( '@stdlib/number/float64/base/to-float32' );
24+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2525

2626

2727
// VARIABLES //
2828

29-
var ONE = f32( 1.0 );
29+
var ONE = float64ToFloat32( 1.0 );
3030

3131

3232
// MAIN //
@@ -56,7 +56,7 @@ var ONE = f32( 1.0 );
5656
* // returns NaN
5757
*/
5858
function asechf( x ) {
59-
return acoshf( f32( ONE / f32( x ) ) );
59+
return acoshf( float64ToFloat32( ONE / float64ToFloat32( x ) ) );
6060
}
6161

6262

lib/node_modules/@stdlib/math/base/special/asechf/test/fixtures/julia/runner.jl

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,53 @@
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
18-
#
1918

2019
import JSON
2120
import Base: asech
2221

2322
"""
24-
gen( domain, name )
23+
gen( domain, name )
2524
2625
Generate fixture data and write to file.
2726
2827
# Arguments
2928
3029
* `domain`: domain
3130
* `name::AbstractString`: output filename
31+
32+
# Examples
33+
34+
``` julia
35+
julia> x = range( -1000, stop = 1000, length = 2022 );
36+
julia> gen( x, "data.json" );
37+
```
3238
"""
3339
function gen( domain, name )
3440
x = collect( domain );
41+
y = Float32.( asech.( x ) );
3542

36-
y = Float32.( asech.( x ) )
37-
data = Dict(
38-
"x" => x,
39-
"expected" => y
40-
)
43+
# Store data to be written to file as a collection:
44+
data = Dict([
45+
("x", x),
46+
("expected", y)
47+
]);
4148

42-
filepath = joinpath( dir, name )
49+
# Based on the script directory, create an output filepath:
50+
filepath = joinpath( dir, name );
4351

44-
open( filepath, "w" ) do io
45-
write( io, JSON.json( data ) )
46-
write( io, "\n" )
47-
end
52+
# Write the data to the output filepath as JSON:
53+
outfile = open( filepath, "w" );
54+
write( outfile, JSON.json(data) );
55+
write( outfile, "\n" );
56+
close( outfile );
4857
end
4958

5059
# Get the filename:
51-
file = @__FILE__
60+
file = @__FILE__;
5261

5362
# Extract the directory in which this file resides:
54-
dir = dirname( file )
63+
dir = dirname( file );
5564

5665
# Generate values over the function domain:
57-
x = Float32.( range( 1.0e-5, stop = 1.0, length = 2003 ) )
58-
gen( x, "data.json" )
66+
x = Float32.( range( 1.0e-5, stop = 1.0, length = 2003 ) );
67+
gen( x, "data.json" );

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

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
var tape = require( 'tape' );
2424
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var randu = require( '@stdlib/random/base/randu' );
2526
var abs = require( '@stdlib/math/base/special/abs' );
2627
var EPS = require( '@stdlib/constants/float32/eps' );
28+
var PINF = require( '@stdlib/constants/float64/pinf' );
2729
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
28-
var max = require( '@stdlib/math/base/special/max' );
2930
var asechf = require( './../lib' );
3031

3132

@@ -56,46 +57,38 @@ tape( 'the function computes the hyperbolic arcsecant on the interval (0, 1]', f
5657

5758
for ( i = 0; i < x.length; i++ ) {
5859
y = asechf( x[i] );
59-
if ( y === expected[ i ] ) {
60-
t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
60+
e = float64ToFloat32( expected[i] );
61+
if ( y === e ) {
62+
t.strictEqual( y, e, 'x: '+x[i]+'. E: '+e );
6163
} else {
62-
e = float64ToFloat32( expected[i] );
6364
delta = abs( y - e );
64-
tol = max( 10.0 * EPS * abs( e ), 2.0e-6 );
65-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
65+
tol = 1.0 * EPS * abs( e );
66+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
6667
}
6768
}
6869
t.end();
6970
});
7071

71-
tape( 'the function computes the hyperbolic arcsecant of 1', function test( t ) {
72-
var v = asechf( 1.0 );
73-
t.strictEqual( v, 0.0, 'returns expected value' );
74-
t.end();
75-
});
76-
77-
tape( 'the function computes the hyperbolic arcsecant of 0.5', function test( t ) {
78-
var expected = float64ToFloat32( 1.3169578969248166 );
79-
var delta;
80-
var tol;
81-
var v;
82-
83-
v = asechf( 0.5 );
84-
delta = abs( v - expected );
85-
tol = 10.0 * EPS;
86-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
72+
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
73+
var v = asechf( NaN );
74+
t.strictEqual( isnanf( v ), true, 'returns expected value' );
8775
t.end();
8876
});
8977

90-
tape( 'the function returns `Infinity` for `x = 0`', function test( t ) {
78+
tape( 'the function returns `+infinity` if provided `+0`', function test( t ) {
9179
var v = asechf( 0.0 );
92-
t.strictEqual( v, Infinity, 'returns expected value' );
80+
t.strictEqual( v, PINF, 'returns expected value' );
9381
t.end();
9482
});
9583

96-
tape( 'the function returns `NaN` for negative values', function test( t ) {
97-
var v = asechf( -1.0 );
98-
t.strictEqual( isnanf( v ), true, 'returns NaN' );
84+
tape( 'the function returns `NaN` if provided a value less than `0`', function test( t ) {
85+
var v;
86+
var i;
87+
88+
for ( i = 0; i < 1e3; i++ ) {
89+
v = -(i+1) * randu();
90+
t.strictEqual( isnanf( asechf( v ) ), true, 'returns NaN when provided '+v );
91+
}
9992
t.end();
10093
});
10194

@@ -105,14 +98,14 @@ tape( 'the function returns `NaN` for negative zero', function test( t ) {
10598
t.end();
10699
});
107100

108-
tape( 'the function returns `NaN` for values greater than 1', function test( t ) {
109-
var v = asechf( 2.0 );
110-
t.strictEqual( isnanf( v ), true, 'returns NaN' );
111-
t.end();
112-
});
101+
tape( 'the function returns `NaN` if provided a value greater than `1`', function test( t ) {
102+
var v;
103+
var i;
113104

114-
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
115-
var v = asechf( NaN );
116-
t.strictEqual( isnanf( v ), true, 'returns NaN' );
105+
for ( i = 0; i < 1e3; i++ ) {
106+
v = ( i * randu() * 100.0 ) + 1.0 + EPS;
107+
t.strictEqual( isnanf( asechf( v ) ), true, 'returns NaN when provided '+v );
108+
}
117109
t.end();
118110
});
111+

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

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26-
var abs = require( '@stdlib/math/base/special/abs' );
26+
var randu = require( '@stdlib/random/base/randu' );
2727
var EPS = require( '@stdlib/constants/float32/eps' );
28+
var PINF = require( '@stdlib/constants/float64/pinf' );
29+
var abs = require( '@stdlib/math/base/special/abs' );
2830
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2931
var tryRequire = require( '@stdlib/utils/try-require' );
30-
var max = require( '@stdlib/math/base/special/max' );
3132

3233

3334
// FIXTURES //
@@ -66,42 +67,37 @@ tape( 'the function computes the hyperbolic arcsecant on the interval (0, 1]', o
6667
for ( i = 0; i < x.length; i++ ) {
6768
y = asechf( x[i] );
6869
e = float64ToFloat32( expected[i] );
69-
delta = abs( y - e );
70-
tol = max( 10.0 * EPS * abs( e ), 2.0e-6 );
71-
72-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
70+
if ( y === e ) {
71+
t.strictEqual( y, e, 'x: '+x[i]+'. E: '+e );
72+
} else {
73+
delta = abs( y - e );
74+
tol = 1.0 * EPS * abs( e );
75+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
76+
}
7377
}
7478
t.end();
7579
});
7680

77-
tape( 'the function computes the hyperbolic arcsecant of 1', opts, function test( t ) {
78-
var v = asechf( 1.0 );
79-
t.strictEqual( v, 0.0, 'returns expected value' );
80-
t.end();
81-
});
82-
83-
tape( 'the function computes the hyperbolic arcsecant of 0.5', opts, function test( t ) {
84-
var expected = float64ToFloat32( 1.3169578969248166 );
85-
var delta;
86-
var tol;
87-
var v;
88-
89-
v = asechf( 0.5 );
90-
delta = abs( v - expected );
91-
tol = 10.0 * EPS;
92-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
81+
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
82+
var v = asechf( NaN );
83+
t.strictEqual( isnanf( v ), true, 'returns expected value' );
9384
t.end();
9485
});
9586

96-
tape( 'the function returns `Infinity` for `x = 0`', opts, function test( t ) {
87+
tape( 'the function returns `+infinity` if provided `+0`', opts, function test( t ) {
9788
var v = asechf( 0.0 );
98-
t.strictEqual( v, Infinity, 'returns Infinity' );
89+
t.strictEqual( v, PINF, 'returns expected value' );
9990
t.end();
10091
});
10192

102-
tape( 'the function returns `NaN` for negative values', opts, function test( t ) {
103-
var v = asechf( -1.0 );
104-
t.strictEqual( isnanf( v ), true, 'returns NaN' );
93+
tape( 'the function returns `NaN` if provided a value less than `0`', opts, function test( t ) {
94+
var v;
95+
var i;
96+
97+
for ( i = 0; i < 1e3; i++ ) {
98+
v = -(i+1) * randu();
99+
t.strictEqual( isnanf( asechf( v ) ), true, 'returns NaN when provided '+v );
100+
}
105101
t.end();
106102
});
107103

@@ -111,14 +107,13 @@ tape( 'the function returns `NaN` for negative zero', opts, function test( t ) {
111107
t.end();
112108
});
113109

114-
tape( 'the function returns `NaN` for values greater than 1', opts, function test( t ) {
115-
var v = asechf( 2.0 );
116-
t.strictEqual( isnanf( v ), true, 'returns NaN' );
117-
t.end();
118-
});
110+
tape( 'the function returns `NaN` if provided a value greater than `1`', opts, function test( t ) {
111+
var v;
112+
var i;
119113

120-
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
121-
var v = asechf( NaN );
122-
t.strictEqual( isnanf( v ), true, 'returns NaN' );
114+
for ( i = 0; i < 1e3; i++ ) {
115+
v = ( i * randu() * 100.0 ) + 1.0 + EPS;
116+
t.strictEqual( isnanf( asechf( v ) ), true, 'returns NaN when provided '+v );
117+
}
123118
t.end();
124119
});

0 commit comments

Comments
 (0)