Skip to content

Commit 2e59850

Browse files
committed
test: add tests for package csignumf-assign
--- 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 acc04d2 commit 2e59850

File tree

1 file changed

+115
-0
lines changed
  • lib/node_modules/@stdlib/math/base/special/csignumf/test

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 Float32Array = require( '@stdlib/array/float32' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
27+
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
28+
var absf = require( '@stdlib/math/base/special/absf' );
29+
var EPS = require( '@stdlib/constants/float32/eps' );
30+
var csignumf = require( './../lib' );
31+
32+
33+
// FIXTURES //
34+
35+
var data = require( './fixtures/julia/data.json' );
36+
37+
38+
// TESTS //
39+
40+
tape( 'main export is a function', function test( t ) {
41+
t.ok( true, __filename );
42+
t.strictEqual( typeof csignumf.assign, 'function', 'main export is a function' );
43+
t.end();
44+
});
45+
46+
tape( 'the function evaluates the signum function and writes to output array', function test( t ) {
47+
var expectedRe = data.expected_re;
48+
var expectedIm = data.expected_im;
49+
var returned;
50+
var output;
51+
var delta;
52+
var tol;
53+
var re = data.re;
54+
var im = data.im;
55+
var i;
56+
57+
for ( i = 0; i < re.length; i++ ) {
58+
// Skip NaN cases for separate dedicated tests:
59+
if ( isnanf( expectedRe[i] ) || isnanf( expectedIm[i] ) ) {
60+
continue;
61+
}
62+
63+
output = new Float32Array( 2 );
64+
returned = csignumf.assign( re[i], im[i], output, 1, 0 );
65+
66+
t.ok( returned instanceof Float32Array, 'returns a Float32Array' );
67+
t.strictEqual( returned, output, 'returns same output array reference' );
68+
69+
if ( output[ 0 ] === expectedRe[ i ] && output[ 1 ] === expectedIm[ i ] ) {
70+
t.strictEqual( output[ 0 ], expectedRe[ i ], 're: ' + re[ i ] + '. Expected: ' + expectedRe[ i ] );
71+
t.strictEqual( output[ 1 ], expectedIm[ i ], 'im: ' + im[ i ] + '. Expected: ' + expectedIm[ i ] );
72+
} else {
73+
delta = absf( output[ 0 ] - expectedRe[ i ] );
74+
tol = EPS * absf( expectedRe[ i ] );
75+
t.ok( delta <= tol, 'within tolerance. re: ' + re[ i ] + '. Expected: ' + expectedRe[ i ] + '. Actual: ' + output[ 0 ] + '. Δ: ' + delta + '. tol: ' + tol + '.' );
76+
77+
delta = absf( output[ 1 ] - expectedIm[ i ] );
78+
tol = EPS * absf( expectedIm[ i ] );
79+
t.ok( delta <= tol, 'within tolerance. im: ' + im[ i ] + '. Expected: ' + expectedIm[ i ] + '. Actual: ' + output[ 1 ] + '. Δ: ' + delta + '. tol: ' + tol + '.' );
80+
}
81+
}
82+
t.end();
83+
});
84+
85+
tape( 'the function returns NaNs if either input is NaN', function test( t ) {
86+
var returned;
87+
var outNaN;
88+
89+
outNaN = new Float32Array( 2 );
90+
returned = csignumf.assign( NaN, NaN, outNaN, 1, 0 );
91+
92+
t.ok( returned instanceof Float32Array, 'returns a Float32Array' );
93+
t.strictEqual( returned, outNaN, 'returns same output array reference' );
94+
t.strictEqual( isnanf( outNaN[ 0 ] ), true, 'real is NaN' );
95+
t.strictEqual( isnanf( outNaN[ 1 ] ), true, 'imag is NaN' );
96+
t.end();
97+
});
98+
99+
tape( 'the function returns +0 if input is +0 +0i', function test( t ) {
100+
var outPosZero = new Float32Array( 2 );
101+
csignumf.assign( +0.0, +0.0, outPosZero, 1, 0 );
102+
103+
t.strictEqual( isPositiveZerof( outPosZero[ 0 ] ), true, 'real is +0' );
104+
t.strictEqual( isPositiveZerof( outPosZero[ 1 ] ), true, 'imag is +0' );
105+
t.end();
106+
});
107+
108+
tape( 'the function returns -0 if input is -0 -0i', function test( t ) {
109+
var outNegZero = new Float32Array( 2 );
110+
csignumf.assign( -0.0, -0.0, outNegZero, 1, 0 );
111+
112+
t.strictEqual( isNegativeZerof( outNegZero[ 0 ] ), true, 'real is -0' );
113+
t.strictEqual( isNegativeZerof( outNegZero[ 1 ] ), true, 'imag is -0' );
114+
t.end();
115+
});

0 commit comments

Comments
 (0)