|
| 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 isBufferLengthCompatible = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a boolean... |
| 25 | +{ |
| 26 | + isBufferLengthCompatible( 4, [ 2, 2 ], [ 2, 1 ], 0 ); // $ExpectType boolean |
| 27 | +} |
| 28 | + |
| 29 | +// The function does not compile if provided a first argument which is not a number... |
| 30 | +{ |
| 31 | + const shape = [ 2, 2 ]; |
| 32 | + const strides = [ 2, 1 ]; |
| 33 | + const offset = 0; |
| 34 | + isBufferLengthCompatible( true, shape, strides, offset ); // $ExpectError |
| 35 | + isBufferLengthCompatible( false, shape, strides, offset ); // $ExpectError |
| 36 | + isBufferLengthCompatible( null, shape, strides, offset ); // $ExpectError |
| 37 | + isBufferLengthCompatible( undefined, shape, strides, offset ); // $ExpectError |
| 38 | + isBufferLengthCompatible( '5', shape, strides, offset ); // $ExpectError |
| 39 | + isBufferLengthCompatible( [ '1', '2' ], shape, strides, offset ); // $ExpectError |
| 40 | + isBufferLengthCompatible( {}, shape, strides, offset ); // $ExpectError |
| 41 | + isBufferLengthCompatible( ( x: number ): number => x, shape, strides, offset ); // $ExpectError |
| 42 | +} |
| 43 | + |
| 44 | +// The function does not compile if provided a second argument which is not an array-like object containing numbers... |
| 45 | +{ |
| 46 | + const len = 4; |
| 47 | + const strides = [ 2, 1 ]; |
| 48 | + const offset = 0; |
| 49 | + isBufferLengthCompatible( len, true, strides, offset ); // $ExpectError |
| 50 | + isBufferLengthCompatible( len, false, strides, offset ); // $ExpectError |
| 51 | + isBufferLengthCompatible( len, null, strides, offset ); // $ExpectError |
| 52 | + isBufferLengthCompatible( len, undefined, strides, offset ); // $ExpectError |
| 53 | + isBufferLengthCompatible( len, '5', strides, offset ); // $ExpectError |
| 54 | + isBufferLengthCompatible( len, [ '1', '2' ], strides, offset ); // $ExpectError |
| 55 | + isBufferLengthCompatible( len, {}, strides, offset ); // $ExpectError |
| 56 | + isBufferLengthCompatible( len, ( x: number ): number => x, strides, offset ); // $ExpectError |
| 57 | +} |
| 58 | + |
| 59 | +// The function does not compile if provided a third argument which is not an array-like object containing numbers... |
| 60 | +{ |
| 61 | + const len = 4; |
| 62 | + const shape = [ 2, 2 ]; |
| 63 | + const offset = 0; |
| 64 | + isBufferLengthCompatible( len, shape, true, offset ); // $ExpectError |
| 65 | + isBufferLengthCompatible( len, shape, false, offset ); // $ExpectError |
| 66 | + isBufferLengthCompatible( len, shape, null, offset ); // $ExpectError |
| 67 | + isBufferLengthCompatible( len, shape, undefined, offset ); // $ExpectError |
| 68 | + isBufferLengthCompatible( len, shape, '5', offset ); // $ExpectError |
| 69 | + isBufferLengthCompatible( len, shape, [ '1', '2' ], offset ); // $ExpectError |
| 70 | + isBufferLengthCompatible( len, shape, {}, offset ); // $ExpectError |
| 71 | + isBufferLengthCompatible( len, shape, ( x: number ): number => x, offset ); // $ExpectError |
| 72 | +} |
| 73 | + |
| 74 | +// The function does not compile if provided a fourth argument which is not a number... |
| 75 | +{ |
| 76 | + const len = 4; |
| 77 | + const shape = [ 2, 2 ]; |
| 78 | + const strides = [ 2, 1 ]; |
| 79 | + isBufferLengthCompatible( len, shape, strides, true ); // $ExpectError |
| 80 | + isBufferLengthCompatible( len, shape, strides, false ); // $ExpectError |
| 81 | + isBufferLengthCompatible( len, shape, strides, null ); // $ExpectError |
| 82 | + isBufferLengthCompatible( len, shape, strides, undefined ); // $ExpectError |
| 83 | + isBufferLengthCompatible( len, shape, strides, '5' ); // $ExpectError |
| 84 | + isBufferLengthCompatible( len, shape, strides, [ '1', '2' ] ); // $ExpectError |
| 85 | + isBufferLengthCompatible( len, shape, strides, {} ); // $ExpectError |
| 86 | + isBufferLengthCompatible( len, shape, strides, ( x: number ): number => x ); // $ExpectError |
| 87 | +} |
| 88 | + |
| 89 | +// The function does not compile if provided insufficient arguments... |
| 90 | +{ |
| 91 | + isBufferLengthCompatible(); // $ExpectError |
| 92 | + isBufferLengthCompatible( 4 ); // $ExpectError |
| 93 | + isBufferLengthCompatible( 4, [ 2, 2 ] ); // $ExpectError |
| 94 | + isBufferLengthCompatible( 4, [ 2, 2 ], [ 2, 1 ] ); // $ExpectError |
| 95 | +} |
0 commit comments