-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.ts
More file actions
141 lines (122 loc) · 4.71 KB
/
test.ts
File metadata and controls
141 lines (122 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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.
*/
/// <reference types="@stdlib/types"/>
import { typedndarray } from '@stdlib/types/ndarray';
import ndarraylike2ndarray = require( './index' );
/**
* Mock function to create an ndarray-like object.
*
* @returns ndarray-like object
*/
function array(): typedndarray<number> {
const obj: typedndarray<number> = {
'byteLength': 80,
'BYTES_PER_ELEMENT': 8,
'data': new Float64Array( 10 ),
'dtype': 'float64',
'flags': {
'ROW_MAJOR_CONTIGUOUS': true,
'COLUMN_MAJOR_CONTIGUOUS': false
},
'length': 10,
'ndims': 1,
'offset': 0,
'order': 'row-major',
'shape': [ 10 ],
'strides': [ 1 ],
'get': (): number => 0,
'set': (): typedndarray<number> => obj
};
return obj;
}
// TESTS //
// The function returns an ndarray...
{
const x = array();
ndarraylike2ndarray( x ); // $ExpectType typedndarray<number>
ndarraylike2ndarray( x, {} ); // $ExpectType typedndarray<number>
}
// The compiler throws an error if the function is not provided an ndarray...
{
ndarraylike2ndarray( '5' ); // $ExpectError
ndarraylike2ndarray( 123 ); // $ExpectError
ndarraylike2ndarray( true ); // $ExpectError
ndarraylike2ndarray( false ); // $ExpectError
ndarraylike2ndarray( null ); // $ExpectError
ndarraylike2ndarray( [] ); // $ExpectError
ndarraylike2ndarray( {} ); // $ExpectError
ndarraylike2ndarray( ( x: number ): number => x ); // $ExpectError
ndarraylike2ndarray( '5', {} ); // $ExpectError
ndarraylike2ndarray( 123, {} ); // $ExpectError
ndarraylike2ndarray( true, {} ); // $ExpectError
ndarraylike2ndarray( false, {} ); // $ExpectError
ndarraylike2ndarray( null, {} ); // $ExpectError
ndarraylike2ndarray( [], {} ); // $ExpectError
ndarraylike2ndarray( {}, {} ); // $ExpectError
ndarraylike2ndarray( ( x: number ): number => x, {} ); // $ExpectError
}
// The compiler throws an error if the function is not provided an object...
{
const x = array();
ndarraylike2ndarray( x, '5' ); // $ExpectError
ndarraylike2ndarray( x, 123 ); // $ExpectError
ndarraylike2ndarray( x, true ); // $ExpectError
ndarraylike2ndarray( x, false ); // $ExpectError
ndarraylike2ndarray( x, null ); // $ExpectError
ndarraylike2ndarray( x, [] ); // $ExpectError
ndarraylike2ndarray( x, ( x: number ): number => x ); // $ExpectError
}
// The compiler throws an error if the function is provided an invalid `mode` option...
{
const x = array();
ndarraylike2ndarray( x, { 'mode': '5' } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': 123 } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': true } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': false } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': null } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': [] } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': {} } ); // $ExpectError
ndarraylike2ndarray( x, { 'mode': ( x: number ): number => x } ); // $ExpectError
}
// The compiler throws an error if the function is provided an invalid `submode` option...
{
const x = array();
ndarraylike2ndarray( x, { 'submode': '5' } ); // $ExpectError
ndarraylike2ndarray( x, { 'submode': 123 } ); // $ExpectError
ndarraylike2ndarray( x, { 'submode': true } ); // $ExpectError
ndarraylike2ndarray( x, { 'submode': false } ); // $ExpectError
ndarraylike2ndarray( x, { 'submode': null } ); // $ExpectError
ndarraylike2ndarray( x, { 'submode': {} } ); // $ExpectError
ndarraylike2ndarray( x, { 'submode': ( x: number ): number => x } ); // $ExpectError
}
// The compiler throws an error if the function is provided an invalid `readonly` option...
{
const x = array();
ndarraylike2ndarray( x, { 'readonly': '5' } ); // $ExpectError
ndarraylike2ndarray( x, { 'readonly': 123 } ); // $ExpectError
ndarraylike2ndarray( x, { 'readonly': null } ); // $ExpectError
ndarraylike2ndarray( x, { 'readonly': [] } ); // $ExpectError
ndarraylike2ndarray( x, { 'readonly': {} } ); // $ExpectError
ndarraylike2ndarray( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError
}
// The compiler throws an error if the function is provided an unsupported number of arguments...
{
const x = array();
ndarraylike2ndarray(); // $ExpectError
ndarraylike2ndarray( x, 5, {}, {} ); // $ExpectError
}