|
| 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 ranks = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns an array of numbers... |
| 25 | +{ |
| 26 | + ranks( [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ); // $ExpectType number[] |
| 27 | + ranks( [ 1.1, 2.0, 3.5, 0.0, 2.4 ], { 'encoding': [ NaN ] } ); // $ExpectType number[] |
| 28 | + ranks( [ 1.1, 2.0, 3.5, 0.0, 2.4 ], { 'missing': 'first' } ); // $ExpectType number[] |
| 29 | + ranks( [ 1.1, 2.0, 3.5, 0.0, 2.4 ], { 'method': 'min' } ); // $ExpectType number[] |
| 30 | +} |
| 31 | + |
| 32 | +// The function does not compile if provided a value other than a collection... |
| 33 | +{ |
| 34 | + ranks( true ); // $ExpectError |
| 35 | + ranks( false ); // $ExpectError |
| 36 | + ranks( null ); // $ExpectError |
| 37 | + ranks( undefined ); // $ExpectError |
| 38 | + ranks( 5 ); // $ExpectError |
| 39 | + ranks( {} ); // $ExpectError |
| 40 | +} |
| 41 | + |
| 42 | +// The compiler throws an error if the function is provided a second argument which is not an options object... |
| 43 | +{ |
| 44 | + const arr = [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ; |
| 45 | + ranks( arr, true ); // $ExpectError |
| 46 | + ranks( arr, false ); // $ExpectError |
| 47 | + ranks( arr, null ); // $ExpectError |
| 48 | + ranks( arr, 5 ); // $ExpectError |
| 49 | + ranks( arr, 'abc' ); // $ExpectError |
| 50 | + ranks( arr, ( x: number ): number => x ); // $ExpectError |
| 51 | +} |
| 52 | + |
| 53 | +// The compiler throws an error if the function is provided a `method` option which is not a recognized method... |
| 54 | +{ |
| 55 | + const arr = [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ; |
| 56 | + ranks( arr, { 'method': 'abc' } ); // $ExpectError |
| 57 | + ranks( arr, { 'method': '123' } ); // $ExpectError |
| 58 | + ranks( arr, { 'method': true } ); // $ExpectError |
| 59 | + ranks( arr, { 'method': false } ); // $ExpectError |
| 60 | + ranks( arr, { 'method': null } ); // $ExpectError |
| 61 | + ranks( arr, { 'method': [] } ); // $ExpectError |
| 62 | + ranks( arr, { 'method': {} } ); // $ExpectError |
| 63 | + ranks( arr, { 'method': ( x: number ): number => x } ); // $ExpectError |
| 64 | +} |
| 65 | + |
| 66 | +// The compiler throws an error if the function is provided a `missing` option which is not a recognized missing value directive... |
| 67 | +{ |
| 68 | + const arr = [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ; |
| 69 | + ranks( arr, { 'missing': 'abc' } ); // $ExpectError |
| 70 | + ranks( arr, { 'missing': '123' } ); // $ExpectError |
| 71 | + ranks( arr, { 'missing': true } ); // $ExpectError |
| 72 | + ranks( arr, { 'missing': false } ); // $ExpectError |
| 73 | + ranks( arr, { 'missing': null } ); // $ExpectError |
| 74 | + ranks( arr, { 'missing': [] } ); // $ExpectError |
| 75 | + ranks( arr, { 'missing': {} } ); // $ExpectError |
| 76 | + ranks( arr, { 'missing': ( x: number ): number => x } ); // $ExpectError |
| 77 | +} |
| 78 | + |
| 79 | +// The compiler throws an error if the function is provided an `encoding` option which is not an array... |
| 80 | +{ |
| 81 | + const arr = [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ; |
| 82 | + ranks( arr, { 'encoding': 'abc' } ); // $ExpectError |
| 83 | + ranks( arr, { 'encoding': '123' } ); // $ExpectError |
| 84 | + ranks( arr, { 'encoding': true } ); // $ExpectError |
| 85 | + ranks( arr, { 'encoding': false } ); // $ExpectError |
| 86 | + ranks( arr, { 'encoding': null } ); // $ExpectError |
| 87 | + ranks( arr, { 'encoding': {} } ); // $ExpectError |
| 88 | + ranks( arr, { 'encoding': ( x: number ): number => x } ); // $ExpectError |
| 89 | +} |
| 90 | + |
| 91 | +// The function does not compile if provided an invalid number of arguments... |
| 92 | +{ |
| 93 | + const arr = [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ; |
| 94 | + ranks(); // $ExpectError |
| 95 | + ranks( arr, {}, {} ); // $ExpectError |
| 96 | +} |
0 commit comments