Skip to content

Commit cf9dac1

Browse files
committed
Add explicit accessor tests
1 parent 796140f commit cf9dac1

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

  • lib/node_modules/@stdlib/array/convert/test

lib/node_modules/@stdlib/array/convert/test/test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,62 @@ tape( 'the function converts an array to an array of a different data type', fun
158158
});
159159

160160
tape( 'the function converts an array to an array of a different data type (accessors)', function test( t ) {
161+
var expected;
162+
var dtypes;
163+
var arr;
164+
var out;
165+
var i;
166+
var j;
167+
168+
dtypes = [
169+
'float64',
170+
'float32',
171+
'generic',
172+
'int16',
173+
'int32',
174+
'int8',
175+
'uint16',
176+
'uint32',
177+
'uint8',
178+
'uint8c'
179+
];
180+
arr = {
181+
'length': 3,
182+
'data': [ -1, 0, 1 ],
183+
'get': getter,
184+
'set': setter
185+
};
186+
expected = [
187+
[ new Float64Array( [ -1.0, 0.0, 1.0 ] ), isFloat64Array ],
188+
[ new Float32Array( [ -1.0, 0.0, 1.0 ] ), isFloat32Array ],
189+
[ [ -1, 0, 1 ], isArray ],
190+
[ new Int16Array( [ -1, 0, 1 ] ), isInt16Array ],
191+
[ new Int32Array( [ -1, 0, 1 ] ), isInt32Array ],
192+
[ new Int8Array( [ -1, 0, 1 ] ), isInt8Array ],
193+
[ new Uint16Array( [ 65535, 0, 1 ] ), isUint16Array ],
194+
[ new Uint32Array( [ 4294967295, 0, 1 ] ), isUint32Array ],
195+
[ new Uint8Array( [ 255, 0, 1 ] ), isUint8Array ],
196+
[ new Uint8ClampedArray( [ 0, 0, 1 ] ), isUint8ClampedArray ]
197+
];
198+
for ( i = 0; i < dtypes.length; i++ ) {
199+
out = convertArray( arr, dtypes[ i ] );
200+
t.strictEqual( expected[ i ][ 1 ]( out ), true, 'returns expected value type for ' + dtypes[ i ] );
201+
for ( j = 0; j < arr.length; j++ ) {
202+
t.strictEqual( out[ j ], expected[ i ][ 0 ][ j ], 'returns expected element ' + j + ' for ' + dtypes[ i ] );
203+
}
204+
}
205+
t.end();
206+
207+
function getter( idx ) {
208+
return arr.data[ idx ];
209+
}
210+
211+
function setter( value, idx ) {
212+
arr.data[ idx ] = value;
213+
}
214+
});
215+
216+
tape( 'the function converts an array to an array of a different data type (real => complex)', function test( t ) {
161217
var expected;
162218
var dtypes;
163219
var arr;
@@ -191,6 +247,8 @@ tape( 'the function converts an array to an array of a different data type (acce
191247
t.end();
192248
});
193249

250+
// TODO: add more tests to cover all code paths
251+
194252
tape( 'the function converts an array to an array of a different data type (large allocations)', function test( t ) {
195253
var expected;
196254
var dtypes;

0 commit comments

Comments
 (0)