/* * @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. */ /* eslint-disable space-in-parens */ import empty = require( './../../../empty' ); import scalar2ndarrayLike = require( './index' ); // TESTS // // The function returns an ndarray... { var x = empty( [ 1 ], { 'dtype': 'float64' }); scalar2ndarrayLike( x, 1.0 ); // $ExpectType float64ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'float64' } ); // $ExpectType float64ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'float32' } ); // $ExpectType float32ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray scalar2ndarrayLike( x, true, { 'dtype': 'bool' } ); // $ExpectType boolndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'int32' } ); // $ExpectType int32ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'int16' } ); // $ExpectType int16ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'int8' } ); // $ExpectType int8ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'uint32' } ); // $ExpectType uint32ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'uint16' } ); // $ExpectType uint16ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'uint8' } ); // $ExpectType uint8ndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'uint8c' } ); // $ExpectType uint8cndarray scalar2ndarrayLike( x, 1.0, { 'dtype': 'generic' } ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { scalar2ndarrayLike( '10', 1.0 ); // $ExpectError scalar2ndarrayLike( 5, 1.0 ); // $ExpectError scalar2ndarrayLike( false, 1.0 ); // $ExpectError scalar2ndarrayLike( true, 1.0 ); // $ExpectError scalar2ndarrayLike( null, 1.0 ); // $ExpectError scalar2ndarrayLike( [], 1.0 ); // $ExpectError scalar2ndarrayLike( ( x: number ): number => x, 1.0 ); // $ExpectError } // The compiler throws an error if the function is provided an options argument which is not an object... { var x = empty( [ 1 ] ); scalar2ndarrayLike( x, 1.0, '10' ); // $ExpectError scalar2ndarrayLike( x, 1.0, 5 ); // $ExpectError scalar2ndarrayLike( x, 1.0, false ); // $ExpectError scalar2ndarrayLike( x, 1.0, true ); // $ExpectError scalar2ndarrayLike( x, 1.0, null ); // $ExpectError scalar2ndarrayLike( x, 1.0, [] ); // $ExpectError scalar2ndarrayLike( x, 1.0, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided a `dtype` option which is not a recognized/supported data type... { var x = empty( [ 1 ] ); scalar2ndarrayLike( x, 1.0, { 'dtype': '10' } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': 5 } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': false } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': true } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': null } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': [] } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': {} } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an `order` option which is not a recognized/supported data order... { var x = empty( [ 1 ] ); scalar2ndarrayLike( x, 1.0, { 'order': '10' } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': 5 } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': false } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': true } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': null } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': [] } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': {} } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'order': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `readonly` option which is not a boolean... { var x = empty( [ 1 ] ); scalar2ndarrayLike( x, 1.0, { 'readonly': '10' } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'readonly': 5 } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'readonly': null } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'readonly': [] } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'readonly': {} } ); // $ExpectError scalar2ndarrayLike( x, 1.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { var x = empty( [ 1 ] ); scalar2ndarrayLike(); // $ExpectError scalar2ndarrayLike( x, 1.0, {}, 1 ); // $ExpectError }