|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2025 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 decompose = require( './index' ); |
| 20 | + |
| 21 | +// TESTS // |
| 22 | + |
| 23 | +// The function returns a number... |
| 24 | +{ |
| 25 | + const initial = [ 4, 2, 3, 5 ]; |
| 26 | + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 27 | + |
| 28 | + decompose( 12, initial, out, 1, 0 ); // $ExpectType number |
| 29 | +} |
| 30 | + |
| 31 | +// The compiler throws an error if the function is provided a sequence length which is not a number... |
| 32 | +{ |
| 33 | + const initial = [ 4, 2, 3, 5 ]; |
| 34 | + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 35 | + |
| 36 | + decompose( '12', initial, out, 1, 0 ); // $ExpectError |
| 37 | + decompose( true, initial, out, 1, 0 ); // $ExpectError |
| 38 | + decompose( false, initial, out, 1, 0 ); // $ExpectError |
| 39 | + decompose( null, initial, out, 1, 0 ); // $ExpectError |
| 40 | + decompose( undefined, initial, out, 1, 0 ); // $ExpectError |
| 41 | + decompose( [], initial, out, 1, 0 ); // $ExpectError |
| 42 | + decompose( {}, initial, out, 1, 0 ); // $ExpectError |
| 43 | + decompose( ( x: number ): number => x, initial, out, 1, 0 ); // $ExpectError |
| 44 | +} |
| 45 | + |
| 46 | +// The compiler throws an error if the function is provided initial trial divisors which is not an array of numbers... |
| 47 | +{ |
| 48 | + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 49 | + |
| 50 | + decompose( 12, '4,2,3,5', out, 1, 0 ); // $ExpectError |
| 51 | + decompose( 12, 5, out, 1, 0 ); // $ExpectError |
| 52 | + decompose( 12, true, out, 1, 0 ); // $ExpectError |
| 53 | + decompose( 12, false, out, 1, 0 ); // $ExpectError |
| 54 | + decompose( 12, null, out, 1, 0 ); // $ExpectError |
| 55 | + decompose( 12, undefined, out, 1, 0 ); // $ExpectError |
| 56 | + decompose( 12, {}, out, 1, 0 ); // $ExpectError |
| 57 | + decompose( 12, ( x: number ): number => x, out, 1, 0 ); // $ExpectError |
| 58 | +} |
| 59 | + |
| 60 | +// The compiler throws an error if the function is provided an output array which is not an array-like object... |
| 61 | +{ |
| 62 | + const initial = [ 4, 2, 3, 5 ]; |
| 63 | + |
| 64 | + decompose( 12, initial, 123, 1, 0 ); // $ExpectError |
| 65 | + decompose( 12, initial, true, 1, 0 ); // $ExpectError |
| 66 | + decompose( 12, initial, false, 1, 0 ); // $ExpectError |
| 67 | + decompose( 12, initial, null, 1, 0 ); // $ExpectError |
| 68 | + decompose( 12, initial, undefined, 1, 0 ); // $ExpectError |
| 69 | + decompose( 12, initial, {}, 1, 0 ); // $ExpectError |
| 70 | + decompose( 12, initial, ( x: number ): number => x, 1, 0 ); // $ExpectError |
| 71 | +} |
| 72 | + |
| 73 | +// The compiler throws an error if the function is provided a stride which is not a number... |
| 74 | +{ |
| 75 | + const initial = [ 4, 2, 3, 5 ]; |
| 76 | + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 77 | + |
| 78 | + decompose( 12, initial, out, '1', 0 ); // $ExpectError |
| 79 | + decompose( 12, initial, out, true, 0 ); // $ExpectError |
| 80 | + decompose( 12, initial, out, false, 0 ); // $ExpectError |
| 81 | + decompose( 12, initial, out, null, 0 ); // $ExpectError |
| 82 | + decompose( 12, initial, out, undefined, 0 ); // $ExpectError |
| 83 | + decompose( 12, initial, out, [], 0 ); // $ExpectError |
| 84 | + decompose( 12, initial, out, {}, 0 ); // $ExpectError |
| 85 | + decompose( 12, initial, out, ( x: number ): number => x, 0 ); // $ExpectError |
| 86 | +} |
| 87 | + |
| 88 | +// The compiler throws an error if the function is provided an offset which is not a number... |
| 89 | +{ |
| 90 | + const initial = [ 4, 2, 3, 5 ]; |
| 91 | + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 92 | + |
| 93 | + decompose( 12, initial, out, 1, '0' ); // $ExpectError |
| 94 | + decompose( 12, initial, out, 1, true ); // $ExpectError |
| 95 | + decompose( 12, initial, out, 1, false ); // $ExpectError |
| 96 | + decompose( 12, initial, out, 1, null ); // $ExpectError |
| 97 | + decompose( 12, initial, out, 1, undefined ); // $ExpectError |
| 98 | + decompose( 12, initial, out, 1, [] ); // $ExpectError |
| 99 | + decompose( 12, initial, out, 1, {} ); // $ExpectError |
| 100 | + decompose( 12, initial, out, 1, ( x: number ): number => x ); // $ExpectError |
| 101 | +} |
| 102 | + |
| 103 | +// The compiler throws an error if the function is provided an unsupported number of arguments... |
| 104 | +{ |
| 105 | + const initial = [ 4, 2, 3, 5 ]; |
| 106 | + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 107 | + |
| 108 | + decompose(); // $ExpectError |
| 109 | + decompose( 12 ); // $ExpectError |
| 110 | + decompose( 12, initial ); // $ExpectError |
| 111 | + decompose( 12, initial, out ); // $ExpectError |
| 112 | + decompose( 12, initial, out, 1 ); // $ExpectError |
| 113 | + decompose( 12, initial, out, 1, 0, 123 ); // $ExpectError |
| 114 | +} |
0 commit comments