|
| 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 bind2vind = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns a number... |
| 25 | +{ |
| 26 | + const shape = [ 3, 3, 3 ]; |
| 27 | + const strides = [ 9, 6, 1 ]; |
| 28 | + const offset = 0; |
| 29 | + const order = 'row-major'; |
| 30 | + const idx = 17; |
| 31 | + const mode = 'throw'; |
| 32 | + bind2vind( shape, strides, offset, order, idx, mode ); // $ExpectType number |
| 33 | +} |
| 34 | + |
| 35 | +// The function does not compile if provided a first argument which is not an array-like object containing numbers... |
| 36 | +{ |
| 37 | + const strides = [ 9, 6, 1 ]; |
| 38 | + const offset = 0; |
| 39 | + const order = 'row-major'; |
| 40 | + const idx = 17; |
| 41 | + const mode = 'throw'; |
| 42 | + bind2vind( true, strides, offset, order, idx, mode ); // $ExpectError |
| 43 | + bind2vind( false, strides, offset, order, idx, mode ); // $ExpectError |
| 44 | + bind2vind( null, strides, offset, order, idx, mode ); // $ExpectError |
| 45 | + bind2vind( undefined, strides, offset, order, idx, mode ); // $ExpectError |
| 46 | + bind2vind( '5', strides, offset, order, idx, mode ); // $ExpectError |
| 47 | + bind2vind( [ '1', '2' ], strides, offset, order, idx, mode ); // $ExpectError |
| 48 | + bind2vind( {}, strides, offset, order, idx, mode ); // $ExpectError |
| 49 | + bind2vind( ( x: number ): number => x, strides, offset, order, idx, mode ); // $ExpectError |
| 50 | +} |
| 51 | + |
| 52 | +// The function does not compile if provided a second argument which is not an array-like object containing numbers... |
| 53 | +{ |
| 54 | + const shape = [ 3, 3, 3 ]; |
| 55 | + const offset = 0; |
| 56 | + const order = 'row-major'; |
| 57 | + const idx = 17; |
| 58 | + const mode = 'throw'; |
| 59 | + bind2vind( shape, true, offset, order, idx, mode ); // $ExpectError |
| 60 | + bind2vind( shape, false, offset, order, idx, mode ); // $ExpectError |
| 61 | + bind2vind( shape, null, offset, order, idx, mode ); // $ExpectError |
| 62 | + bind2vind( shape, undefined, offset, order, idx, mode ); // $ExpectError |
| 63 | + bind2vind( shape, '5', offset, order, idx, mode ); // $ExpectError |
| 64 | + bind2vind( shape, [ '1', '2' ], offset, order, idx, mode ); // $ExpectError |
| 65 | + bind2vind( shape, {}, offset, order, idx, mode ); // $ExpectError |
| 66 | + bind2vind( shape, ( x: number ): number => x, offset, order, idx, mode ); // $ExpectError |
| 67 | +} |
| 68 | + |
| 69 | +// The function does not compile if provided a third argument which is not a number... |
| 70 | +{ |
| 71 | + const shape = [ 3, 3, 3 ]; |
| 72 | + const strides = [ 9, 6, 1 ]; |
| 73 | + const order = 'row-major'; |
| 74 | + const idx = 17; |
| 75 | + const mode = 'throw'; |
| 76 | + bind2vind( shape, strides, true, order, idx, mode ); // $ExpectError |
| 77 | + bind2vind( shape, strides, false, order, idx, mode ); // $ExpectError |
| 78 | + bind2vind( shape, strides, null, order, idx, mode ); // $ExpectError |
| 79 | + bind2vind( shape, strides, undefined, order, idx, mode ); // $ExpectError |
| 80 | + bind2vind( shape, strides, '5', order, idx, mode ); // $ExpectError |
| 81 | + bind2vind( shape, strides, [ '1', '2' ], order, idx, mode ); // $ExpectError |
| 82 | + bind2vind( shape, strides, {}, order, idx, mode ); // $ExpectError |
| 83 | + bind2vind( shape, strides, ( x: number ): number => x, order, idx, mode ); // $ExpectError |
| 84 | +} |
| 85 | + |
| 86 | +// The function does not compile if provided a fourth argument which is not a known array order... |
| 87 | +{ |
| 88 | + const shape = [ 3, 3, 3 ]; |
| 89 | + const strides = [ 9, 6, 1 ]; |
| 90 | + const offset = 0; |
| 91 | + const idx = 17; |
| 92 | + const mode = 'throw'; |
| 93 | + bind2vind( shape, strides, offset, true, idx, mode ); // $ExpectError |
| 94 | + bind2vind( shape, strides, offset, false, idx, mode ); // $ExpectError |
| 95 | + bind2vind( shape, strides, offset, null, idx, mode ); // $ExpectError |
| 96 | + bind2vind( shape, strides, offset, undefined, idx, mode ); // $ExpectError |
| 97 | + bind2vind( shape, strides, offset, '5', idx, mode ); // $ExpectError |
| 98 | + bind2vind( shape, strides, offset, [ '1', '2' ], idx, mode ); // $ExpectError |
| 99 | + bind2vind( shape, strides, offset, {}, idx, mode ); // $ExpectError |
| 100 | + bind2vind( shape, strides, offset, ( x: number ): number => x, idx, mode ); // $ExpectError |
| 101 | +} |
| 102 | + |
| 103 | +// The function does not compile if provided a fifth argument which is not a number... |
| 104 | +{ |
| 105 | + const shape = [ 3, 3, 3 ]; |
| 106 | + const strides = [ 9, 6, 1 ]; |
| 107 | + const offset = 0; |
| 108 | + const order = 'row-major'; |
| 109 | + const mode = 'throw'; |
| 110 | + bind2vind( shape, strides, offset, order, true, mode ); // $ExpectError |
| 111 | + bind2vind( shape, strides, offset, order, false, mode ); // $ExpectError |
| 112 | + bind2vind( shape, strides, offset, order, null, mode ); // $ExpectError |
| 113 | + bind2vind( shape, strides, offset, order, undefined, mode ); // $ExpectError |
| 114 | + bind2vind( shape, strides, offset, order, '5', mode ); // $ExpectError |
| 115 | + bind2vind( shape, strides, offset, order, [ '1', '2' ], mode ); // $ExpectError |
| 116 | + bind2vind( shape, strides, offset, order, {}, mode ); // $ExpectError |
| 117 | + bind2vind( shape, strides, offset, order, ( x: number ): number => x, mode ); // $ExpectError |
| 118 | +} |
| 119 | + |
| 120 | +// The function does not compile if provided a sixth argument which is not a known mode... |
| 121 | +{ |
| 122 | + const shape = [ 3, 3, 3 ]; |
| 123 | + const strides = [ 9, 6, 1 ]; |
| 124 | + const offset = 0; |
| 125 | + const order = 'row-major'; |
| 126 | + const idx = 17; |
| 127 | + bind2vind( shape, strides, offset, order, idx, true ); // $ExpectError |
| 128 | + bind2vind( shape, strides, offset, order, idx, false ); // $ExpectError |
| 129 | + bind2vind( shape, strides, offset, order, idx, null ); // $ExpectError |
| 130 | + bind2vind( shape, strides, offset, order, idx, undefined ); // $ExpectError |
| 131 | + bind2vind( shape, strides, offset, order, idx, '5' ); // $ExpectError |
| 132 | + bind2vind( shape, strides, offset, order, idx, [ '1', '2' ] ); // $ExpectError |
| 133 | + bind2vind( shape, strides, offset, order, idx, {} ); // $ExpectError |
| 134 | + bind2vind( shape, strides, offset, order, idx, ( x: number ): number => x ); // $ExpectError |
| 135 | +} |
| 136 | + |
| 137 | +// The function does not compile if provided insufficient arguments... |
| 138 | +{ |
| 139 | + const shape = [ 3, 3, 3 ]; |
| 140 | + const strides = [ 9, 6, 1 ]; |
| 141 | + const offset = 0; |
| 142 | + const order = 'row-major'; |
| 143 | + const idx = 17; |
| 144 | + bind2vind(); // $ExpectError |
| 145 | + bind2vind( shape ); // $ExpectError |
| 146 | + bind2vind( shape, strides ); // $ExpectError |
| 147 | + bind2vind( shape, strides, offset ); // $ExpectError |
| 148 | + bind2vind( shape, strides, offset, order ); // $ExpectError |
| 149 | + bind2vind( shape, strides, offset, order, idx ); // $ExpectError |
| 150 | +} |
0 commit comments