|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2019 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 cdf = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a number... |
| 25 | +{ |
| 26 | + cdf( 2, 2, 4 ); // $ExpectType number |
| 27 | + cdf( 1, 2, 8 ); // $ExpectType number |
| 28 | +} |
| 29 | + |
| 30 | +// The compiler throws an error if the function is provided values other than three numbers... |
| 31 | +{ |
| 32 | + cdf( true, 3, 6 ); // $ExpectError |
| 33 | + cdf( false, 2, 4 ); // $ExpectError |
| 34 | + cdf( '5', 1, 2 ); // $ExpectError |
| 35 | + cdf( [], 1, 2 ); // $ExpectError |
| 36 | + cdf( {}, 2, 4 ); // $ExpectError |
| 37 | + cdf( ( x: number ): number => x, 2, 4 ); // $ExpectError |
| 38 | + |
| 39 | + cdf( 9, true, 12 ); // $ExpectError |
| 40 | + cdf( 9, false, 12 ); // $ExpectError |
| 41 | + cdf( 5, '5', 10 ); // $ExpectError |
| 42 | + cdf( 8, [], 16 ); // $ExpectError |
| 43 | + cdf( 9, {}, 18 ); // $ExpectError |
| 44 | + cdf( 8, ( x: number ): number => x, 16 ); // $ExpectError |
| 45 | + |
| 46 | + cdf( 9, 5, true ); // $ExpectError |
| 47 | + cdf( 9, 5, false ); // $ExpectError |
| 48 | + cdf( 5, 2, '5' ); // $ExpectError |
| 49 | + cdf( 8, 4, [] ); // $ExpectError |
| 50 | + cdf( 9, 4, {} ); // $ExpectError |
| 51 | + cdf( 8, 5, ( x: number ): number => x ); // $ExpectError |
| 52 | +} |
| 53 | + |
| 54 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 55 | +{ |
| 56 | + cdf(); // $ExpectError |
| 57 | + cdf( 2 ); // $ExpectError |
| 58 | + cdf( 2, 0 ); // $ExpectError |
| 59 | + cdf( 2, 0, 4, 1 ); // $ExpectError |
| 60 | +} |
| 61 | + |
| 62 | +// Attached to main export is a `factory` method which returns a function... |
| 63 | +{ |
| 64 | + cdf.factory( 3, 4 ); // $ExpectType Unary |
| 65 | +} |
| 66 | + |
| 67 | +// The `factory` method returns a function which returns an number... |
| 68 | +{ |
| 69 | + const fcn = cdf.factory( 3, 4 ); |
| 70 | + fcn( 2 ); // $ExpectType number |
| 71 | +} |
| 72 | + |
| 73 | +// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... |
| 74 | +{ |
| 75 | + const fcn = cdf.factory( 3, 4 ); |
| 76 | + fcn( true ); // $ExpectError |
| 77 | + fcn( false ); // $ExpectError |
| 78 | + fcn( '5' ); // $ExpectError |
| 79 | + fcn( [] ); // $ExpectError |
| 80 | + fcn( {} ); // $ExpectError |
| 81 | + fcn( ( x: number ): number => x ); // $ExpectError |
| 82 | +} |
| 83 | + |
| 84 | +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... |
| 85 | +{ |
| 86 | + const fcn = cdf.factory( 3, 4 ); |
| 87 | + fcn(); // $ExpectError |
| 88 | + fcn( 2, 0 ); // $ExpectError |
| 89 | + fcn( 2, 0, 1 ); // $ExpectError |
| 90 | +} |
| 91 | + |
| 92 | +// The compiler throws an error if the `factory` method is provided values other than two numbers... |
| 93 | +{ |
| 94 | + cdf.factory( true, 3 ); // $ExpectError |
| 95 | + cdf.factory( false, 2 ); // $ExpectError |
| 96 | + cdf.factory( '5', 1 ); // $ExpectError |
| 97 | + cdf.factory( [], 1 ); // $ExpectError |
| 98 | + cdf.factory( {}, 2 ); // $ExpectError |
| 99 | + cdf.factory( ( x: number ): number => x, 2 ); // $ExpectError |
| 100 | + |
| 101 | + cdf.factory( 9, true ); // $ExpectError |
| 102 | + cdf.factory( 9, false ); // $ExpectError |
| 103 | + cdf.factory( 5, '5' ); // $ExpectError |
| 104 | + cdf.factory( 8, [] ); // $ExpectError |
| 105 | + cdf.factory( 9, {} ); // $ExpectError |
| 106 | + cdf.factory( 8, ( x: number ): number => x ); // $ExpectError |
| 107 | + |
| 108 | + cdf.factory( [], true ); // $ExpectError |
| 109 | + cdf.factory( {}, false ); // $ExpectError |
| 110 | + cdf.factory( false, '5' ); // $ExpectError |
| 111 | + cdf.factory( {}, [] ); // $ExpectError |
| 112 | + cdf.factory( '5', ( x: number ): number => x ); // $ExpectError |
| 113 | +} |
| 114 | + |
| 115 | +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... |
| 116 | +{ |
| 117 | + cdf.factory( 0 ); // $ExpectError |
| 118 | + cdf.factory( 0, 4, 8 ); // $ExpectError |
| 119 | +} |
0 commit comments