Skip to content

Commit 6e828e6

Browse files
committed
Add tests
1 parent c1c8df7 commit 6e828e6

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

lib/node_modules/@stdlib/array/complex64/test/test.from.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,85 @@ tape( 'the method supports providing a "map" function which is invoked for each
545545
}
546546
});
547547

548+
tape( 'the method supports providing a `this` context for a provided map function', function test( t ) {
549+
var arr;
550+
var ctx;
551+
552+
ctx = {
553+
'count': 0
554+
};
555+
arr = Complex64Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk, ctx );
556+
t.strictEqual( arr instanceof Complex64Array, true, 'returns expected value' );
557+
t.strictEqual( ctx.count, 4, 'returns expected value' );
558+
559+
t.end();
560+
561+
function clbk( v ) {
562+
this.count += 1; // eslint-disable-line no-invalid-this
563+
return v;
564+
}
565+
});
566+
567+
tape( 'the method supports providing a `this` context for a provided map function (iterable)', function test( t ) {
568+
var Complex64Array;
569+
var iter;
570+
var ctx;
571+
var arr;
572+
573+
Complex64Array = proxyquire( './../lib/main.js', {
574+
'@stdlib/assert/has-iterator-symbol-support': hasSupport,
575+
'@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__'
576+
});
577+
578+
iter = {
579+
'next': next,
580+
'i': 0,
581+
'N': 4
582+
};
583+
ctx = {
584+
'count': 0
585+
};
586+
587+
arr = Complex64Array.from( createIterable( iter ), clbk, ctx );
588+
t.strictEqual( arr instanceof Complex64Array, true, 'returns expected value' );
589+
t.strictEqual( ctx.count, 4, 'returns expected value' );
590+
591+
t.end();
592+
593+
function hasSupport() {
594+
return true;
595+
}
596+
597+
function createIterable( iterator ) {
598+
var it = {};
599+
it[ '__SYMBOL_ITERATOR__' ] = iterable;
600+
return it;
601+
602+
function iterable() {
603+
return iterator;
604+
}
605+
}
606+
607+
function next() {
608+
iter.i += 1;
609+
if ( iter.i <= iter.N ) {
610+
return {
611+
'value': [ 1.0, 1.0 ]
612+
};
613+
}
614+
return {
615+
'done': true
616+
};
617+
}
618+
619+
function clbk( v ) {
620+
this.count += 1; // eslint-disable-line no-invalid-this
621+
v[ 0 ] += 1.0;
622+
v[ 1 ] += 1.0;
623+
return v;
624+
}
625+
});
626+
548627
tape( 'the method throws an error if provided an array-like object having an odd length', function test( t ) {
549628
var values;
550629
var i;

0 commit comments

Comments
 (0)