Skip to content

Commit 01e7ade

Browse files
committed
test: add tests
--- 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 6fbb66a commit 01e7ade

File tree

1 file changed

+113
-0
lines changed
  • lib/node_modules/@stdlib/lapack/base/dlapy3/test

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 PINF = require( '@stdlib/constants/float64/pinf' );
25+
var sqrt = require( '@stdlib/math/base/special/sqrt' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
29+
var dlapy3 = require( './../lib' );
30+
31+
32+
// TESTS //
33+
34+
tape( 'main export is a function', function test( t ) {
35+
t.ok( true, __filename );
36+
t.strictEqual( typeof dlapy3, 'function', 'main export is a function' );
37+
t.end();
38+
});
39+
40+
tape( 'the function returns `NaN` if either argument is `NaN` but not `+-infinity`', function test( t ) {
41+
var h;
42+
43+
h = dlapy3( NaN, 3.14, 2.0 );
44+
t.strictEqual( isnan( h ), true, 'returns expected value' );
45+
46+
h = dlapy3( 3.14, NaN, 2.0 );
47+
t.strictEqual( isnan( h ), true, 'returns expected value' );
48+
49+
h = dlapy3( 3.14, 2.0, NaN );
50+
t.strictEqual( isnan( h ), true, 'returns expected value' );
51+
52+
h = dlapy3( NaN, NaN, NaN );
53+
t.strictEqual( isnan( h ), true, 'returns expected value' );
54+
55+
t.end();
56+
});
57+
58+
tape( 'the function returns `+0` if both arguments are `+-0`', function test( t ) {
59+
var h;
60+
61+
h = dlapy3( +0.0, +0.0, +0.0 );
62+
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );
63+
64+
h = dlapy3( -0.0, +0.0, -0.0 );
65+
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );
66+
67+
h = dlapy3( +0.0, -0.0, 0.0 );
68+
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );
69+
70+
h = dlapy3( -0.0, -0.0, -0.0 );
71+
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );
72+
73+
t.end();
74+
});
75+
76+
tape( 'the function computes the euclidian norm', function test( t ) {
77+
var h;
78+
79+
h = dlapy3( 1234.0, 7863.0, 1298.0 );
80+
t.strictEqual( h, 8064.3864614736813, 'returns expected value' );
81+
82+
h = dlapy3( 7.0, 9.0, 12.0 );
83+
t.strictEqual( h, 16.552945357246848, 'returns expected value' );
84+
85+
h = dlapy3( 3.0, 4.0, 12.0 );
86+
t.strictEqual( h, 13.0, 'returns expected value' );
87+
88+
t.end();
89+
});
90+
91+
tape( 'the function avoids overflow', function test( t ) {
92+
var h;
93+
94+
h = sqrt( pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) );
95+
t.strictEqual( h, PINF, 'returns expected value' );
96+
97+
h = dlapy3( 1.0e308, 1.0e308, 1.0e308 );
98+
t.strictEqual( h, 1.7320508075688772e+308, 'avoids overflow' );
99+
100+
t.end();
101+
});
102+
103+
tape( 'the function avoids underflow', function test( t ) {
104+
var h;
105+
106+
h = sqrt( pow( 1.0e-200, 2 ) + pow( 1e-200, 2 ) + pow( 1e-200, 2 ) );
107+
t.strictEqual( h, 0.0, 'returns 0' );
108+
109+
h = dlapy3( 1.0e-200, 1.0e-200, 1.0e-200 );
110+
t.strictEqual( h, 1.7320508075688772e-200, 'avoids underflow' );
111+
112+
t.end();
113+
});

0 commit comments

Comments
 (0)