Skip to content

Commit 35af1ff

Browse files
author
aayush0325
committed
feat: tests added
1 parent cabf621 commit 35af1ff

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var absf = require( '@stdlib/math/base/special/absf' );
27+
var NINF = require( '@stdlib/constants/float64/ninf' );
28+
var lucas = require( '@stdlib/math/base/special/lucas' );
29+
var negalucasf = require( './../lib' );
30+
31+
32+
// FIXTURES //
33+
34+
var NEGALUCAS = require( './../lib/negalucas.json' );
35+
36+
37+
// TESTS //
38+
39+
tape( 'main export is a function', function test( t ) {
40+
t.ok( true, __filename );
41+
t.strictEqual( typeof negalucasf, 'function', 'main export is a function' );
42+
t.end();
43+
});
44+
45+
tape( 'if provided a positive number, the function returns `NaN`', function test( t ) {
46+
var v;
47+
var i;
48+
49+
t.strictEqual( isnanf( negalucasf( 3.14 ) ), true, 'returns NaN' );
50+
51+
for ( i = 1; i < 100; i++ ) {
52+
v = negalucasf( i );
53+
t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i );
54+
}
55+
t.end();
56+
});
57+
58+
tape( 'if provided negative infinity, the function returns `NaN`', function test( t ) {
59+
var v = negalucasf( NINF );
60+
t.strictEqual( isnanf( v ), true, 'returns NaN when provided -infinity' );
61+
t.end();
62+
});
63+
64+
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
65+
var v = negalucasf( NaN );
66+
t.strictEqual( isnanf( v ), true, 'returns NaN when provided a NaN' );
67+
t.end();
68+
});
69+
70+
tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) {
71+
var v = negalucasf( -3.14 );
72+
t.strictEqual( isnanf( v ), true, 'returns NaN' );
73+
t.end();
74+
});
75+
76+
tape( 'the function returns the nth negaLucas number', function test( t ) {
77+
var v;
78+
var i;
79+
for ( i = 0; i > -35; i-- ) {
80+
v = negalucasf( i );
81+
t.strictEqual( v, NEGALUCAS[ absf(i) ], 'returns the '+i+'th negaLucas number' );
82+
}
83+
t.end();
84+
});
85+
86+
tape( 'the function returns the nth negaLucas number (Lucas relationship)', function test( t ) {
87+
var v;
88+
var f;
89+
var i;
90+
for ( i = 0; i > -35; i-- ) {
91+
v = negalucasf( i );
92+
f = pow( -1.0, absf(i) ) * lucas( absf(i) );
93+
t.strictEqual( v, f, 'returns the '+i+'th negaLucas number' );
94+
}
95+
t.end();
96+
});
97+
98+
tape( 'if provided nonpositive integers less than `-34`, the function returns `NaN`', function test( t ) {
99+
var i;
100+
var v;
101+
for ( i = -35; i > -500; i-- ) {
102+
v = negalucasf( i );
103+
t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i );
104+
}
105+
t.end();
106+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var absf = require( '@stdlib/math/base/special/absf' );
28+
var lucas = require( '@stdlib/math/base/special/lucas' );
29+
var tryRequire = require( '@stdlib/utils/try-require' );
30+
31+
32+
// FIXTURES //
33+
34+
var NEGALUCAS = require( './../lib/negalucas.json' );
35+
36+
37+
// VARIABLES //
38+
39+
var negalucasf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
40+
var opts = {
41+
'skip': ( negalucasf instanceof Error )
42+
};
43+
44+
45+
// TESTS //
46+
47+
tape( 'main export is a function', opts, function test( t ) {
48+
t.ok( true, __filename );
49+
t.strictEqual( typeof negalucasf, 'function', 'main export is a function' );
50+
t.end();
51+
});
52+
53+
tape( 'if provided a positive number, the function returns `NaN`', opts, function test( t ) {
54+
var v;
55+
var i;
56+
57+
for ( i = 1; i < 100; i++ ) {
58+
v = negalucasf( i );
59+
t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i );
60+
}
61+
t.end();
62+
});
63+
64+
tape( 'the function returns the nth negaLucas number', opts, function test( t ) {
65+
var v;
66+
var i;
67+
for ( i = 0; i > -35; i-- ) {
68+
v = negalucasf( i );
69+
t.strictEqual( v, NEGALUCAS[ absf( i ) ], 'returns the '+i+'th negaLucas number' );
70+
}
71+
t.end();
72+
});
73+
74+
tape( 'the function returns the nth negaLucas number (Lucas relationship)', opts, function test( t ) {
75+
var v;
76+
var f;
77+
var i;
78+
for ( i = 0; i > -35; i-- ) {
79+
v = negalucasf( i );
80+
f = pow( -1.0, absf(i) ) * lucas( absf(i) );
81+
t.strictEqual( v, f, 'returns the '+i+'th negaLucas number' );
82+
}
83+
t.end();
84+
});
85+
86+
tape( 'if provided nonpositive integers less than `-34`, the function returns `NaN`', opts, function test( t ) {
87+
var i;
88+
var v;
89+
for ( i = -35; i > -500; i-- ) {
90+
v = negalucasf( i );
91+
t.strictEqual( isnanf( v ), true, 'returns NaN when provided ' + i );
92+
}
93+
t.end();
94+
});

0 commit comments

Comments
 (0)