Skip to content

Commit e41e763

Browse files
committed
test: add tests to achieve full coverage in math/base/special/lnf
--- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent f57dc90 commit e41e763

File tree

3 files changed

+230
-0
lines changed

3 files changed

+230
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ tape( 'the function returns `NaN` if provided a negative number', function test(
242242
t.end();
243243
});
244244

245+
tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) {
246+
var v = lnf( NINF );
247+
t.strictEqual( isnanf( v ), true, 'returns expected value' );
248+
t.end();
249+
});
250+
251+
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
252+
var v = lnf( NaN );
253+
t.strictEqual( isnanf( v ), true, 'returns expected value' );
254+
t.end();
255+
});
256+
245257
tape( 'the function returns positive zero if provided `1.0`', function test( t ) {
246258
var v = lnf( 1.0 );
247259
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 abs = require( '@stdlib/math/base/special/abs' );
25+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
26+
var polyval = require( './../lib/polyval_p.js' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof polyval, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'the function evaluates a polynomial for x = 0', function test( t ) {
38+
var v = polyval( 0.0 );
39+
t.strictEqual( v, 0.40000972152, 'returns expected value' );
40+
t.end();
41+
});
42+
43+
tape( 'the function evaluates a polynomial for x = -0', function test( t ) {
44+
var v = polyval( -0.0 );
45+
t.strictEqual( v, 0.40000972152, 'returns expected value' );
46+
t.end();
47+
});
48+
49+
tape( 'the function evaluates a polynomial for positive values', function test( t ) {
50+
var expected;
51+
var delta;
52+
var tol;
53+
var v;
54+
var x;
55+
56+
x = 1.0;
57+
expected = float64ToFloat32( 0.40000972152 + (x * 0.24279078841) );
58+
v = polyval( x );
59+
delta = abs( v - expected );
60+
tol = 1e-6;
61+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
62+
63+
x = 0.5;
64+
expected = float64ToFloat32( 0.40000972152 + (x * 0.24279078841) );
65+
v = polyval( x );
66+
delta = abs( v - expected );
67+
tol = 1e-6;
68+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
69+
70+
x = 0.1;
71+
expected = float64ToFloat32( 0.40000972152 + (x * 0.24279078841) );
72+
v = polyval( x );
73+
delta = abs( v - expected );
74+
tol = 1e-6;
75+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
76+
77+
t.end();
78+
});
79+
80+
tape( 'the function evaluates a polynomial for negative values', function test( t ) {
81+
var expected;
82+
var delta;
83+
var tol;
84+
var v;
85+
var x;
86+
87+
x = -1.0;
88+
expected = float64ToFloat32( 0.40000972152 + (x * 0.24279078841) );
89+
v = polyval( x );
90+
delta = abs( v - expected );
91+
tol = 1e-6;
92+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
93+
94+
x = -0.5;
95+
expected = float64ToFloat32( 0.40000972152 + (x * 0.24279078841) );
96+
v = polyval( x );
97+
delta = abs( v - expected );
98+
tol = 1e-6;
99+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
100+
101+
x = -0.1;
102+
expected = float64ToFloat32( 0.40000972152 + (x * 0.24279078841) );
103+
v = polyval( x );
104+
delta = abs( v - expected );
105+
tol = 1e-6;
106+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
107+
108+
t.end();
109+
});
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 abs = require( '@stdlib/math/base/special/abs' );
25+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
26+
var polyval = require( './../lib/polyval_q.js' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof polyval, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'the function evaluates a polynomial for x = 0', function test( t ) {
38+
var v = polyval( 0.0 );
39+
t.strictEqual( v, 0.66666662693, 'returns expected value' );
40+
t.end();
41+
});
42+
43+
tape( 'the function evaluates a polynomial for x = -0', function test( t ) {
44+
var v = polyval( -0.0 );
45+
t.strictEqual( v, 0.66666662693, 'returns expected value' );
46+
t.end();
47+
});
48+
49+
tape( 'the function evaluates a polynomial for positive values', function test( t ) {
50+
var expected;
51+
var delta;
52+
var tol;
53+
var v;
54+
var x;
55+
56+
x = 1.0;
57+
expected = float64ToFloat32( 0.66666662693 + (x * 0.28498786688) );
58+
v = polyval( x );
59+
delta = abs( v - expected );
60+
tol = 1e-6;
61+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
62+
63+
x = 0.5;
64+
expected = float64ToFloat32( 0.66666662693 + (x * 0.28498786688) );
65+
v = polyval( x );
66+
delta = abs( v - expected );
67+
tol = 1e-6;
68+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
69+
70+
x = 0.1;
71+
expected = float64ToFloat32( 0.66666662693 + (x * 0.28498786688) );
72+
v = polyval( x );
73+
delta = abs( v - expected );
74+
tol = 1e-6;
75+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
76+
77+
t.end();
78+
});
79+
80+
tape( 'the function evaluates a polynomial for negative values', function test( t ) {
81+
var expected;
82+
var delta;
83+
var tol;
84+
var v;
85+
var x;
86+
87+
x = -1.0;
88+
expected = float64ToFloat32( 0.66666662693 + (x * 0.28498786688) );
89+
v = polyval( x );
90+
delta = abs( v - expected );
91+
tol = 1e-6;
92+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
93+
94+
x = -0.5;
95+
expected = float64ToFloat32( 0.66666662693 + (x * 0.28498786688) );
96+
v = polyval( x );
97+
delta = abs( v - expected );
98+
tol = 1e-6;
99+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
100+
101+
x = -0.1;
102+
expected = float64ToFloat32( 0.66666662693 + (x * 0.28498786688) );
103+
v = polyval( x );
104+
delta = abs( v - expected );
105+
tol = 1e-6;
106+
t.ok( delta <= tol, 'within tolerance. x: ' + x + '. Value: ' + v + '. Expected: ' + expected + '. Delta: ' + delta + '. Tolerance: ' + tol + '.' );
107+
108+
t.end();
109+
});

0 commit comments

Comments
 (0)