|
| 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 bquinary5d = require( './index' ); |
| 20 | + |
| 21 | +/** |
| 22 | +* Quinary function. |
| 23 | +* |
| 24 | +* @param x - input value |
| 25 | +* @param y - input value |
| 26 | +* @param z - input value |
| 27 | +* @param w - input value |
| 28 | +* @param v - input value |
| 29 | +* @returns result |
| 30 | +*/ |
| 31 | +function fcn( x: number, y: number, z: number, w: number, v: number ): number { |
| 32 | + return x + y + z + w + v; |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | +* List of input and output array shapes. |
| 37 | +*/ |
| 38 | +type InOutShapes = [ Array<number>, Array<number>, Array<number>, Array<number>, Array<number>, Array<number> ]; |
| 39 | + |
| 40 | + |
| 41 | +// TESTS // |
| 42 | + |
| 43 | +// The function returns undefined... |
| 44 | +{ |
| 45 | + const x = [[[[[ 1.0, 2.0 ]]]]]; |
| 46 | + const y = [[[[[ 1.0, 2.0 ]]]]]; |
| 47 | + const z = [[[[[ 1.0, 2.0 ]]]]]; |
| 48 | + const w = [[[[[ 1.0, 2.0 ]]]]]; |
| 49 | + const v = [[[[[ 1.0, 2.0 ]]]]]; |
| 50 | + const out = [[[[[ 0.0, 0.0 ]]]]]; |
| 51 | + |
| 52 | + const shapes: InOutShapes = [ [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ] ]; |
| 53 | + |
| 54 | + bquinary5d( [ x, y, z, w, v, out ], shapes, fcn ); // $ExpectType void |
| 55 | + bquinary5d( [ x[ 0 ], y, z, w, v, out ], [ [ shapes[ 0 ][ 4 ] ], shapes[ 1 ], shapes[ 2 ], shapes[ 3 ], shapes[ 4 ], shapes[ 5 ] ], fcn ); // $ExpectType void |
| 56 | +} |
| 57 | + |
| 58 | +// The compiler throws an error if the function is provided a first argument which is not an array of nested arrays... |
| 59 | +{ |
| 60 | + const shapes: InOutShapes = [ [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ] ]; |
| 61 | + |
| 62 | + bquinary5d( 'abc', shapes, fcn ); // $ExpectError |
| 63 | + bquinary5d( 3.14, shapes, fcn ); // $ExpectError |
| 64 | + bquinary5d( true, shapes, fcn ); // $ExpectError |
| 65 | + bquinary5d( false, shapes, fcn ); // $ExpectError |
| 66 | + bquinary5d( null, shapes, fcn ); // $ExpectError |
| 67 | + bquinary5d( [ '1' ], shapes, fcn ); // $ExpectError |
| 68 | + bquinary5d( {}, shapes, fcn ); // $ExpectError |
| 69 | + bquinary5d( ( x: number ): number => x, shapes, fcn ); // $ExpectError |
| 70 | +} |
| 71 | + |
| 72 | +// The compiler throws an error if the function is provided a second argument which is not an array of arrays... |
| 73 | +{ |
| 74 | + const x = [[[[[ 1.0, 2.0 ]]]]]; |
| 75 | + const y = [[[[[ 1.0, 2.0 ]]]]]; |
| 76 | + const z = [[[[[ 1.0, 2.0 ]]]]]; |
| 77 | + const w = [[[[[ 1.0, 2.0 ]]]]]; |
| 78 | + const v = [[[[[ 1.0, 2.0 ]]]]]; |
| 79 | + const out = [[[[[ 0.0, 0.0 ]]]]]; |
| 80 | + |
| 81 | + bquinary5d( [ x, y, z, w, v, out ], 'abc', fcn ); // $ExpectError |
| 82 | + bquinary5d( [ x, y, z, w, v, out ], 3.14, fcn ); // $ExpectError |
| 83 | + bquinary5d( [ x, y, z, w, v, out ], true, fcn ); // $ExpectError |
| 84 | + bquinary5d( [ x, y, z, w, v, out ], false, fcn ); // $ExpectError |
| 85 | + bquinary5d( [ x, y, z, w, v, out ], null, fcn ); // $ExpectError |
| 86 | + bquinary5d( [ x, y, z, w, v, out ], [ '1' ], fcn ); // $ExpectError |
| 87 | + bquinary5d( [ x, y, z, w, v, out ], {}, fcn ); // $ExpectError |
| 88 | + bquinary5d( [ x, y, z, w, v, out ], ( x: number ): number => x, fcn ); // $ExpectError |
| 89 | +} |
| 90 | + |
| 91 | +// The compiler throws an error if the function is provided a third argument which is not a valid callback... |
| 92 | +{ |
| 93 | + const x = [[[[[ 1.0, 2.0 ]]]]]; |
| 94 | + const y = [[[[[ 1.0, 2.0 ]]]]]; |
| 95 | + const z = [[[[[ 1.0, 2.0 ]]]]]; |
| 96 | + const w = [[[[[ 1.0, 2.0 ]]]]]; |
| 97 | + const v = [[[[[ 1.0, 2.0 ]]]]]; |
| 98 | + const out = [[[[[ 0.0, 0.0 ]]]]]; |
| 99 | + |
| 100 | + const shapes: InOutShapes = [ [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ] ]; |
| 101 | + |
| 102 | + bquinary5d( [ x, y, z, w, v, out ], shapes, 'abc' ); // $ExpectError |
| 103 | + bquinary5d( [ x, y, z, w, v, out ], shapes, 3.14 ); // $ExpectError |
| 104 | + bquinary5d( [ x, y, z, w, v, out ], shapes, true ); // $ExpectError |
| 105 | + bquinary5d( [ x, y, z, w, v, out ], shapes, false ); // $ExpectError |
| 106 | + bquinary5d( [ x, y, z, w, v, out ], shapes, null ); // $ExpectError |
| 107 | + bquinary5d( [ x, y, z, w, v, out ], shapes, [ '1' ] ); // $ExpectError |
| 108 | + bquinary5d( [ x, y, z, w, v, out ], shapes, {} ); // $ExpectError |
| 109 | +} |
| 110 | + |
| 111 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 112 | +{ |
| 113 | + const x = [[[[[ 1.0, 2.0 ]]]]]; |
| 114 | + const y = [[[[[ 1.0, 2.0 ]]]]]; |
| 115 | + const z = [[[[[ 1.0, 2.0 ]]]]]; |
| 116 | + const w = [[[[[ 1.0, 2.0 ]]]]]; |
| 117 | + const v = [[[[[ 1.0, 2.0 ]]]]]; |
| 118 | + const out = [[[[[ 0.0, 0.0 ]]]]]; |
| 119 | + |
| 120 | + const shapes: InOutShapes = [ [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 2 ] ]; |
| 121 | + |
| 122 | + bquinary5d(); // $ExpectError |
| 123 | + bquinary5d( [ x, y, z, w, v, out ] ); // $ExpectError |
| 124 | + bquinary5d( [ x, y, z, w, v, out ], shapes, fcn, {} ); // $ExpectError |
| 125 | +} |
0 commit comments