Skip to content

Commit 9c5c475

Browse files
committed
"added test.js"
1 parent 4212a00 commit 9c5c475

File tree

1 file changed

+188
-0
lines changed
  • lib/node_modules/@stdlib/math/base/special/cosc/test

1 file changed

+188
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 PINF = require( '@stdlib/constants/float64/pinf' );
26+
var NINF = require( '@stdlib/constants/float64/ninf' );
27+
var EPS = require( '@stdlib/constants/float64/eps' );
28+
var abs = require( '@stdlib/math/base/special/abs' );
29+
var cosc = require( './../lib' );
30+
31+
32+
// FIXTURES //
33+
34+
var data = require( './fixtures/julia/data.json' );
35+
var largeNegative = require( './fixtures/julia/large_negative.json' );
36+
var largePositive = require( './fixtures/julia/large_positive.json' );
37+
var tinyNegative = require( './fixtures/julia/tiny_negative.json' );
38+
var tinyPositive = require( './fixtures/julia/tiny_positive.json' );
39+
40+
41+
// TESTS //
42+
43+
tape( 'main export is a function', function test( t ) {
44+
t.ok( true, __filename );
45+
t.strictEqual( typeof sinc, 'function', 'main export is a function' );
46+
t.end();
47+
});
48+
49+
tape( 'the function computes the derivative of cardinal sine', function test( t ) {
50+
var expected;
51+
var delta;
52+
var tol;
53+
var x;
54+
var y;
55+
var i;
56+
57+
x = data.x;
58+
expected = data.expected;
59+
60+
for ( i = 0; i < x.length; i++ ) {
61+
y = cosc( x[i] );
62+
if ( y === expected[ i ] ) {
63+
t.equal( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
64+
} else {
65+
delta = abs( y - expected[i] );
66+
tol = 2.0 * EPS * abs( expected[i] );
67+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' );
68+
}
69+
}
70+
t.end();
71+
});
72+
73+
tape( 'the function computes the derivative of cardinal sine (large negative)', function test( t ) {
74+
var expected;
75+
var delta;
76+
var tol;
77+
var x;
78+
var y;
79+
var i;
80+
81+
x = largeNegative.x;
82+
expected = largeNegative.expected;
83+
84+
for ( i = 0; i < x.length; i++ ) {
85+
y = cosc( x[i] );
86+
if ( y === expected[ i ] ) {
87+
t.equal( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
88+
} else {
89+
delta = abs( y - expected[i] );
90+
tol = 2.0 * EPS * abs( expected[i] );
91+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' );
92+
}
93+
}
94+
t.end();
95+
});
96+
97+
tape( 'the function computes the derivative of cardinal sine (large positive)', function test( t ) {
98+
var expected;
99+
var delta;
100+
var tol;
101+
var x;
102+
var y;
103+
var i;
104+
105+
x = largePositive.x;
106+
expected = largePositive.expected;
107+
108+
for ( i = 0; i < x.length; i++ ) {
109+
y = cosc( x[i] );
110+
if ( y === expected[ i ] ) {
111+
t.equal( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
112+
} else {
113+
delta = abs( y - expected[i] );
114+
tol = 2.0 * EPS * abs( expected[i] );
115+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' );
116+
}
117+
}
118+
t.end();
119+
});
120+
121+
tape( 'the function computes the derivative of cardinal sine (tiny negative)', function test( t ) {
122+
var expected;
123+
var delta;
124+
var tol;
125+
var x;
126+
var y;
127+
var i;
128+
129+
x = tinyNegative.x;
130+
expected = tinyNegative.expected;
131+
132+
for ( i = 0; i < x.length; i++ ) {
133+
y = cosc( x[i] );
134+
if ( y === expected[ i ] ) {
135+
t.equal( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
136+
} else {
137+
delta = abs( y - expected[i] );
138+
tol = EPS * abs( expected[i] );
139+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' );
140+
}
141+
}
142+
t.end();
143+
});
144+
145+
tape( 'the function computes the derivative of cardinal sine (tiny positive)', function test( t ) {
146+
var expected;
147+
var delta;
148+
var tol;
149+
var x;
150+
var y;
151+
var i;
152+
153+
x = tinyPositive.x;
154+
expected = tinyPositive.expected;
155+
156+
for ( i = 0; i < x.length; i++ ) {
157+
y = cosc( x[i] );
158+
if ( y === expected[ i ] ) {
159+
t.equal( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
160+
} else {
161+
delta = abs( y - expected[i] );
162+
tol = EPS * abs( expected[i] );
163+
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' );
164+
}
165+
}
166+
t.end();
167+
});
168+
169+
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
170+
var v = cosc( NaN );
171+
t.equal( isnan( v ), true, 'returns NaN' );
172+
t.end();
173+
});
174+
175+
tape( 'the function returns `0.0` if provided `0.0`', function test( t ) {
176+
var v = cosc( 0.0 );
177+
t.equal( v, 0.0, 'returns 0.0' );
178+
t.end();
179+
});
180+
181+
tape( 'the function returns `0.0` if provided positive or negative infinity', function test( t ) {
182+
var v = cosc( PINF );
183+
t.equal( v, 0.0, 'returns 0.0' );
184+
185+
v = cosc( NINF );
186+
t.equal( v, 0.0, 'returns 0.0' );
187+
t.end();
188+
});

0 commit comments

Comments
 (0)