|
1 | 1 | /** |
2 | 2 | * @license Apache-2.0 |
3 | 3 | * |
4 | | -* Copyright (c) 2022 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | * |
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | * you may not use this file except in compliance with the License. |
|
21 | 21 | // MODULES // |
22 | 22 |
|
23 | 23 | var tape = require( 'tape' ); |
24 | | -var Float64Array = require( '@stdlib/array-float64' ); |
25 | | -var Float32Array = require( '@stdlib/array-float32' ); |
26 | | -var Int32Array = require( '@stdlib/array-int32' ); |
27 | | -var Uint32Array = require( '@stdlib/array-uint32' ); |
28 | | -var Int16Array = require( '@stdlib/array-int16' ); |
29 | | -var Uint16Array = require( '@stdlib/array-uint16' ); |
30 | | -var Int8Array = require( '@stdlib/array-int8' ); |
31 | | -var Uint8Array = require( '@stdlib/array-uint8' ); |
32 | | -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); |
33 | | -var Complex64Array = require( '@stdlib/array-complex64' ); |
34 | | -var Complex128Array = require( '@stdlib/array-complex128' ); |
35 | | -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); |
36 | | -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); |
37 | | -var instanceOf = require( '@stdlib/assert-instance-of' ); |
38 | | -var zeros = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
39 | 25 |
|
40 | 26 |
|
41 | 27 | // TESTS // |
42 | 28 |
|
43 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
44 | 30 | t.ok( true, __filename ); |
45 | | - t.strictEqual( typeof zeros, 'function', 'main export is a function' ); |
46 | | - t.end(); |
47 | | -}); |
48 | | - |
49 | | -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { |
50 | | - var values; |
51 | | - var i; |
52 | | - |
53 | | - values = [ |
54 | | - '5', |
55 | | - -3, |
56 | | - 3.14, |
57 | | - NaN, |
58 | | - true, |
59 | | - false, |
60 | | - null, |
61 | | - void 0, |
62 | | - [], |
63 | | - {}, |
64 | | - function noop() {} |
65 | | - ]; |
66 | | - |
67 | | - for ( i = 0; i < values.length; i++ ) { |
68 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
69 | | - } |
70 | | - t.end(); |
71 | | - |
72 | | - function badValue( value ) { |
73 | | - return function badValue() { |
74 | | - zeros( value ); |
75 | | - }; |
76 | | - } |
77 | | -}); |
78 | | - |
79 | | -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { |
80 | | - var values; |
81 | | - var i; |
82 | | - |
83 | | - values = [ |
84 | | - '5', |
85 | | - -3, |
86 | | - 3.14, |
87 | | - NaN, |
88 | | - true, |
89 | | - false, |
90 | | - null, |
91 | | - void 0, |
92 | | - [], |
93 | | - {}, |
94 | | - function noop() {} |
95 | | - ]; |
96 | | - |
97 | | - for ( i = 0; i < values.length; i++ ) { |
98 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
99 | | - } |
100 | | - t.end(); |
101 | | - |
102 | | - function badValue( value ) { |
103 | | - return function badValue() { |
104 | | - zeros( value, 'float32' ); |
105 | | - }; |
106 | | - } |
107 | | -}); |
108 | | - |
109 | | -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { |
110 | | - var values; |
111 | | - var i; |
112 | | - |
113 | | - values = [ |
114 | | - '5', |
115 | | - 'beep', |
116 | | - 'zeros', |
117 | | - 'Int32', |
118 | | - 'Uint32', |
119 | | - 'Int16', |
120 | | - 'Uint16', |
121 | | - 'Int8', |
122 | | - 'Uint8', |
123 | | - 'Uint8c', |
124 | | - 'uint8_clamped', |
125 | | - 'Float64', |
126 | | - 'Float32', |
127 | | - 'FLOAT64', |
128 | | - 'FLOAT32', |
129 | | - 'GENERIC' |
130 | | - ]; |
131 | | - |
132 | | - for ( i = 0; i < values.length; i++ ) { |
133 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
134 | | - } |
135 | | - t.end(); |
136 | | - |
137 | | - function badValue( value ) { |
138 | | - return function badValue() { |
139 | | - zeros( 10, value ); |
140 | | - }; |
141 | | - } |
142 | | -}); |
143 | | - |
144 | | -tape( 'the function returns a zero-filled array (default)', function test( t ) { |
145 | | - var expected; |
146 | | - var arr; |
147 | | - |
148 | | - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
149 | | - |
150 | | - arr = zeros( 5 ); |
151 | | - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); |
152 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
153 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
154 | | - |
155 | | - t.end(); |
156 | | -}); |
157 | | - |
158 | | -tape( 'the function returns a zero-filled array (dtype=float64)', function test( t ) { |
159 | | - var expected; |
160 | | - var arr; |
161 | | - |
162 | | - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
163 | | - |
164 | | - arr = zeros( 5, 'float64' ); |
165 | | - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); |
166 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
167 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
168 | | - |
169 | | - t.end(); |
170 | | -}); |
171 | | - |
172 | | -tape( 'the function returns a zero-filled array (dtype=float32)', function test( t ) { |
173 | | - var expected; |
174 | | - var arr; |
175 | | - |
176 | | - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
177 | | - |
178 | | - arr = zeros( 5, 'float32' ); |
179 | | - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); |
180 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
181 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
182 | | - |
183 | | - t.end(); |
184 | | -}); |
185 | | - |
186 | | -tape( 'the function returns a zero-filled array (dtype=complex128)', function test( t ) { |
187 | | - var expected; |
188 | | - var arr; |
189 | | - |
190 | | - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); |
191 | | - |
192 | | - arr = zeros( 2, 'complex128' ); |
193 | | - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); |
194 | | - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); |
195 | | - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); |
196 | | - |
197 | | - t.end(); |
198 | | -}); |
199 | | - |
200 | | -tape( 'the function returns a zero-filled array (dtype=complex64)', function test( t ) { |
201 | | - var expected; |
202 | | - var arr; |
203 | | - |
204 | | - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); |
205 | | - |
206 | | - arr = zeros( 2, 'complex64' ); |
207 | | - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); |
208 | | - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); |
209 | | - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); |
210 | | - |
211 | | - t.end(); |
212 | | -}); |
213 | | - |
214 | | -tape( 'the function returns a zero-filled array (dtype=int32)', function test( t ) { |
215 | | - var expected; |
216 | | - var arr; |
217 | | - |
218 | | - expected = new Int32Array( [ 0, 0, 0, 0, 0 ] ); |
219 | | - |
220 | | - arr = zeros( 5, 'int32' ); |
221 | | - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); |
222 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
223 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
224 | | - |
225 | | - t.end(); |
226 | | -}); |
227 | | - |
228 | | -tape( 'the function returns a zero-filled array (dtype=uint32)', function test( t ) { |
229 | | - var expected; |
230 | | - var arr; |
231 | | - |
232 | | - expected = new Uint32Array( [ 0, 0, 0, 0, 0 ] ); |
233 | | - |
234 | | - arr = zeros( 5, 'uint32' ); |
235 | | - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); |
236 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
237 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
238 | | - |
239 | | - t.end(); |
240 | | -}); |
241 | | - |
242 | | -tape( 'the function returns a zero-filled array (dtype=int16)', function test( t ) { |
243 | | - var expected; |
244 | | - var arr; |
245 | | - |
246 | | - expected = new Int16Array( [ 0, 0, 0, 0, 0 ] ); |
247 | | - |
248 | | - arr = zeros( 5, 'int16' ); |
249 | | - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); |
250 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
251 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
252 | | - |
253 | | - t.end(); |
254 | | -}); |
255 | | - |
256 | | -tape( 'the function returns a zero-filled array (dtype=uint16)', function test( t ) { |
257 | | - var expected; |
258 | | - var arr; |
259 | | - |
260 | | - expected = new Uint16Array( [ 0, 0, 0, 0, 0 ] ); |
261 | | - |
262 | | - arr = zeros( 5, 'uint16' ); |
263 | | - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); |
264 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
265 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
266 | | - |
267 | | - t.end(); |
268 | | -}); |
269 | | - |
270 | | -tape( 'the function returns a zero-filled array (dtype=int8)', function test( t ) { |
271 | | - var expected; |
272 | | - var arr; |
273 | | - |
274 | | - expected = new Int8Array( [ 0, 0, 0, 0, 0 ] ); |
275 | | - |
276 | | - arr = zeros( 5, 'int8' ); |
277 | | - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); |
278 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
279 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
280 | | - |
281 | | - t.end(); |
282 | | -}); |
283 | | - |
284 | | -tape( 'the function returns a zero-filled array (dtype=uint8)', function test( t ) { |
285 | | - var expected; |
286 | | - var arr; |
287 | | - |
288 | | - expected = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); |
289 | | - |
290 | | - arr = zeros( 5, 'uint8' ); |
291 | | - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); |
292 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
293 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
294 | | - |
295 | | - t.end(); |
296 | | -}); |
297 | | - |
298 | | -tape( 'the function returns a zero-filled array (dtype=uint8c)', function test( t ) { |
299 | | - var expected; |
300 | | - var arr; |
301 | | - |
302 | | - expected = new Uint8ClampedArray( [ 0, 0, 0, 0, 0 ] ); |
303 | | - |
304 | | - arr = zeros( 5, 'uint8c' ); |
305 | | - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); |
306 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
307 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
308 | | - |
309 | | - t.end(); |
310 | | -}); |
311 | | - |
312 | | -tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { |
313 | | - var expected; |
314 | | - var arr; |
315 | | - |
316 | | - expected = [ 0, 0, 0, 0, 0 ]; |
317 | | - |
318 | | - arr = zeros( 5, 'generic' ); |
319 | | - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); |
320 | | - t.strictEqual( arr.length, expected.length, 'returns expected value' ); |
321 | | - t.deepEqual( arr, expected, 'returns expected value' ); |
322 | | - |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
323 | 32 | t.end(); |
324 | 33 | }); |
0 commit comments