|
1 | 1 | /** |
2 | 2 | * @license Apache-2.0 |
3 | 3 | * |
4 | | -* Copyright (c) 2018 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. |
|
20 | 20 |
|
21 | 21 | // MODULES // |
22 | 22 |
|
23 | | -var vm = require( 'vm' ); // TODO: handle in-browser tests |
24 | 23 | var tape = require( 'tape' ); |
25 | | -var inherit = require( '@stdlib/utils-inherit' ); |
26 | | -var Int8Array = require( '@stdlib/array-int8' ); |
27 | | -var Uint8Array = require( '@stdlib/array-uint8' ); |
28 | | -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); |
29 | | -var Int16Array = require( '@stdlib/array-int16' ); |
30 | | -var Uint16Array = require( '@stdlib/array-uint16' ); |
31 | | -var Int32Array = require( '@stdlib/array-int32' ); |
32 | | -var Uint32Array = require( '@stdlib/array-uint32' ); |
33 | | -var Float32Array = require( '@stdlib/array-float32' ); |
34 | | -var Float64Array = require( '@stdlib/array-float64' ); |
35 | | -var Complex64Array = require( '@stdlib/array-complex64' ); |
36 | | -var Complex128Array = require( '@stdlib/array-complex128' ); |
37 | | -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); |
38 | | -var isComplexTypedArray = require( './../../dist' ); |
39 | | - |
40 | | - |
41 | | -// VARIABLES // |
42 | | - |
43 | | -var opts = { |
44 | | - 'skip': IS_BROWSER |
45 | | -}; |
| 24 | +var main = require( './../../dist' ); |
46 | 25 |
|
47 | 26 |
|
48 | 27 | // TESTS // |
49 | 28 |
|
50 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
51 | 30 | t.ok( true, __filename ); |
52 | | - t.strictEqual( typeof isComplexTypedArray, 'function', 'main export is a function' ); |
53 | | - t.end(); |
54 | | -}); |
55 | | - |
56 | | -tape( 'the function returns `true` if provided a complex typed array', function test( t ) { |
57 | | - var values; |
58 | | - var i; |
59 | | - |
60 | | - values = [ |
61 | | - new Complex128Array( 10 ), |
62 | | - new Complex64Array( 10 ) |
63 | | - ]; |
64 | | - |
65 | | - for ( i = 0; i < values.length; i++ ) { |
66 | | - t.strictEqual( isComplexTypedArray( values[i] ), true, 'returns true when provided '+values[i] ); |
67 | | - } |
68 | | - t.end(); |
69 | | -}); |
70 | | - |
71 | | -tape( 'the function returns `false` if provided a non-complex typed array', function test( t ) { |
72 | | - var values; |
73 | | - var i; |
74 | | - |
75 | | - values = [ |
76 | | - new Int8Array( 10 ), |
77 | | - new Uint8Array( 10 ), |
78 | | - new Uint8ClampedArray( 10 ), |
79 | | - new Int16Array( 10 ), |
80 | | - new Uint16Array( 10 ), |
81 | | - new Int32Array( 10 ), |
82 | | - new Uint32Array( 10 ), |
83 | | - new Float32Array( 10 ), |
84 | | - new Float64Array( 10 ) |
85 | | - ]; |
86 | | - |
87 | | - for ( i = 0; i < values.length; i++ ) { |
88 | | - t.strictEqual( isComplexTypedArray( values[i] ), false, 'returns true when provided '+values[i] ); |
89 | | - } |
90 | | - t.end(); |
91 | | -}); |
92 | | - |
93 | | -tape( 'the function returns `true` if provided an object inheriting from a complex typed array', function test( t ) { |
94 | | - function CustomArray( data ) { |
95 | | - var i; |
96 | | - for ( i = 0; i < data.length; i++ ) { |
97 | | - this[ i ] = data[ i ]; |
98 | | - } |
99 | | - return this; |
100 | | - } |
101 | | - |
102 | | - inherit( CustomArray, Complex64Array ); |
103 | | - |
104 | | - t.strictEqual( isComplexTypedArray( new CustomArray( [ 5.0, 3.0 ] ) ), true, 'returns true when provided a value which inherits from a complex typed array' ); |
105 | | - t.end(); |
106 | | -}); |
107 | | - |
108 | | -tape( 'the function returns `true` if provided a complex typed array from a different realm', opts, function test( t ) { |
109 | | - var ctx; |
110 | | - var arr; |
111 | | - |
112 | | - // FIXME: this test does not test what it is supposed to test. Since `require` is from the same realm, we generate objects from the same realm. In order to fix this, we need to create a "new" require function with a fresh cache. This has been done elsewhere in the project, but requires a bit of code to achieve. |
113 | | - ctx = { |
114 | | - 'require': require |
115 | | - }; |
116 | | - arr = vm.runInNewContext( 'new ( require( "@stdlib/array/complex64" ) )( [ 5.0, 3.0 ] )', ctx ); |
117 | | - t.strictEqual( isComplexTypedArray( arr ), true, 'returns true' ); |
118 | | - |
119 | | - t.end(); |
120 | | -}); |
121 | | - |
122 | | -tape( 'the function returns `true` if provided an object from a different realm which inherits from a complex typed array', opts, function test( t ) { |
123 | | - var ctx; |
124 | | - var arr; |
125 | | - |
126 | | - // FIXME: this test does not test what it is supposed to test. Since `require` is from the same realm, we generate objects from the same realm. In order to fix this, we need to create a "new" require function with a fresh cache. This has been done elsewhere in the project, but requires a bit of code to achieve. |
127 | | - ctx = { |
128 | | - 'require': require |
129 | | - }; |
130 | | - arr = vm.runInNewContext( 'function Arr() { return this; }; Arr.prototype = Object.create( require( "@stdlib/array/complex64" ).prototype ); Arr.prototype.constructor = Arr; new Arr( [ 5.0, 3.0 ] );', ctx ); |
131 | | - t.strictEqual( isComplexTypedArray( arr ), true, 'returns true' ); |
132 | | - |
133 | | - t.end(); |
134 | | -}); |
135 | | - |
136 | | -tape( 'the function returns `false` if not provided a complex typed array', function test( t ) { |
137 | | - var values; |
138 | | - var i; |
139 | | - |
140 | | - values = [ |
141 | | - '5', |
142 | | - 5, |
143 | | - NaN, |
144 | | - null, |
145 | | - void 0, |
146 | | - true, |
147 | | - false, |
148 | | - [], |
149 | | - {}, |
150 | | - function noop() {} |
151 | | - ]; |
152 | | - |
153 | | - for ( i = 0; i < values.length; i++ ) { |
154 | | - t.strictEqual( isComplexTypedArray( values[i] ), false, 'returns false when provided '+values[i] ); |
155 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
156 | 32 | t.end(); |
157 | 33 | }); |
0 commit comments