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