Skip to content

Commit 11384c2

Browse files
committed
test: add tests and its fixtures
--- 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 8619abb commit 11384c2

File tree

6 files changed

+368
-0
lines changed

6 files changed

+368
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
julia 1.5
2+
JSON 0.21

lib/node_modules/@stdlib/math/base/special/kernel-sincos/test/fixtures/julia/large_negative.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/kernel-sincos/test/fixtures/julia/large_positive.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/kernel-sincos/test/fixtures/julia/small_range.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
26+
var kernelSincos = require( './../lib' );
27+
28+
29+
// FIXTURES //
30+
31+
var smallRange = require( './fixtures/julia/small_range.json' );
32+
var largePositive = require( './fixtures/julia/large_positive.json' );
33+
var largeNegative = require( './fixtures/julia/large_negative.json' );
34+
35+
36+
// TESTS //
37+
38+
tape( 'main export is a function', function test( t ) {
39+
t.ok( true, __filename );
40+
t.equal( typeof kernelSincos, 'function', 'main export is a function' );
41+
t.end();
42+
});
43+
44+
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
45+
var v;
46+
var z;
47+
48+
z = [ 0.0, 0.0 ];
49+
v = kernelSincos( NaN, 0.0, z, 1, 0 );
50+
t.equal( v, z, 'returns output array' );
51+
t.equal( isnan( v[0] ), true, 'returns expected value' );
52+
t.equal( isnan( v[1] ), true, 'returns expected value' );
53+
t.end();
54+
});
55+
56+
tape( 'the function evaluates the sine and cosine for input values on the interval `[-pi/4, pi/4]`', function test( t ) {
57+
var cosine;
58+
var sine;
59+
var x;
60+
var y;
61+
var i;
62+
var z;
63+
64+
z = [ 0.0, 0.0 ];
65+
x = smallRange.x;
66+
sine = smallRange.sine;
67+
cosine = smallRange.cosine;
68+
69+
for ( i = 0; i < x.length; i++ ) {
70+
y = kernelSincos( x[i], 0.0, z, 1, 0 );
71+
t.equal( y, z, 'returns output array' );
72+
t.equal( y[0], sine[ i ], 'returns expected value' );
73+
t.equal( y[1], cosine[ i ], 'returns expected value' );
74+
}
75+
t.end();
76+
});
77+
78+
tape( 'the function can be used to compute the sine and cosine for input values outside of `[-pi/4, pi/4]` after argument reduction via `rempio2` (positive)', function test( t ) {
79+
var cosine;
80+
var sine;
81+
var out;
82+
var z;
83+
var x;
84+
var y;
85+
var n;
86+
var i;
87+
88+
z = [ 0.0, 0.0 ];
89+
y = [ 0.0, 0.0 ];
90+
x = largePositive.x;
91+
sine = largePositive.sine;
92+
cosine = largePositive.cosine;
93+
for ( i = 0; i < x.length; i++ ) {
94+
n = rempio2( x[ i ], y );
95+
switch ( n & 3 ) {
96+
case 0:
97+
out = kernelSincos( y[ 0 ], y[ 1 ], z, 1, 0 );
98+
t.equal( out, z, 'returns output array' );
99+
t.equal( out[ 0 ], sine[ i ], 'returns expected value' );
100+
t.equal( out[ 1 ], cosine[ i ], 'returns expected value' );
101+
break;
102+
case 2:
103+
out = kernelSincos( y[ 0 ], y[ 1 ], z, 1, 0 );
104+
t.equal( out, z, 'returns output array' );
105+
t.equal( -out[ 0 ], sine[ i ], 'returns expected value' );
106+
t.equal( -out[ 1 ], cosine[ i ], 'returns expected value' );
107+
break;
108+
default:
109+
break;
110+
}
111+
}
112+
t.end();
113+
});
114+
115+
tape( 'the function can be used to compute the sine and cosine for input values outside of `[-pi/4, pi/4]` after argument reduction via `rempio2` (negative)', function test( t ) {
116+
var cosine;
117+
var sine;
118+
var out;
119+
var z;
120+
var x;
121+
var y;
122+
var n;
123+
var i;
124+
125+
z = [ 0.0, 0.0 ];
126+
y = [ 0.0, 0.0 ];
127+
x = largeNegative.x;
128+
sine = largeNegative.sine;
129+
cosine = largeNegative.cosine;
130+
for ( i = 0; i < x.length; i++ ) {
131+
n = rempio2( x[ i ], y );
132+
switch ( n & 3 ) {
133+
case 0:
134+
out = kernelSincos( y[ 0 ], y[ 1 ], z, 1, 0 );
135+
t.equal( out, z, 'returns output array' );
136+
t.equal( out[ 0 ], sine[ i ], 'returns expected value' );
137+
t.equal( out[ 1 ], cosine[ i ], 'returns expected value' );
138+
break;
139+
case 2:
140+
out = kernelSincos( y[ 0 ], y[ 1 ], z, 1, 0 );
141+
t.equal( out, z, 'returns output array' );
142+
t.equal( -out[ 0 ], sine[ i ], 'returns expected value' );
143+
t.equal( -out[ 1 ], cosine[ i ], 'returns expected value' );
144+
break;
145+
default:
146+
break;
147+
}
148+
}
149+
t.end();
150+
});
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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 abs = require( '@stdlib/math/base/special/abs' );
27+
var EPS = require( '@stdlib/constants/float64/eps' );
28+
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
29+
var tryRequire = require( '@stdlib/utils/try-require' );
30+
31+
32+
// VARIABLES //
33+
34+
var kernelSincos = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( kernelSincos instanceof Error )
37+
};
38+
39+
40+
// FIXTURES //
41+
42+
var smallRange = require( './fixtures/julia/small_range.json' );
43+
var largePositive = require( './fixtures/julia/large_positive.json' );
44+
var largeNegative = require( './fixtures/julia/large_negative.json' );
45+
46+
47+
// TESTS //
48+
49+
tape( 'main export is a function', opts, function test( t ) {
50+
t.ok( true, __filename );
51+
t.equal( typeof kernelSincos, 'function', 'main export is a function' );
52+
t.end();
53+
});
54+
55+
tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) {
56+
var v;
57+
58+
v = kernelSincos( NaN, 0.0 );
59+
t.equal( isnan( v[0] ), true, 'returns expected value' );
60+
t.equal( isnan( v[1] ), true, 'returns expected value' );
61+
t.end();
62+
});
63+
64+
tape( 'the function evaluates the sine and cosine for input values on the interval `[-pi/4, pi/4]`', opts, function test( t ) {
65+
var cosine;
66+
var delta;
67+
var sine;
68+
var tol;
69+
var x;
70+
var y;
71+
var i;
72+
73+
x = smallRange.x;
74+
sine = smallRange.sine;
75+
cosine = smallRange.cosine;
76+
77+
for ( i = 0; i < x.length; i++ ) {
78+
y = kernelSincos( x[i], 0.0 );
79+
if ( y[0] === sine[ i ] ) {
80+
t.equal( y[0], sine[ i ], 'returns expected value' );
81+
} else {
82+
delta = abs( y[0] - sine[i] );
83+
84+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
85+
tol = EPS * abs( sine[i] );
86+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
87+
}
88+
t.equal( y[1], cosine[ i ], 'returns expected value' );
89+
}
90+
t.end();
91+
});
92+
93+
tape( 'the function can be used to compute the sine and cosine for input values outside of `[-pi/4, pi/4]` after argument reduction via `rempio2` (positive)', opts, function test( t ) {
94+
var cosine;
95+
var delta;
96+
var sine;
97+
var tol;
98+
var out;
99+
var x;
100+
var y;
101+
var n;
102+
var i;
103+
104+
y = [ 0.0, 0.0 ];
105+
x = largePositive.x;
106+
sine = largePositive.sine;
107+
cosine = largePositive.cosine;
108+
for ( i = 0; i < x.length; i++ ) {
109+
n = rempio2( x[ i ], y );
110+
switch ( n & 3 ) {
111+
case 0:
112+
out = kernelSincos( y[ 0 ], y[ 1 ] );
113+
if ( out[0] === sine[ i ] ) {
114+
t.equal( out[0], sine[ i ], 'returns expected value' );
115+
} else {
116+
delta = abs( out[0] - sine[i] );
117+
118+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
119+
tol = EPS * abs( sine[i] );
120+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+out[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
121+
}
122+
t.equal( out[1], cosine[ i ], 'returns expected value' );
123+
break;
124+
case 2:
125+
out = kernelSincos( y[ 0 ], y[ 1 ] );
126+
out[ 0 ] = -out[ 0 ];
127+
out[ 1 ] = -out[ 1 ];
128+
if ( out[0] === sine[ i ] ) {
129+
t.equal( out[0], sine[ i ], 'returns expected value' );
130+
} else {
131+
delta = abs( out[0] - sine[i] );
132+
133+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
134+
tol = EPS * abs( sine[i] );
135+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+out[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
136+
}
137+
if ( out[1] === cosine[ i ] ) {
138+
t.equal( out[1], cosine[ i ], 'returns expected value' );
139+
} else {
140+
delta = abs( out[1] - cosine[i] );
141+
142+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
143+
tol = EPS * abs( cosine[i] );
144+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+out[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
145+
}
146+
break;
147+
default:
148+
break;
149+
}
150+
}
151+
t.end();
152+
});
153+
154+
tape( 'the function can be used to compute the sine and cosine for input values outside of `[-pi/4, pi/4]` after argument reduction via `rempio2` (negative)', opts, function test( t ) {
155+
var cosine;
156+
var delta;
157+
var sine;
158+
var tol;
159+
var out;
160+
var x;
161+
var y;
162+
var n;
163+
var i;
164+
165+
y = [ 0.0, 0.0 ];
166+
x = largeNegative.x;
167+
sine = largeNegative.sine;
168+
cosine = largeNegative.cosine;
169+
for ( i = 0; i < x.length; i++ ) {
170+
n = rempio2( x[ i ], y );
171+
switch ( n & 3 ) {
172+
case 0:
173+
out = kernelSincos( y[ 0 ], y[ 1 ] );
174+
if ( out[0] === sine[ i ] ) {
175+
t.equal( out[0], sine[ i ], 'returns expected value' );
176+
} else {
177+
delta = abs( out[0] - sine[i] );
178+
179+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
180+
tol = EPS * abs( sine[i] );
181+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+out[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
182+
}
183+
t.equal( out[1], cosine[ i ], 'returns expected value' );
184+
break;
185+
case 2:
186+
out = kernelSincos( y[ 0 ], y[ 1 ] );
187+
out[ 0 ] = -out[ 0 ];
188+
out[ 1 ] = -out[ 1 ];
189+
if ( out[0] === sine[ i ] ) {
190+
t.equal( out[0], sine[ i ], 'returns expected value' );
191+
} else {
192+
delta = abs( out[0] - sine[i] );
193+
194+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
195+
tol = EPS * abs( sine[i] );
196+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+out[0]+'. Expected: '+sine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
197+
}
198+
if ( out[1] === cosine[ i ] ) {
199+
t.equal( out[1], cosine[ i ], 'returns expected value' );
200+
} else {
201+
delta = abs( out[1] - cosine[i] );
202+
203+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
204+
tol = EPS * abs( cosine[i] );
205+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+out[1]+'. Expected: '+cosine[i]+'. tol: '+tol+'. delta: '+delta+'.' );
206+
}
207+
break;
208+
default:
209+
break;
210+
}
211+
}
212+
t.end();
213+
});

0 commit comments

Comments
 (0)