Skip to content

Commit 53b443c

Browse files
chore: add test for acoshf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c4b1fc0 commit 53b443c

File tree

2 files changed

+289
-0
lines changed

2 files changed

+289
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var EPS = require( '@stdlib/constants/float32/eps' );
27+
var absf = require( '@stdlib/math/base/special/absf' );
28+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
29+
var acoshf = require( './../lib' );
30+
31+
32+
// FIXTURES //
33+
34+
var largerPositive = require( './fixtures/julia/larger_positive.json' );
35+
var largePositive = require( './fixtures/julia/large_positive.json' );
36+
var mediumPositive = require( './fixtures/julia/medium_positive.json' );
37+
38+
39+
// TESTS //
40+
41+
tape( 'main export is a function', function test( t ) {
42+
t.ok( true, __filename );
43+
t.true( typeof acoshf, 'function', 'main export is a function' );
44+
t.end();
45+
});
46+
47+
tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]', function test( t ) {
48+
var expected;
49+
var delta;
50+
var tol;
51+
var e;
52+
var x;
53+
var y;
54+
var i;
55+
56+
x = mediumPositive.x;
57+
expected = mediumPositive.expected;
58+
59+
for ( i = 0; i < x.length; i++ ) {
60+
y = acoshf( x[i] );
61+
e = float64ToFloat32( expected[ i ] );
62+
if ( y === e ) {
63+
t.equal( y, e, 'x: '+x[i]+'. E: '+e );
64+
} else {
65+
delta = absf( y - e );
66+
tol = 1.0 * EPS * absf( e );
67+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
68+
}
69+
}
70+
t.end();
71+
});
72+
73+
tape( 'the function computes the hyperbolic arccosine on the interval [3.0,28.0]', function test( t ) {
74+
var expected;
75+
var delta;
76+
var tol;
77+
var e;
78+
var x;
79+
var y;
80+
var i;
81+
82+
x = largePositive.x;
83+
expected = largePositive.expected;
84+
85+
for ( i = 0; i < x.length; i++ ) {
86+
y = acoshf( x[i] );
87+
e = float64ToFloat32( expected[ i ] );
88+
if ( y === e ) {
89+
t.equal( y, e, 'x: '+x[i]+'. E: '+e );
90+
} else {
91+
delta = absf( y - e );
92+
tol = 1.0 * EPS * absf( e );
93+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
94+
}
95+
}
96+
t.end();
97+
});
98+
99+
tape( 'the function computes the hyperbolic arccosine on the interval [28.0,100.0]', function test( t ) {
100+
var expected;
101+
var delta;
102+
var tol;
103+
var e;
104+
var x;
105+
var y;
106+
var i;
107+
108+
x = largerPositive.x;
109+
expected = largerPositive.expected;
110+
111+
for ( i = 0; i < x.length; i++ ) {
112+
y = acoshf( x[i] );
113+
e = float64ToFloat32( expected[ i ] );
114+
if ( y === e ) {
115+
t.equal( y, e, 'x: '+x[i]+'. E: '+e );
116+
} else {
117+
delta = absf( y - e );
118+
tol = 1.0 * EPS * absf( e );
119+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
120+
}
121+
}
122+
t.end();
123+
});
124+
125+
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
126+
var v = acoshf( NaN );
127+
t.equal( isnanf( v ), true, 'returns expected value' );
128+
t.end();
129+
});
130+
131+
tape( 'the function returns `NaN` if provided value less than `1`', function test( t ) {
132+
var v;
133+
var i;
134+
135+
for ( i = 0; i < 1e3; i++ ) {
136+
v = -(randu()*1.0e6) + (1-EPS);
137+
t.equal( isnanf( acoshf( v ) ), true, 'returns expected value when provided '+v );
138+
}
139+
t.end();
140+
});
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var tape = require( 'tape' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var randu = require( '@stdlib/random/base/randu' );
27+
var EPS = require( '@stdlib/constants/float64/eps' );
28+
var abs = require( '@stdlib/math/base/special/abs' );
29+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
32+
33+
// FIXTURES //
34+
35+
var largerPositive = require( './fixtures/julia/larger_positive.json' );
36+
var largePositive = require( './fixtures/julia/large_positive.json' );
37+
var mediumPositive = require( './fixtures/julia/medium_positive.json' );
38+
39+
40+
// VARIABLES //
41+
42+
var acoshf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
43+
var opts = {
44+
'skip': ( acoshf instanceof Error )
45+
};
46+
47+
48+
// TESTS //
49+
50+
tape( 'main export is a function', opts, function test( t ) {
51+
t.ok( true, __filename );
52+
t.true( typeof acoshf, 'function', 'main export is a function' );
53+
t.end();
54+
});
55+
56+
tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]', opts, function test( t ) {
57+
var expected;
58+
var delta;
59+
var tol;
60+
var e;
61+
var x;
62+
var y;
63+
var i;
64+
65+
x = mediumPositive.x;
66+
expected = mediumPositive.expected;
67+
68+
for ( i = 0; i < x.length; i++ ) {
69+
y = acoshf( x[i] );
70+
e = float64ToFloat32( expected[ i ] );
71+
if ( y === e ) {
72+
t.equal( y, e, 'x: '+x[i]+'. E: '+e );
73+
} else {
74+
delta = abs( y - e );
75+
tol = 1.0 * EPS * abs( e );
76+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
77+
}
78+
}
79+
t.end();
80+
});
81+
82+
tape( 'the function computes the hyperbolic arccosine on the interval [3.0,28.0]', opts, function test( t ) {
83+
var expected;
84+
var delta;
85+
var tol;
86+
var e;
87+
var x;
88+
var y;
89+
var i;
90+
91+
x = largePositive.x;
92+
expected = largePositive.expected;
93+
94+
for ( i = 0; i < x.length; i++ ) {
95+
e = float64ToFloat32( expected[ i ] );
96+
y = acoshf( x[i] );
97+
if ( y === e ) {
98+
t.equal( y, e, 'x: '+x[i]+'. E: '+e );
99+
} else {
100+
delta = abs( y - e );
101+
tol = 1.0 * EPS * abs( e );
102+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
103+
}
104+
}
105+
t.end();
106+
});
107+
108+
tape( 'the function computes the hyperbolic arccosine on the interval [28.0,100.0]', opts, function test( t ) {
109+
var expected;
110+
var delta;
111+
var tol;
112+
var e;
113+
var x;
114+
var y;
115+
var i;
116+
117+
x = largerPositive.x;
118+
expected = largerPositive.expected;
119+
120+
for ( i = 0; i < x.length; i++ ) {
121+
y = acoshf( x[i] );
122+
e = float64ToFloat32( expected[ i ] );
123+
if ( y === e ) {
124+
t.equal( y, e, 'x: '+x[i]+'. E: '+e );
125+
} else {
126+
delta = abs( y - e );
127+
tol = 1.0 * EPS * abs( e );
128+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. tol: '+tol+'. Δ: '+delta+'.' );
129+
}
130+
}
131+
t.end();
132+
});
133+
134+
tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
135+
var v = acoshf( NaN );
136+
t.equal( isnan( v ), true, 'returns expected value' );
137+
t.end();
138+
});
139+
140+
tape( 'the function returns `NaN` if provided value less than `1`', opts, function test( t ) {
141+
var v;
142+
var i;
143+
144+
for ( i = 0; i < 1e3; i++ ) {
145+
v = -(randu()*1.0e6) + (1-EPS);
146+
t.equal( isnan( acoshf( v ) ), true, 'returns expected value when provided '+v );
147+
}
148+
t.end();
149+
});

0 commit comments

Comments
 (0)