Skip to content

Commit 0605322

Browse files
committed
test: add test files and their 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: na - 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 7b7852a commit 0605322

File tree

6 files changed

+329
-0
lines changed

6 files changed

+329
-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/sind/test/fixtures/julia/negative.json

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

lib/node_modules/@stdlib/math/base/special/sind/test/fixtures/julia/positive.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env julia
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2025 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
import JSON
20+
21+
"""
22+
gen( domain, name )
23+
24+
Generate fixture data and write to file.
25+
26+
# Arguments
27+
28+
* `domain`: domain
29+
* `name::AbstractString`: output filename
30+
31+
# Examples
32+
33+
``` julia
34+
julia> x = range( -1, stop = 1, length = 2001 );
35+
julia> gen( x, \"data.json\" );
36+
```
37+
"""
38+
function gen( domain, name )
39+
x = collect( domain );
40+
y = sind.( x );
41+
42+
# Store data to be written to file as a collection:
43+
data = Dict([
44+
("x", x),
45+
("expected", y)
46+
]);
47+
48+
# Based on the script directory, create an output filepath:
49+
filepath = joinpath( dir, name );
50+
51+
# Write the data to the output filepath as JSON:
52+
outfile = open( filepath, "w" );
53+
write( outfile, JSON.json(data) );
54+
write( outfile, "\n" );
55+
close( outfile );
56+
end
57+
58+
# Get the filename:
59+
file = @__FILE__;
60+
61+
# Extract the directory in which this file resides:
62+
dir = dirname( file );
63+
64+
# Generate fixture data for negative values:
65+
x = range( -10.0, stop = 0, length = 1000 );
66+
gen( x, "negative.json" );
67+
68+
# Generate fixture data for positive values:
69+
x = range( 10.0, stop = 0, length = 1000 );
70+
gen( x, "positive.json" );
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 abs = require( '@stdlib/math/base/special/abs' );
26+
var EPS = require( '@stdlib/constants/float64/eps' );
27+
var PINF = require( '@stdlib/constants/float64/pinf' );
28+
var NINF = require( '@stdlib/constants/float64/ninf' );
29+
var sind = require( './../lib' );
30+
31+
32+
// FIXTURES //
33+
34+
var negative = require( './fixtures/julia/negative.json' );
35+
var positive = require( './fixtures/julia/positive.json' );
36+
37+
38+
// TESTS //
39+
40+
tape( 'main export is a function', function test( t ) {
41+
t.ok( true, __filename );
42+
t.true( typeof sind, 'function', 'main export is a function' );
43+
t.end();
44+
});
45+
46+
tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) {
47+
var v = sind( NaN );
48+
t.equal( isnan( v ), true, 'returns expected value' );
49+
t.end();
50+
});
51+
52+
tape( 'the function computes the sine of an angle measured in degrees (negative values)', function test( t ) {
53+
var expected;
54+
var delta;
55+
var tol;
56+
var x;
57+
var y;
58+
var i;
59+
60+
x = negative.x;
61+
expected = negative.expected;
62+
63+
for ( i = 0; i < x.length; i++ ) {
64+
y = sind( x[i] );
65+
if ( y === expected[ i ] ) {
66+
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
67+
} else {
68+
delta = abs( y - expected[i] );
69+
tol = EPS * abs( expected[i] );
70+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
71+
}
72+
}
73+
t.end();
74+
});
75+
76+
tape( 'the function computes the sine of an angle measured in degrees (positive values)', function test( t ) {
77+
var expected;
78+
var delta;
79+
var tol;
80+
var x;
81+
var y;
82+
var i;
83+
84+
x = positive.x;
85+
expected = positive.expected;
86+
87+
for ( i = 0; i < x.length; i++ ) {
88+
y = sind( x[i] );
89+
if ( y === expected[ i ] ) {
90+
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
91+
} else {
92+
delta = abs( y - expected[i] );
93+
tol = EPS * abs( expected[i] );
94+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
95+
}
96+
}
97+
t.end();
98+
});
99+
100+
tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) {
101+
var v = sind( PINF );
102+
t.equal( isnan( v ), true, 'returns expected value' );
103+
t.end();
104+
});
105+
106+
tape( 'if provided `-infinity`, the function returns `NaN`', function test( t ) {
107+
var v = sind( NINF );
108+
t.equal( isnan( v ), true, 'returns expected value' );
109+
t.end();
110+
});
111+
112+
tape( 'if provided a multiple of `180.0`, the function returns `0.0`', function test( t ) {
113+
var v = sind( 180.0 );
114+
t.equal( v, 0.0, 'returns expected value' );
115+
116+
v = sind( -180.0 );
117+
t.equal( v, 0.0, 'returns expected value' );
118+
119+
v = sind( 360.0 );
120+
t.equal( v, 0.0, 'returns expected value' );
121+
122+
t.end();
123+
});
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 PINF = require( '@stdlib/constants/float64/pinf' );
29+
var NINF = require( '@stdlib/constants/float64/ninf' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
32+
33+
// VARIABLES //
34+
35+
var sind = tryRequire( resolve( __dirname, './../lib/native.js' ) );
36+
var opts = {
37+
'skip': ( sind instanceof Error )
38+
};
39+
40+
41+
// FIXTURES //
42+
43+
var negative = require( './fixtures/julia/negative.json' );
44+
var positive = require( './fixtures/julia/positive.json' );
45+
46+
47+
// TESTS //
48+
49+
tape( 'main export is a function', opts, function test( t ) {
50+
t.ok( true, __filename );
51+
t.true( typeof sind, 'function', 'main export is a function' );
52+
t.end();
53+
});
54+
55+
tape( 'if provided a `NaN`, the function returns `NaN`', opts, function test( t ) {
56+
var v = sind( NaN );
57+
t.equal( isnan( v ), true, 'returns expected value' );
58+
t.end();
59+
});
60+
61+
tape( 'the function computes the sine of an angle measured in degrees (negative values)', opts, function test( t ) {
62+
var expected;
63+
var delta;
64+
var tol;
65+
var x;
66+
var y;
67+
var i;
68+
69+
x = negative.x;
70+
expected = negative.expected;
71+
72+
for ( i = 0; i < x.length; i++ ) {
73+
y = sind( x[i] );
74+
if ( y === expected[ i ] ) {
75+
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
76+
} else {
77+
delta = abs( y - expected[i] );
78+
tol = EPS * abs( expected[i] );
79+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
80+
}
81+
}
82+
t.end();
83+
});
84+
85+
tape( 'the function computes the sine of an angle measured in degrees (positive values)', opts, function test( t ) {
86+
var expected;
87+
var delta;
88+
var tol;
89+
var x;
90+
var y;
91+
var i;
92+
93+
x = positive.x;
94+
expected = positive.expected;
95+
96+
for ( i = 0; i < x.length; i++ ) {
97+
y = sind( x[i] );
98+
if ( y === expected[ i ] ) {
99+
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
100+
} else {
101+
delta = abs( y - expected[i] );
102+
tol = EPS * abs( expected[i] );
103+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
104+
}
105+
}
106+
t.end();
107+
});
108+
109+
tape( 'if provided `+infinity`, the function returns `NaN`', opts, function test( t ) {
110+
var v = sind( PINF );
111+
t.equal( isnan( v ), true, 'returns expected value' );
112+
t.end();
113+
});
114+
115+
tape( 'if provided `-infinity`, the function returns `NaN`', opts, function test( t ) {
116+
var v = sind( NINF );
117+
t.equal( isnan( v ), true, 'returns expected value' );
118+
t.end();
119+
});
120+
121+
tape( 'if provided a multiple of `180.0`, the function returns `0.0`', opts, function test( t ) {
122+
var v = sind( 180.0 );
123+
t.equal( v, 0.0, 'returns expected value' );
124+
125+
v = sind( -180.0 );
126+
t.equal( v, 0.0, 'returns expected value' );
127+
128+
v = sind( 360.0 );
129+
t.equal( v, 0.0, 'returns expected value' );
130+
131+
t.end();
132+
});

0 commit comments

Comments
 (0)