/* * @license Apache-2.0 * * Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import empty = require( './../../../base/empty' ); import truesLike = require( './index' ); // TESTS // // The function returns an ndarray... { const sh = [ 2, 2 ]; const ord = 'row-major'; truesLike( empty( 'bool', sh, ord ) ); // $ExpectType boolndarray truesLike( empty( 'generic', sh, ord ) ); // $ExpectType genericndarray truesLike( empty( 'bool', sh, ord ), {} ); // $ExpectType boolndarray truesLike( empty( 'generic', sh, ord ), {} ); // $ExpectType genericndarray truesLike( empty( 'bool', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType boolndarray truesLike( empty( 'generic', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType genericndarray truesLike( empty( 'bool', sh, ord ), { 'order': 'column-major' } ); // $ExpectType boolndarray truesLike( empty( 'generic', sh, ord ), { 'order': 'column-major' } ); // $ExpectType genericndarray truesLike( empty( 'generic', sh, ord ), { 'dtype': 'bool' } ); // $ExpectType boolndarray truesLike( empty( 'bool', sh, ord ), { 'dtype': 'generic' } ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument is not an ndarray which has a recognized/supported data type... { truesLike( '10' ); // $ExpectError truesLike( 10 ); // $ExpectError truesLike( false ); // $ExpectError truesLike( true ); // $ExpectError truesLike( null ); // $ExpectError truesLike( [] ); // $ExpectError truesLike( {} ); // $ExpectError truesLike( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a second argument is not an options object... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, '10' ); // $ExpectError truesLike( x, 10 ); // $ExpectError truesLike( x, false ); // $ExpectError truesLike( x, true ); // $ExpectError truesLike( x, [] ); // $ExpectError truesLike( x, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a `dtype` option which is not a valid data type... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, { 'dtype': '10' } ); // $ExpectError truesLike( x, { 'dtype': 10 } ); // $ExpectError truesLike( x, { 'dtype': null } ); // $ExpectError truesLike( x, { 'dtype': false } ); // $ExpectError truesLike( x, { 'dtype': true } ); // $ExpectError truesLike( x, { 'dtype': [] } ); // $ExpectError truesLike( x, { 'dtype': {} } ); // $ExpectError truesLike( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an `order` option which is not a valid order... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, { 'order': '10' } ); // $ExpectError truesLike( x, { 'order': 10 } ); // $ExpectError truesLike( x, { 'order': false } ); // $ExpectError truesLike( x, { 'order': true } ); // $ExpectError truesLike( x, { 'order': [] } ); // $ExpectError truesLike( x, { 'order': {} } ); // $ExpectError truesLike( x, { 'order': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `shape` option which is not a valid shape... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, { 'shape': '10' } ); // $ExpectError truesLike( x, { 'shape': false } ); // $ExpectError truesLike( x, { 'shape': true } ); // $ExpectError truesLike( x, { 'shape': [ '5' ] } ); // $ExpectError truesLike( x, { 'shape': {} } ); // $ExpectError truesLike( x, { 'shape': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `mode` option which is not a valid mode... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, { 'mode': '5' } ); // $ExpectError truesLike( x, { 'mode': 5 } ); // $ExpectError truesLike( x, { 'mode': false } ); // $ExpectError truesLike( x, { 'mode': true } ); // $ExpectError truesLike( x, { 'mode': [ '5' ] } ); // $ExpectError truesLike( x, { 'mode': {} } ); // $ExpectError truesLike( x, { 'mode': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `submode` option which is not valid... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, { 'submode': '5' } ); // $ExpectError truesLike( x, { 'submode': 5 } ); // $ExpectError truesLike( x, { 'submode': false } ); // $ExpectError truesLike( x, { 'submode': true } ); // $ExpectError truesLike( x, { 'submode': [ '5' ] } ); // $ExpectError truesLike( x, { 'submode': {} } ); // $ExpectError truesLike( x, { 'submode': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `readonly` option which is not a boolean... { const x = empty( 'generic', [ 2, 2 ], 'row-major' ); truesLike( x, { 'readonly': '5' } ); // $ExpectError truesLike( x, { 'readonly': 5 } ); // $ExpectError truesLike( x, { 'readonly': [ '5' ] } ); // $ExpectError truesLike( x, { 'readonly': {} } ); // $ExpectError truesLike( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { truesLike(); // $ExpectError truesLike( empty( 'generic', [ 2, 2 ], 'row-major' ), {}, 1 ); // $ExpectError }