|
| 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 | +}); |
0 commit comments