Skip to content

Commit 59814ef

Browse files
committed
test: add argument tests
1 parent 2e88648 commit 59814ef

File tree

1 file changed

+126
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/map/test

1 file changed

+126
-0
lines changed

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

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,129 @@ tape( 'the function supports providing a callback execution context (options)',
607607
return z * 10.0;
608608
}
609609
});
610+
611+
tape( 'the function invokes a provided callback with three arguments (row-major)', function test( t ) {
612+
var expected;
613+
var indices;
614+
var values;
615+
var arrays;
616+
var ord;
617+
var sh;
618+
var st;
619+
var dt;
620+
var o;
621+
var x;
622+
var y;
623+
var i;
624+
625+
dt = 'float64';
626+
ord = 'row-major';
627+
sh = [ 2, 1, 2 ];
628+
st = shape2strides( sh, ord );
629+
o = strides2offset( sh, st );
630+
631+
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
632+
633+
values = [];
634+
indices = [];
635+
arrays = [];
636+
y = map( x, scale );
637+
638+
expected = new Float64Array([
639+
10.0,
640+
10.0,
641+
10.0,
642+
10.0
643+
]);
644+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
645+
646+
expected = [
647+
[ 0, 0, 0 ],
648+
[ 0, 0, 1 ],
649+
[ 1, 0, 0 ],
650+
[ 1, 0, 1 ]
651+
];
652+
t.deepEqual( indices, expected, 'returns expected value' );
653+
654+
expected = [
655+
x,
656+
x,
657+
x,
658+
x
659+
];
660+
for ( i = 0; i < expected.length; i++ ) {
661+
t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' );
662+
}
663+
664+
t.end();
665+
666+
function scale( z, idx, arr ) {
667+
values.push( z );
668+
indices.push( idx );
669+
arrays.push( arr );
670+
return z * 10.0;
671+
}
672+
});
673+
674+
tape( 'the function invokes a provided callback with three arguments (column-major)', function test( t ) {
675+
var expected;
676+
var indices;
677+
var values;
678+
var arrays;
679+
var ord;
680+
var sh;
681+
var st;
682+
var dt;
683+
var o;
684+
var x;
685+
var y;
686+
var i;
687+
688+
dt = 'float64';
689+
ord = 'column-major';
690+
sh = [ 2, 1, 2 ];
691+
st = shape2strides( sh, ord );
692+
o = strides2offset( sh, st );
693+
694+
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
695+
696+
values = [];
697+
indices = [];
698+
arrays = [];
699+
y = map( x, scale );
700+
701+
expected = new Float64Array([
702+
10.0,
703+
10.0,
704+
10.0,
705+
10.0
706+
]);
707+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
708+
709+
expected = [
710+
[ 0, 0, 0 ],
711+
[ 1, 0, 0 ],
712+
[ 0, 0, 1 ],
713+
[ 1, 0, 1 ]
714+
];
715+
t.deepEqual( indices, expected, 'returns expected value' );
716+
717+
expected = [
718+
x,
719+
x,
720+
x,
721+
x
722+
];
723+
for ( i = 0; i < expected.length; i++ ) {
724+
t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' );
725+
}
726+
727+
t.end();
728+
729+
function scale( z, idx, arr ) {
730+
values.push( z );
731+
indices.push( idx );
732+
arrays.push( arr );
733+
return z * 10.0;
734+
}
735+
});

0 commit comments

Comments
 (0)