|
| 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 stridedarray2iterator = require( './index' ); |
| 20 | + |
| 21 | +/** |
| 22 | +* Multiplies a value by 10. |
| 23 | +* |
| 24 | +* @param v - iterated value |
| 25 | +* @returns new value |
| 26 | +*/ |
| 27 | +function times10( v: number ): number { |
| 28 | + return v * 10.0; |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +// TESTS // |
| 33 | + |
| 34 | +// The function returns an iterator... |
| 35 | +{ |
| 36 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectType Iterator |
| 37 | + stridedarray2iterator( 4, [ 1, 2, 3, 4, 5, 6, 7, 8 ], -2, 6, times10 ); // $ExpectType Iterator |
| 38 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, times10, {} ); // $ExpectType Iterator |
| 39 | +} |
| 40 | + |
| 41 | +// The compiler throws an error if the function is provided a first argument which is not a number... |
| 42 | +{ |
| 43 | + stridedarray2iterator( 'abc', [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError |
| 44 | + stridedarray2iterator( true, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError |
| 45 | + stridedarray2iterator( false, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError |
| 46 | + stridedarray2iterator( {}, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError |
| 47 | + stridedarray2iterator( null, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError |
| 48 | + stridedarray2iterator( undefined, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError |
| 49 | +} |
| 50 | + |
| 51 | +// The compiler throws an error if the function is provided a second argument which is not array-like... |
| 52 | +{ |
| 53 | + stridedarray2iterator( 2, 123, -2, 3 ); // $ExpectError |
| 54 | + stridedarray2iterator( 2, true, -2, 3 ); // $ExpectError |
| 55 | + stridedarray2iterator( 2, false, -2, 3 ); // $ExpectError |
| 56 | + stridedarray2iterator( 2, {}, -2, 3 ); // $ExpectError |
| 57 | + stridedarray2iterator( 2, null, -2, 3 ); // $ExpectError |
| 58 | + stridedarray2iterator( 2, undefined, -2, 3 ); // $ExpectError |
| 59 | +} |
| 60 | + |
| 61 | +// The compiler throws an error if the function is provided a third argument which is not a number... |
| 62 | +{ |
| 63 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], 'abc', 3 ); // $ExpectError |
| 64 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], true, 3 ); // $ExpectError |
| 65 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], false, 3 ); // $ExpectError |
| 66 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], {}, 3 ); // $ExpectError |
| 67 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], null, 3 ); // $ExpectError |
| 68 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], undefined, 3 ); // $ExpectError |
| 69 | +} |
| 70 | + |
| 71 | +// The compiler throws an error if the function is provided a fourth argument which is not a number... |
| 72 | +{ |
| 73 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 'abc' ); // $ExpectError |
| 74 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, true ); // $ExpectError |
| 75 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, false ); // $ExpectError |
| 76 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, {} ); // $ExpectError |
| 77 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, null ); // $ExpectError |
| 78 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, undefined ); // $ExpectError |
| 79 | +} |
| 80 | + |
| 81 | +// The compiler throws an error if the function is provided a fifth argument which is not a map function... |
| 82 | +{ |
| 83 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, 'abc' ); // $ExpectError |
| 84 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, 123 ); // $ExpectError |
| 85 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, [] ); // $ExpectError |
| 86 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, {} ); // $ExpectError |
| 87 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, true ); // $ExpectError |
| 88 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, false ); // $ExpectError |
| 89 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, null ); // $ExpectError |
| 90 | +} |
| 91 | + |
| 92 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 93 | +{ |
| 94 | + stridedarray2iterator(); // $ExpectError |
| 95 | + stridedarray2iterator( 2 ); // $ExpectError |
| 96 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ] ); // $ExpectError |
| 97 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2 ); // $ExpectError |
| 98 | + stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, times10, {}, 123 ); // $ExpectError |
| 99 | +} |
0 commit comments