Skip to content

Commit 4a15e2e

Browse files
feat: tests added
1 parent 845b876 commit 4a15e2e

File tree

7 files changed

+551
-0
lines changed

7 files changed

+551
-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/atan2f/test/fixtures/julia/negative_negative.json

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

lib/node_modules/@stdlib/math/base/special/atan2f/test/fixtures/julia/negative_positive.json

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

lib/node_modules/@stdlib/math/base/special/atan2f/test/fixtures/julia/positive_positive.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env julia
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2024 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( x, y, name )
23+
24+
Generate fixture data and write to file.
25+
26+
# Arguments
27+
28+
* `x`: denominator domain
29+
* `y`: numerator domain
30+
* `name::AbstractString`: output filename
31+
32+
# Examples
33+
34+
``` julia
35+
julia> x = range( -1000.0, stop = 1000.0, length = 2001 );
36+
julia> y = range( 0.0, stop = 1000.0, length = 1001 );
37+
julia> gen( x, y, \"data.json\" );
38+
```
39+
"""
40+
function gen( x, y, name )
41+
z = Array{Float64}( undef, length(x) );
42+
for i in eachindex(x)
43+
z[ i ] = atan2.( y[i], x[i] );
44+
end
45+
46+
# Store data to be written to file as a collection:
47+
data = Dict([
48+
("x", x),
49+
("y", y),
50+
("expected", z)
51+
]);
52+
53+
# Based on the script directory, create an output filepath:
54+
filepath = joinpath( dir, name );
55+
56+
# Write the data to the output filepath as JSON:
57+
outfile = open( filepath, "w" );
58+
write( outfile, JSON.json(data) );
59+
write( outfile, "\n" );
60+
close( outfile );
61+
end
62+
63+
# Get the filename:
64+
file = @__FILE__;
65+
66+
# Extract the directory in which this file resides:
67+
dir = dirname( file );
68+
69+
# Random (x positive, y positive):
70+
x = rand( 5001 ) .* 500.0;
71+
y = rand( 5001 ) .* 500.0;
72+
gen( x, y, "positive_positive.json" );
73+
74+
# Random (x negative, y positive):
75+
x = -rand( 1001 ) .* 500.0;
76+
y = rand( 1001 ) .* 500.0;
77+
gen( x, y, "negative_positive.json" );
78+
79+
# Random (x negative, y negative):
80+
x = -rand( 1001 ) .* 500.0;
81+
y = -rand( 1001 ) .* 500.0;
82+
gen( x, y, "negative_negative.json" );
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
26+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
27+
var abs = require( '@stdlib/math/base/special/abs' );
28+
var EPS = require( '@stdlib/constants/float64/eps' );
29+
var PINF = require( '@stdlib/constants/float64/pinf' );
30+
var NINF = require( '@stdlib/constants/float64/ninf' );
31+
var PI = require( '@stdlib/constants/float64/pi' );
32+
var atan2f = require( './../lib' );
33+
34+
35+
// FIXTURES //
36+
37+
var positivePositive = require( './fixtures/julia/positive_positive.json' );
38+
var negativePositive = require( './fixtures/julia/negative_positive.json' );
39+
var negativeNegative = require( './fixtures/julia/negative_negative.json' );
40+
41+
42+
// TESTS //
43+
44+
tape( 'main export is a function', function test( t ) {
45+
t.ok( true, __filename );
46+
t.strictEqual( typeof atan2f, 'function', 'main export is a function' );
47+
t.end();
48+
});
49+
50+
tape( 'the function has two parameters: a numerator and a denominator value', function test( t ) {
51+
t.equal( atan2f.length, 2.0, 'arity is 2' );
52+
t.end();
53+
});
54+
55+
tape( 'the function returns `NaN` if provided `NaN` as either of the arguments', function test( t ) {
56+
t.equal( isnanf( atan2f( 2.0, NaN ) ), true, 'returns NaN' );
57+
t.equal( isnanf( atan2f( NaN, 3.0 ) ), true, 'returns NaN' );
58+
t.end();
59+
});
60+
61+
tape( 'the function returns `+0` if provided `y = +0.0` and `x >= 0`', function test( t ) {
62+
t.equal( isPositiveZero( atan2f( +0.0, 0.0 ) ), true, 'returns +0' );
63+
t.equal( isPositiveZero( atan2f( +0.0, 2.0 ) ), true, 'returns +0' );
64+
t.equal( isPositiveZero( atan2f( +0.0, 4.0 ) ), true, 'returns +0' );
65+
t.equal( isPositiveZero( atan2f( +0.0, 5.0 ) ), true, 'returns +0' );
66+
t.equal( isPositiveZero( atan2f( +0.0, 10.0 ) ), true, 'returns +0' );
67+
t.end();
68+
});
69+
70+
tape( 'the function returns `-0` if provided `y = -0.0` and `x >= 0`', function test( t ) {
71+
t.equal( isNegativeZero( atan2f( -0.0, 0.0 ) ), true, 'returns -0' );
72+
t.equal( isNegativeZero( atan2f( -0.0, 2.0 ) ), true, 'returns -0' );
73+
t.equal( isNegativeZero( atan2f( -0.0, 4.0 ) ), true, 'returns -0' );
74+
t.equal( isNegativeZero( atan2f( -0.0, 5.0 ) ), true, 'returns -0' );
75+
t.equal( isNegativeZero( atan2f( -0.0, 10.0 ) ), true, 'returns -0' );
76+
t.end();
77+
});
78+
79+
tape( 'the function returns `PI` if provided `y = +0.0` and `x <= -0.0`', function test( t ) {
80+
t.equal( atan2f( +0.0, -0.0 ), +PI, 'returns +PI' );
81+
t.equal( atan2f( +0.0, -2.0 ), +PI, 'returns +PI' );
82+
t.equal( atan2f( +0.0, -4.0 ), +PI, 'returns +PI' );
83+
t.equal( atan2f( +0.0, -5.0 ), +PI, 'returns +PI' );
84+
t.equal( atan2f( +0.0, -10.0 ), +PI, 'returns +PI' );
85+
t.end();
86+
});
87+
88+
tape( 'the function returns `-PI` if provided `y = -0.0` and `x <= -0.0`', function test( t ) {
89+
t.equal( atan2f( -0.0, -0.0 ), -PI, 'returns -PI' );
90+
t.equal( atan2f( -0.0, -2.0 ), -PI, 'returns -PI' );
91+
t.equal( atan2f( -0.0, -4.0 ), -PI, 'returns -PI' );
92+
t.equal( atan2f( -0.0, -5.0 ), -PI, 'returns -PI' );
93+
t.equal( atan2f( -0.0, -10.0 ), -PI, 'returns -PI' );
94+
t.end();
95+
});
96+
97+
tape( 'the function returns `+PI/4` if provided `x = y = +infinity`', function test( t ) {
98+
t.equal( atan2f( PINF, PINF ), +PI/4.0, 'returns +PI/4' );
99+
t.end();
100+
});
101+
102+
tape( 'the function returns `-PI/4` if provided `x = -y = +infinity`', function test( t ) {
103+
t.equal( atan2f( NINF, PINF ), -PI/4.0, 'returns -PI/4' );
104+
t.end();
105+
});
106+
107+
tape( 'the function returns `*3*PI/4` if provided `-x = y = +infinity`', function test( t ) {
108+
t.equal( atan2f( PINF, NINF ), +3.0*PI/4.0, 'returns +3*PI/4' );
109+
t.end();
110+
});
111+
112+
tape( 'the function returns `-3*PI/4` if provided `x = y = -infinity`', function test( t ) {
113+
t.equal( atan2f( NINF, NINF ), -3.0*PI/4.0, 'returns -3*PI/4' );
114+
t.end();
115+
});
116+
117+
tape( 'the function returns `0.0` when `x = +infinity`', function test( t ) {
118+
t.equal( atan2f( -2.0, PINF ), 0.0, 'returns 0.0' );
119+
t.equal( atan2f( 0.0, PINF ), 0.0, 'returns 0.0' );
120+
t.equal( atan2f( 2.0, PINF ), 0.0, 'returns 0.0' );
121+
t.end();
122+
});
123+
124+
tape( 'the function returns `+PI` when `y > 0` and `x = -infinity`', function test( t ) {
125+
t.equal( atan2f( 1.0, NINF ), PI, 'returns PI' );
126+
t.equal( atan2f( 2.0, NINF ), PI, 'returns PI' );
127+
t.equal( atan2f( 3.0, NINF ), PI, 'returns PI' );
128+
t.end();
129+
});
130+
131+
tape( 'the function returns `-PI` when `y < 0` and `x = -infinity`', function test( t ) {
132+
t.equal( atan2f( -1.0, NINF ), -PI, 'returns -PI' );
133+
t.equal( atan2f( -2.0, NINF ), -PI, 'returns -PI' );
134+
t.equal( atan2f( -3.0, NINF ), -PI, 'returns -PI' );
135+
t.end();
136+
});
137+
138+
tape( 'the function returns `+PI/2` when `y = +infinity`', function test( t ) {
139+
t.equal( atan2f( PINF, -1.0 ), PI/2.0, 'returns PI/2' );
140+
t.equal( atan2f( PINF, 0.0 ), PI/2.0, 'returns PI/2' );
141+
t.equal( atan2f( PINF, 2.0 ), PI/2.0, 'returns PI/2' );
142+
t.end();
143+
});
144+
145+
tape( 'the function returns `-PI/2` when `y = -infinity`', function test( t ) {
146+
t.equal( atan2f( NINF, -1.0 ), -PI/2.0, 'returns -PI/2' );
147+
t.equal( atan2f( NINF, 0.0 ), -PI/2.0, 'returns -PI/2' );
148+
t.equal( atan2f( NINF, 2.0 ), -PI/2.0, 'returns -PI/2' );
149+
t.end();
150+
});
151+
152+
tape( 'the function returns `PI/2` if provided a positive `y` and `x=0`', function test( t ) {
153+
t.equal( atan2f( 2.0, 0.0 ), PI/2.0, 'returns PI/2' );
154+
t.equal( atan2f( 1.0, 0.0 ), PI/2.0, 'returns PI/2' );
155+
t.equal( atan2f( 0.5, 0.0 ), PI/2.0, 'returns PI/2' );
156+
t.end();
157+
});
158+
159+
tape( 'the function returns `-PI/2` if provided a negative `y` and `x=0`', function test( t ) {
160+
t.equal( atan2f( -2.0, 0.0 ), -PI/2.0, 'returns PI/2' );
161+
t.equal( atan2f( -1.0, 0.0 ), -PI/2.0, 'returns PI/2' );
162+
t.equal( atan2f( -0.5, 0.0 ), -PI/2.0, 'returns PI/2' );
163+
t.end();
164+
});
165+
166+
tape( 'the function evaluates the `atan2` function (when x and y are positive)', function test( t ) {
167+
var expected;
168+
var actual;
169+
var delta;
170+
var tol;
171+
var x;
172+
var y;
173+
var i;
174+
175+
y = positivePositive.y;
176+
x = positivePositive.x;
177+
expected = positivePositive.expected;
178+
for ( i = 0; i < x.length; i++ ) {
179+
actual = atan2f( y[i], x[i] );
180+
delta = abs( actual - expected[i] );
181+
tol = EPS * abs( expected[i] );
182+
t.equal( delta <= tol, true, 'within tolerance. y: '+y[i]+'. x: '+x[i]+'. Actual: '+actual+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
183+
}
184+
t.end();
185+
});
186+
187+
tape( 'the function evaluates the `atan2` function (when x is negative and y is positive)', function test( t ) {
188+
var expected;
189+
var actual;
190+
var delta;
191+
var tol;
192+
var x;
193+
var y;
194+
var i;
195+
196+
y = negativePositive.y;
197+
x = negativePositive.x;
198+
expected = negativePositive.expected;
199+
for ( i = 0; i < x.length; i++ ) {
200+
actual = atan2f( y[i], x[i] );
201+
delta = abs( actual - expected[i] );
202+
tol = 2.0 * EPS * abs( expected[i] );
203+
t.equal( delta <= tol, true, 'within tolerance. y: '+y[i]+'. x: '+x[i]+'. Actual: '+actual+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
204+
}
205+
t.end();
206+
});
207+
208+
tape( 'the function evaluates the `atan2` function (when x and y are negative)', function test( t ) {
209+
var expected;
210+
var actual;
211+
var delta;
212+
var tol;
213+
var x;
214+
var y;
215+
var i;
216+
217+
y = negativeNegative.y;
218+
x = negativeNegative.x;
219+
expected = negativeNegative.expected;
220+
for ( i = 0; i < x.length; i++ ) {
221+
actual = atan2f( y[i], x[i] );
222+
delta = abs( actual - expected[i] );
223+
tol = 2.0 * EPS * abs( expected[i] );
224+
t.equal( delta <= tol, true, 'within tolerance. y: '+y[i]+'. x: '+x[i]+'. Actual: '+actual+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
225+
}
226+
t.end();
227+
});

0 commit comments

Comments
 (0)