Skip to content

Commit 6e6a3c6

Browse files
committed
Add tests for complex array data buffers
1 parent 00c51cc commit 6e6a3c6

File tree

4 files changed

+247
-0
lines changed

4 files changed

+247
-0
lines changed

lib/node_modules/@stdlib/ndarray/ctor/test/test.argument_validation.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ tape( 'the constructor throws an error if not provided a valid `buffer` argument
135135
null,
136136
void 0,
137137
{},
138+
{
139+
'length': 10,
140+
'get': function noop() {},
141+
'set': true
142+
},
143+
{
144+
'length': 10,
145+
'get': true,
146+
'set': function noop() {}
147+
},
138148
function noop() {}
139149
];
140150
for ( i = 0; i < values.length; i++ ) {
@@ -173,6 +183,16 @@ tape( 'the constructor throws an error if not provided a valid `buffer` argument
173183
null,
174184
void 0,
175185
{},
186+
{
187+
'length': 10,
188+
'get': function noop() {},
189+
'set': true
190+
},
191+
{
192+
'length': 10,
193+
'get': true,
194+
'set': function noop() {}
195+
},
176196
function noop() {}
177197
];
178198
for ( i = 0; i < values.length; i++ ) {

lib/node_modules/@stdlib/ndarray/ctor/test/test.instance.tojson.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var Float64Array = require( '@stdlib/array/float64' );
25+
var Complex64Array = require( '@stdlib/array/complex64' );
2526
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2627
var hasProp = require( '@stdlib/assert/has-property' );
2728
var isFunction = require( '@stdlib/assert/is-function' );
@@ -152,3 +153,42 @@ tape( 'an ndarray constructor returns an instance which has a custom `toJSON()`
152153

153154
t.end();
154155
});
156+
157+
tape( 'an ndarray constructor returns an instance which has a custom `toJSON()` method (complex type)', function test( t ) {
158+
var expected;
159+
var strides;
160+
var actual;
161+
var buffer;
162+
var offset;
163+
var dtype;
164+
var order;
165+
var shape;
166+
var arr;
167+
168+
dtype = 'complex64';
169+
buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
170+
shape = [ 2, 2 ];
171+
order = 'row-major';
172+
strides = [ 2, 1 ];
173+
offset = 0;
174+
175+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
176+
177+
t.strictEqual( hasOwnProp( arr, 'toJSON' ), false, 'does not have own property' );
178+
t.strictEqual( hasProp( arr, 'toJSON' ), true, 'has property' );
179+
t.strictEqual( isFunction( arr.toJSON ), true, 'has method' );
180+
181+
expected = {
182+
'type': 'ndarray',
183+
'dtype': 'complex64',
184+
'data': [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ],
185+
'shape': [ 2, 2 ],
186+
'strides': [ 2, 1 ],
187+
'order': 'row-major',
188+
'flags': {}
189+
};
190+
actual = arr.toJSON();
191+
t.deepEqual( actual, expected, 'returns expected value' );
192+
193+
t.end();
194+
});

lib/node_modules/@stdlib/ndarray/ctor/test/test.instance.tostring.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var tape = require( 'tape' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var hasProp = require( '@stdlib/assert/has-property' );
2626
var isFunction = require( '@stdlib/assert/is-function' );
27+
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var Complex64Array = require( '@stdlib/array/complex64' );
29+
var Complex64 = require( '@stdlib/complex/float32' );
30+
var Complex128 = require( '@stdlib/complex/float64' );
2731
var ndarray = require( './../lib' );
2832

2933

@@ -97,6 +101,68 @@ tape( 'an ndarray constructor returns an instance which has a custom `toString()
97101
t.end();
98102
});
99103

104+
tape( 'an ndarray constructor returns an instance which has a custom `toString()` method (complex type)', function test( t ) {
105+
var expected;
106+
var strides;
107+
var actual;
108+
var buffer;
109+
var offset;
110+
var dtype;
111+
var order;
112+
var shape;
113+
var arr;
114+
115+
dtype = 'complex64';
116+
buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
117+
shape = [ 2, 2 ];
118+
order = 'row-major';
119+
strides = [ 2, 1 ];
120+
offset = 0;
121+
122+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
123+
124+
t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' );
125+
t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' );
126+
t.strictEqual( isFunction( arr.toString ), true, 'has method' );
127+
128+
expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
129+
actual = arr.toString();
130+
t.strictEqual( actual, expected, 'returns expected value' );
131+
132+
t.end();
133+
});
134+
135+
tape( 'an ndarray constructor returns an instance which has a custom `toString()` method (complex type)', function test( t ) {
136+
var expected;
137+
var strides;
138+
var actual;
139+
var buffer;
140+
var offset;
141+
var dtype;
142+
var order;
143+
var shape;
144+
var arr;
145+
146+
dtype = 'complex128';
147+
buffer = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
148+
shape = [ 2, 2 ];
149+
order = 'row-major';
150+
strides = [ 2, 1 ];
151+
offset = 0;
152+
153+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
154+
155+
t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' );
156+
t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' );
157+
t.strictEqual( isFunction( arr.toString ), true, 'has method' );
158+
159+
expected = 'ndarray( \'complex128\', new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
160+
actual = arr.toString();
161+
t.strictEqual( actual, expected, 'returns expected value' );
162+
163+
t.end();
164+
});
165+
100166
tape( 'an ndarray constructor returns an instance which has a custom `toString()` method (large array)', function test( t ) {
101167
var expected;
102168
var strides;
@@ -135,6 +201,82 @@ tape( 'an ndarray constructor returns an instance which has a custom `toString()
135201
t.end();
136202
});
137203

204+
tape( 'an ndarray constructor returns an instance which has a custom `toString()` method (large array; complex type)', function test( t ) {
205+
var expected;
206+
var strides;
207+
var actual;
208+
var buffer;
209+
var offset;
210+
var dtype;
211+
var order;
212+
var shape;
213+
var arr;
214+
215+
dtype = 'complex64';
216+
buffer = new Complex64Array( 1e4 );
217+
shape = [ buffer.length ];
218+
order = 'row-major';
219+
strides = [ 1 ];
220+
offset = 0;
221+
222+
buffer.set( new Complex64( 1.0, 1.0 ), 0 );
223+
buffer.set( new Complex64( 2.0, 2.0 ), 1 );
224+
buffer.set( new Complex64( 3.0, 3.0 ), 2 );
225+
buffer.set( new Complex64( 4.0, 4.0 ), buffer.length-3 );
226+
buffer.set( new Complex64( 5.0, 5.0 ), buffer.length-2 );
227+
buffer.set( new Complex64( 6.0, 6.0 ), buffer.length-1 );
228+
229+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
230+
231+
t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' );
232+
t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' );
233+
t.strictEqual( isFunction( arr.toString ), true, 'has method' );
234+
235+
expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 1, 2, 2, 3, 3, ..., 4, 4, 5, 5, 6, 6 ] ), [ 10000 ], [ 1 ], 0, \'row-major\' )';
236+
actual = arr.toString();
237+
t.strictEqual( actual, expected, 'returns expected value' );
238+
239+
t.end();
240+
});
241+
242+
tape( 'an ndarray constructor returns an instance which has a custom `toString()` method (large array; complex type)', function test( t ) {
243+
var expected;
244+
var strides;
245+
var actual;
246+
var buffer;
247+
var offset;
248+
var dtype;
249+
var order;
250+
var shape;
251+
var arr;
252+
253+
dtype = 'complex128';
254+
buffer = new Complex128Array( 1e4 );
255+
shape = [ buffer.length ];
256+
order = 'row-major';
257+
strides = [ 1 ];
258+
offset = 0;
259+
260+
buffer.set( new Complex128( 1.0, 1.0 ), 0 );
261+
buffer.set( new Complex128( 2.0, 2.0 ), 1 );
262+
buffer.set( new Complex128( 3.0, 3.0 ), 2 );
263+
buffer.set( new Complex128( 4.0, 4.0 ), buffer.length-3 );
264+
buffer.set( new Complex128( 5.0, 5.0 ), buffer.length-2 );
265+
buffer.set( new Complex128( 6.0, 6.0 ), buffer.length-1 );
266+
267+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
268+
269+
t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' );
270+
t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' );
271+
t.strictEqual( isFunction( arr.toString ), true, 'has method' );
272+
273+
expected = 'ndarray( \'complex128\', new Complex128Array( [ 1, 1, 2, 2, 3, 3, ..., 4, 4, 5, 5, 6, 6 ] ), [ 10000 ], [ 1 ], 0, \'row-major\' )';
274+
actual = arr.toString();
275+
t.strictEqual( actual, expected, 'returns expected value' );
276+
277+
t.end();
278+
});
279+
138280
tape( 'an ndarray constructor returns an instance which has a custom `toString()` method (0d)', function test( t ) {
139281
var expected;
140282
var strides;

lib/node_modules/@stdlib/ndarray/ctor/test/test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var instanceOf = require( '@stdlib/assert/instance-of' );
25+
var Complex64Array = require( '@stdlib/array/complex64' );
2526
var ndarray = require( './../lib' );
2627

2728

@@ -55,6 +56,28 @@ tape( 'the function is an ndarray constructor', function test( t ) {
5556
t.end();
5657
});
5758

59+
tape( 'the function is an ndarray constructor (complex dtype)', function test( t ) {
60+
var strides;
61+
var buffer;
62+
var offset;
63+
var dtype;
64+
var order;
65+
var shape;
66+
var arr;
67+
68+
dtype = 'complex64';
69+
buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
70+
shape = [ 2, 2 ];
71+
order = 'row-major';
72+
strides = [ 2, 1 ];
73+
offset = 0;
74+
75+
arr = new ndarray( dtype, buffer, shape, strides, offset, order );
76+
77+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' );
78+
t.end();
79+
});
80+
5881
tape( 'the function is an ndarray constructor (0d)', function test( t ) {
5982
var strides;
6083
var buffer;
@@ -77,6 +100,28 @@ tape( 'the function is an ndarray constructor (0d)', function test( t ) {
77100
t.end();
78101
});
79102

103+
tape( 'the function is an ndarray constructor (0d; complex dtype)', function test( t ) {
104+
var strides;
105+
var buffer;
106+
var offset;
107+
var dtype;
108+
var order;
109+
var shape;
110+
var arr;
111+
112+
dtype = 'complex64';
113+
buffer = new Complex64Array( [ 1.0, 1.0 ] );
114+
shape = [];
115+
order = 'row-major';
116+
strides = [ 0 ];
117+
offset = 0;
118+
119+
arr = new ndarray( dtype, buffer, shape, strides, offset, order );
120+
121+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' );
122+
t.end();
123+
});
124+
80125
tape( 'the function is an ndarray constructor (options)', function test( t ) {
81126
var strides;
82127
var buffer;

0 commit comments

Comments
 (0)