|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 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 at3d = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns an array element... |
| 25 | +{ |
| 26 | + const x = [ [ [ 1, 2 ], [ 3, 4 ] ] ]; |
| 27 | + |
| 28 | + at3d( x, 0, 0, 0 ); // $ExpectType number | void |
| 29 | +} |
| 30 | + |
| 31 | +// The compiler throws an error if the function is provided a first argument which is not a nested array... |
| 32 | +{ |
| 33 | + at3d( 'abc', 0, 0, 0 ); // $ExpectError |
| 34 | + at3d( 5, 0, 0, 0 ); // $ExpectError |
| 35 | + at3d( true, 0, 0, 0 ); // $ExpectError |
| 36 | + at3d( false, 0, 0, 0 ); // $ExpectError |
| 37 | + at3d( null, 0, 0, 0 ); // $ExpectError |
| 38 | + at3d( void 0, 0, 0, 0 ); // $ExpectError |
| 39 | + at3d( {}, 0, 0, 0 ); // $ExpectError |
| 40 | + at3d( ( x: number ): number => x, 0, 0, 0 ); // $ExpectError |
| 41 | +} |
| 42 | + |
| 43 | +// The compiler throws an error if the function is provided a second argument which is not a number... |
| 44 | +{ |
| 45 | + const x = [ [ [ 1, 2 ], [ 3, 4 ] ] ]; |
| 46 | + |
| 47 | + at3d( x, 'abc', 0, 0 ); // $ExpectError |
| 48 | + at3d( x, true, 0, 0 ); // $ExpectError |
| 49 | + at3d( x, false, 0, 0 ); // $ExpectError |
| 50 | + at3d( x, null, 0, 0 ); // $ExpectError |
| 51 | + at3d( x, void 0, 0, 0 ); // $ExpectError |
| 52 | + at3d( x, [ '1' ], 0, 0 ); // $ExpectError |
| 53 | + at3d( x, {}, 0, 0 ); // $ExpectError |
| 54 | + at3d( x, ( x: number ): number => x, 0, 0 ); // $ExpectError |
| 55 | +} |
| 56 | + |
| 57 | +// The compiler throws an error if the function is provided a third argument which is not a number... |
| 58 | +{ |
| 59 | + const x = [ [ [ 1, 2 ], [ 3, 4 ] ] ]; |
| 60 | + |
| 61 | + at3d( x, 0, 'abc', 0 ); // $ExpectError |
| 62 | + at3d( x, 0, true, 0 ); // $ExpectError |
| 63 | + at3d( x, 0, false, 0 ); // $ExpectError |
| 64 | + at3d( x, 0, null, 0 ); // $ExpectError |
| 65 | + at3d( x, 0, void 0, 0 ); // $ExpectError |
| 66 | + at3d( x, 0, [ '1' ], 0 ); // $ExpectError |
| 67 | + at3d( x, 0, {}, 0 ); // $ExpectError |
| 68 | + at3d( x, 0, ( x: number ): number => x, 0 ); // $ExpectError |
| 69 | +} |
| 70 | + |
| 71 | +// The compiler throws an error if the function is provided a fourth argument which is not a number... |
| 72 | +{ |
| 73 | + const x = [ [ [ 1, 2 ], [ 3, 4 ] ] ]; |
| 74 | + |
| 75 | + at3d( x, 0, 0, 'abc' ); // $ExpectError |
| 76 | + at3d( x, 0, 0, true ); // $ExpectError |
| 77 | + at3d( x, 0, 0, false ); // $ExpectError |
| 78 | + at3d( x, 0, 0, null ); // $ExpectError |
| 79 | + at3d( x, 0, 0, void 0 ); // $ExpectError |
| 80 | + at3d( x, 0, 0, [ '1' ] ); // $ExpectError |
| 81 | + at3d( x, 0, 0, {} ); // $ExpectError |
| 82 | + at3d( x, 0, 0, ( x: number ): number => x ); // $ExpectError |
| 83 | +} |
| 84 | + |
| 85 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 86 | +{ |
| 87 | + const x = [ [ [ 1, 2 ], [ 3, 4 ] ] ]; |
| 88 | + |
| 89 | + at3d(); // $ExpectError |
| 90 | + at3d( x ); // $ExpectError |
| 91 | + at3d( x, 0 ); // $ExpectError |
| 92 | + at3d( x, 0, 0 ); // $ExpectError |
| 93 | + at3d( x, 0, 0, 0, 0 ); // $ExpectError |
| 94 | +} |
0 commit comments