|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2021 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 | +import continuedFraction = require( './index' ); |
| 20 | + |
| 21 | +/** |
| 22 | +* Continued fraction for (e-1)^(-1). |
| 23 | +*/ |
| 24 | +function* generator() { |
| 25 | + let i = 0; |
| 26 | + while ( true ) { |
| 27 | + i += 1; |
| 28 | + yield [ i, i ]; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// TESTS // |
| 33 | + |
| 34 | +// The function returns a number... |
| 35 | +{ |
| 36 | + continuedFraction( generator ); // $ExpectType number |
| 37 | + const opts = { |
| 38 | + 'keep': true, |
| 39 | + 'maxIter': 500, |
| 40 | + 'tolerance': 1e-6 |
| 41 | + }; |
| 42 | + continuedFraction( generator, opts ); // $ExpectType number |
| 43 | +} |
| 44 | + |
| 45 | +// The compiler throws an error if the function is provided a first argument which is not a function... |
| 46 | +{ |
| 47 | + continuedFraction( 'abc' ); // $ExpectError |
| 48 | + continuedFraction( 123 ); // $ExpectError |
| 49 | + continuedFraction( false ); // $ExpectError |
| 50 | + continuedFraction( true ); // $ExpectError |
| 51 | + continuedFraction( [] ); // $ExpectError |
| 52 | + continuedFraction( {} ); // $ExpectError |
| 53 | +} |
| 54 | + |
| 55 | +// The compiler throws an error if the function is provided a `keep` option which is not a boolean... |
| 56 | +{ |
| 57 | + continuedFraction( generator, { 'keep': 'abc' } ); // $ExpectError |
| 58 | + continuedFraction( generator, { 'keep': 123 } ); // $ExpectError |
| 59 | + continuedFraction( generator, { 'keep': null } ); // $ExpectError |
| 60 | + continuedFraction( generator, { 'keep': [] } ); // $ExpectError |
| 61 | + continuedFraction( generator, { 'keep': {} } ); // $ExpectError |
| 62 | + continuedFraction( generator, { 'keep': ( x: number ): number => x } ); // $ExpectError |
| 63 | +} |
| 64 | + |
| 65 | +// The compiler throws an error if the function is provided a `maxIter` option which is not a number... |
| 66 | +{ |
| 67 | + continuedFraction( generator, { 'maxIter': 'abc' } ); // $ExpectError |
| 68 | + continuedFraction( generator, { 'maxIter': true } ); // $ExpectError |
| 69 | + continuedFraction( generator, { 'maxIter': false } ); // $ExpectError |
| 70 | + continuedFraction( generator, { 'maxIter': null } ); // $ExpectError |
| 71 | + continuedFraction( generator, { 'maxIter': [] } ); // $ExpectError |
| 72 | + continuedFraction( generator, { 'maxIter': {} } ); // $ExpectError |
| 73 | + continuedFraction( generator, { 'maxIter': ( x: number ): number => x } ); // $ExpectError |
| 74 | +} |
| 75 | + |
| 76 | +// The compiler throws an error if the function is provided a `tolerance` option which is not a number... |
| 77 | +{ |
| 78 | + continuedFraction( generator, { 'tolerance': 'abc' } ); // $ExpectError |
| 79 | + continuedFraction( generator, { 'tolerance': true } ); // $ExpectError |
| 80 | + continuedFraction( generator, { 'tolerance': false } ); // $ExpectError |
| 81 | + continuedFraction( generator, { 'tolerance': null } ); // $ExpectError |
| 82 | + continuedFraction( generator, { 'tolerance': [] } ); // $ExpectError |
| 83 | + continuedFraction( generator, { 'tolerance': {} } ); // $ExpectError |
| 84 | + continuedFraction( generator, { 'tolerance': ( x: number ): number => x } ); // $ExpectError |
| 85 | +} |
| 86 | + |
| 87 | +// The compiler throws an error if the function is provided insufficient arguments... |
| 88 | +{ |
| 89 | + continuedFraction(); // $ExpectError |
| 90 | +} |
0 commit comments