/* * @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 broadcastScalarLike = require( './index' ); // TESTS // // The function returns an ndarray... { var x = empty( [ 2, 2 ], { 'dtype': 'float64' }); broadcastScalarLike( x, 1.0 ); // $ExpectType float64ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'float64' } ); // $ExpectType float64ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'float32' } ); // $ExpectType float32ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray broadcastScalarLike( x, true, { 'dtype': 'bool' } ); // $ExpectType boolndarray broadcastScalarLike( x, 1.0, { 'dtype': 'int32' } ); // $ExpectType int32ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'int16' } ); // $ExpectType int16ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'int8' } ); // $ExpectType int8ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'uint32' } ); // $ExpectType uint32ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'uint16' } ); // $ExpectType uint16ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'uint8' } ); // $ExpectType uint8ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'uint8c' } ); // $ExpectType uint8cndarray broadcastScalarLike( 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... { broadcastScalarLike( '10', 1.0 ); // $ExpectError broadcastScalarLike( 5, 1.0 ); // $ExpectError broadcastScalarLike( false, 1.0 ); // $ExpectError broadcastScalarLike( true, 1.0 ); // $ExpectError broadcastScalarLike( null, 1.0 ); // $ExpectError broadcastScalarLike( [], 1.0 ); // $ExpectError broadcastScalarLike( ( 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( [ 2, 2 ] ); broadcastScalarLike( x, 1.0, '10' ); // $ExpectError broadcastScalarLike( x, 1.0, 5 ); // $ExpectError broadcastScalarLike( x, 1.0, false ); // $ExpectError broadcastScalarLike( x, 1.0, true ); // $ExpectError broadcastScalarLike( x, 1.0, null ); // $ExpectError broadcastScalarLike( x, 1.0, [] ); // $ExpectError broadcastScalarLike( 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( [ 2, 2 ] ); broadcastScalarLike( x, 1.0, { 'dtype': '10' } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': 5 } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': false } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': true } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': null } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': [] } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': {} } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided a `shape` option which is not an array of numbers... { var x = empty( [ 2, 2 ] ); broadcastScalarLike( x, 1.0, { 'shape': '10' } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'shape': 5 } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'shape': false } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'shape': true } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'shape': null } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'shape': {} } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'shape': ( 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( [ 2, 2 ] ); broadcastScalarLike( x, 1.0, { 'order': '10' } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'order': 5 } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'order': false } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'order': true } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'order': null } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'order': [] } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'order': {} } ); // $ExpectError broadcastScalarLike( 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( [ 2, 2 ] ); broadcastScalarLike( x, 1.0, { 'readonly': '10' } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'readonly': 5 } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'readonly': null } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'readonly': [] } ); // $ExpectError broadcastScalarLike( x, 1.0, { 'readonly': {} } ); // $ExpectError broadcastScalarLike( 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( [ 2, 2 ] ); broadcastScalarLike(); // $ExpectError broadcastScalarLike( x, 1.0, {}, {} ); // $ExpectError }