|
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 Complex64Array = require( '@stdlib/array-complex64' ); |
26 | | -var Complex64 = require( '@stdlib/complex-float32' ); |
27 | | -var array = require( '@stdlib/ndarray-array' ); |
28 | | -var ndarray = require( '@stdlib/ndarray-ctor' ); |
29 | | -var realf = require( '@stdlib/complex-realf' ); |
30 | | -var imagf = require( '@stdlib/complex-imagf' ); |
31 | | -var ndarraylike2object = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
32 | 25 |
|
33 | 26 |
|
34 | 27 | // TESTS // |
35 | 28 |
|
36 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
37 | 30 | t.ok( true, __filename ); |
38 | | - t.strictEqual( typeof ndarraylike2object, 'function', 'main export is a function' ); |
39 | | - t.end(); |
40 | | -}); |
41 | | - |
42 | | -tape( 'the function converts an ndarray to a standardized object', function test( t ) { |
43 | | - var expected; |
44 | | - var actual; |
45 | | - var xbuf; |
46 | | - var x; |
47 | | - var v; |
48 | | - |
49 | | - xbuf = new Float64Array( 10 ); |
50 | | - x = array( xbuf ); |
51 | | - |
52 | | - expected = { |
53 | | - 'ref': x, |
54 | | - 'data': x.data, |
55 | | - 'dtype': x.dtype, |
56 | | - 'length': x.length, |
57 | | - 'shape': x.shape, |
58 | | - 'strides': x.strides, |
59 | | - 'offset': x.offset, |
60 | | - 'order': x.order, |
61 | | - 'accessorProtocol': false |
62 | | - }; |
63 | | - actual = ndarraylike2object( x ); |
64 | | - |
65 | | - t.strictEqual( actual.ref, expected.ref, 'returns expected value' ); |
66 | | - t.strictEqual( actual.data, expected.data, 'returns expected value' ); |
67 | | - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); |
68 | | - t.strictEqual( actual.length, expected.length, 'returns expected value' ); |
69 | | - t.deepEqual( actual.shape, expected.shape, 'returns expected value' ); |
70 | | - t.deepEqual( actual.strides, expected.strides, 'returns expected value' ); |
71 | | - t.strictEqual( actual.offset, expected.offset, 'returns expected value' ); |
72 | | - t.strictEqual( actual.order, expected.order, 'returns expected value' ); |
73 | | - t.strictEqual( actual.accessorProtocol, expected.accessorProtocol, 'returns expected value' ); |
74 | | - t.strictEqual( typeof actual.accessors[ 0 ], 'function', 'returns expected value' ); |
75 | | - t.strictEqual( actual.accessors[ 0 ].length, 2, 'returns expected value' ); |
76 | | - t.strictEqual( typeof actual.accessors[ 1 ], 'function', 'returns expected value' ); |
77 | | - t.strictEqual( actual.accessors[ 1 ].length, 3, 'returns expected value' ); |
78 | | - |
79 | | - actual.accessors[ 1 ]( actual.data, 0, 1.0 ); |
80 | | - v = actual.accessors[ 0 ]( actual.data, 0 ); |
81 | | - t.strictEqual( v, 1.0, 'returns expected value' ); |
82 | | - |
83 | | - t.end(); |
84 | | -}); |
85 | | - |
86 | | -tape( 'the function converts an ndarray-like object to a standardized object', function test( t ) { |
87 | | - var expected; |
88 | | - var actual; |
89 | | - var xbuf; |
90 | | - var x; |
91 | | - var v; |
92 | | - |
93 | | - xbuf = new Float64Array( 10 ); |
94 | | - x = { |
95 | | - 'data': xbuf, |
96 | | - 'dtype': 'float64', |
97 | | - 'length': 10, |
98 | | - 'shape': [ 2, 5 ], |
99 | | - 'strides': [ 5, 1 ], |
100 | | - 'offset': 0, |
101 | | - 'order': 'row-major' |
102 | | - }; |
103 | | - |
104 | | - expected = { |
105 | | - 'ref': x, |
106 | | - 'data': x.data, |
107 | | - 'dtype': x.dtype, |
108 | | - 'length': x.length, |
109 | | - 'shape': x.shape, |
110 | | - 'strides': x.strides, |
111 | | - 'offset': x.offset, |
112 | | - 'order': x.order, |
113 | | - 'accessorProtocol': false |
114 | | - }; |
115 | | - actual = ndarraylike2object( x ); |
116 | | - |
117 | | - t.strictEqual( actual.ref, expected.ref, 'returns expected value' ); |
118 | | - t.strictEqual( actual.data, expected.data, 'returns expected value' ); |
119 | | - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); |
120 | | - t.strictEqual( actual.length, expected.length, 'returns expected value' ); |
121 | | - t.deepEqual( actual.shape, expected.shape, 'returns expected value' ); |
122 | | - t.deepEqual( actual.strides, expected.strides, 'returns expected value' ); |
123 | | - t.strictEqual( actual.offset, expected.offset, 'returns expected value' ); |
124 | | - t.strictEqual( actual.order, expected.order, 'returns expected value' ); |
125 | | - t.strictEqual( actual.accessorProtocol, expected.accessorProtocol, 'returns expected value' ); |
126 | | - t.strictEqual( typeof actual.accessors[ 0 ], 'function', 'returns expected value' ); |
127 | | - t.strictEqual( actual.accessors[ 0 ].length, 2, 'returns expected value' ); |
128 | | - t.strictEqual( typeof actual.accessors[ 1 ], 'function', 'returns expected value' ); |
129 | | - t.strictEqual( actual.accessors[ 1 ].length, 3, 'returns expected value' ); |
130 | | - |
131 | | - actual.accessors[ 1 ]( actual.data, 0, 1.0 ); |
132 | | - v = actual.accessors[ 0 ]( actual.data, 0 ); |
133 | | - t.strictEqual( v, 1.0, 'returns expected value' ); |
134 | | - |
135 | | - t.end(); |
136 | | -}); |
137 | | - |
138 | | -tape( 'the function converts an ndarray to a standardized object (data buffer accessors)', function test( t ) { |
139 | | - var expected; |
140 | | - var actual; |
141 | | - var xbuf; |
142 | | - var x; |
143 | | - var v; |
144 | | - |
145 | | - xbuf = new Complex64Array( 10 ); |
146 | | - x = ndarray( 'complex64', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); |
147 | | - |
148 | | - expected = { |
149 | | - 'ref': x, |
150 | | - 'data': x.data, |
151 | | - 'dtype': x.dtype, |
152 | | - 'length': x.length, |
153 | | - 'shape': x.shape, |
154 | | - 'strides': x.strides, |
155 | | - 'offset': x.offset, |
156 | | - 'order': x.order, |
157 | | - 'accessorProtocol': true |
158 | | - }; |
159 | | - actual = ndarraylike2object( x ); |
160 | | - |
161 | | - t.strictEqual( actual.ref, expected.ref, 'returns expected value' ); |
162 | | - t.strictEqual( actual.data, expected.data, 'returns expected value' ); |
163 | | - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); |
164 | | - t.strictEqual( actual.length, expected.length, 'returns expected value' ); |
165 | | - t.deepEqual( actual.shape, expected.shape, 'returns expected value' ); |
166 | | - t.deepEqual( actual.strides, expected.strides, 'returns expected value' ); |
167 | | - t.strictEqual( actual.offset, expected.offset, 'returns expected value' ); |
168 | | - t.strictEqual( actual.order, expected.order, 'returns expected value' ); |
169 | | - t.strictEqual( actual.accessorProtocol, expected.accessorProtocol, 'returns expected value' ); |
170 | | - t.strictEqual( typeof actual.accessors[ 0 ], 'function', 'returns expected value' ); |
171 | | - t.strictEqual( actual.accessors[ 0 ].length, 2, 'returns expected value' ); |
172 | | - t.strictEqual( typeof actual.accessors[ 1 ], 'function', 'returns expected value' ); |
173 | | - t.strictEqual( actual.accessors[ 1 ].length, 3, 'returns expected value' ); |
174 | | - |
175 | | - actual.accessors[ 1 ]( actual.data, 0, new Complex64( 1.0, 2.0 ) ); |
176 | | - v = actual.accessors[ 0 ]( actual.data, 0 ); |
177 | | - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); |
178 | | - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); |
179 | | - |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
180 | 32 | t.end(); |
181 | 33 | }); |
0 commit comments