|
| 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 lowess = require( './index' ); |
| 20 | + |
| 21 | + |
| 22 | +// TESTS // |
| 23 | + |
| 24 | +// The function returns an object with ordered x-values and fitted values... |
| 25 | +{ |
| 26 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 27 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 28 | + lowess( x, y ); // $ExpectType Output |
| 29 | + lowess( x, y, { 'nsteps': 3 } ); // $ExpectType Output |
| 30 | + lowess( x, y, { 'f': 2 / 3 } ); // $ExpectType Output |
| 31 | + lowess( x, y, { 'sorted': true } ); // $ExpectType Output |
| 32 | +} |
| 33 | + |
| 34 | +// The function does not compile if provided a first argument that is not an array of numbers... |
| 35 | +{ |
| 36 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 37 | + lowess( 'abc', y ); // $ExpectError |
| 38 | + lowess( true, y ); // $ExpectError |
| 39 | + lowess( false, y ); // $ExpectError |
| 40 | + lowess( null, y ); // $ExpectError |
| 41 | + lowess( undefined, y ); // $ExpectError |
| 42 | + lowess( 5, y ); // $ExpectError |
| 43 | + lowess( {}, y ); // $ExpectError |
| 44 | + lowess( ( x: number ): number => x, y ); // $ExpectError |
| 45 | +} |
| 46 | + |
| 47 | +// The function does not compile if provided a second argument that is not an array of numbers... |
| 48 | +{ |
| 49 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 50 | + lowess( x, 'abc' ); // $ExpectError |
| 51 | + lowess( x, true ); // $ExpectError |
| 52 | + lowess( x, false ); // $ExpectError |
| 53 | + lowess( x, null ); // $ExpectError |
| 54 | + lowess( x, undefined ); // $ExpectError |
| 55 | + lowess( x, 5 ); // $ExpectError |
| 56 | + lowess( x, {} ); // $ExpectError |
| 57 | + lowess( x, ( x: number ): number => x ); // $ExpectError |
| 58 | +} |
| 59 | + |
| 60 | +// The compiler throws an error if the function is provided a third argument which is not an options object... |
| 61 | +{ |
| 62 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 63 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 64 | + lowess( x, y, true ); // $ExpectError |
| 65 | + lowess( x, y, false ); // $ExpectError |
| 66 | + lowess( x, y, null ); // $ExpectError |
| 67 | + lowess( x, y, 5 ); // $ExpectError |
| 68 | + lowess( x, y, 'abc' ); // $ExpectError |
| 69 | + lowess( x, y, ( x: number ): number => x ); // $ExpectError |
| 70 | +} |
| 71 | + |
| 72 | +// The compiler throws an error if the function is provided a `f` option which is not a number... |
| 73 | +{ |
| 74 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 75 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 76 | + lowess( x, y, { 'f': 'abc' } ); // $ExpectError |
| 77 | + lowess( x, y, { 'f': '123' } ); // $ExpectError |
| 78 | + lowess( x, y, { 'f': true } ); // $ExpectError |
| 79 | + lowess( x, y, { 'f': false } ); // $ExpectError |
| 80 | + lowess( x, y, { 'f': null } ); // $ExpectError |
| 81 | + lowess( x, y, { 'f': [] } ); // $ExpectError |
| 82 | + lowess( x, y, { 'f': {} } ); // $ExpectError |
| 83 | + lowess( x, y, { 'f': ( x: number ): number => x } ); // $ExpectError |
| 84 | +} |
| 85 | + |
| 86 | +// The compiler throws an error if the function is provided a `nsteps` option which is not a number... |
| 87 | +{ |
| 88 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 89 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 90 | + lowess( x, y, { 'nsteps': 'abc' } ); // $ExpectError |
| 91 | + lowess( x, y, { 'nsteps': '123' } ); // $ExpectError |
| 92 | + lowess( x, y, { 'nsteps': true } ); // $ExpectError |
| 93 | + lowess( x, y, { 'nsteps': false } ); // $ExpectError |
| 94 | + lowess( x, y, { 'nsteps': null } ); // $ExpectError |
| 95 | + lowess( x, y, { 'nsteps': [] } ); // $ExpectError |
| 96 | + lowess( x, y, { 'nsteps': {} } ); // $ExpectError |
| 97 | + lowess( x, y, { 'nsteps': ( x: number ): number => x } ); // $ExpectError |
| 98 | +} |
| 99 | + |
| 100 | +// The compiler throws an error if the function is provided a `delta` option which is not a number... |
| 101 | +{ |
| 102 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 103 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 104 | + lowess( x, y, { 'delta': 'abc' } ); // $ExpectError |
| 105 | + lowess( x, y, { 'delta': '123' } ); // $ExpectError |
| 106 | + lowess( x, y, { 'delta': true } ); // $ExpectError |
| 107 | + lowess( x, y, { 'delta': false } ); // $ExpectError |
| 108 | + lowess( x, y, { 'delta': null } ); // $ExpectError |
| 109 | + lowess( x, y, { 'delta': [] } ); // $ExpectError |
| 110 | + lowess( x, y, { 'delta': {} } ); // $ExpectError |
| 111 | + lowess( x, y, { 'delta': ( x: number ): number => x } ); // $ExpectError |
| 112 | +} |
| 113 | + |
| 114 | +// The compiler throws an error if the function is provided a `sorted` option which is not a boolean... |
| 115 | +{ |
| 116 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 117 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 118 | + lowess( x, y, { 'sorted': 'abc' } ); // $ExpectError |
| 119 | + lowess( x, y, { 'sorted': '123' } ); // $ExpectError |
| 120 | + lowess( x, y, { 'sorted': 123 } ); // $ExpectError |
| 121 | + lowess( x, y, { 'sorted': null } ); // $ExpectError |
| 122 | + lowess( x, y, { 'sorted': [] } ); // $ExpectError |
| 123 | + lowess( x, y, { 'sorted': {} } ); // $ExpectError |
| 124 | + lowess( x, y, { 'sorted': ( x: number ): number => x } ); // $ExpectError |
| 125 | +} |
| 126 | + |
| 127 | +// The function does not compile if provided an invalid number of arguments... |
| 128 | +{ |
| 129 | + const x = [ 1.0, 2.0, 3.0 ]; |
| 130 | + const y = [ 2.0, 3.5, 3.9 ]; |
| 131 | + lowess( x ); // $ExpectError |
| 132 | + lowess( x, y, {}, {} ); // $ExpectError |
| 133 | +} |
0 commit comments