Skip to content

Commit 9c5ed90

Browse files
committed
test: ensure full test coverage
1 parent a4513e8 commit 9c5ed90

File tree

1 file changed

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

1 file changed

+104
-0
lines changed

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

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,17 @@ tape( 'the function applies a callback to each indexed element in an input ndarr
300300
o = strides2offset( sh, st );
301301
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
302302

303+
opts = {};
304+
y = map( x, opts, scale );
305+
306+
expected = new Float64Array([
307+
10.0,
308+
10.0,
309+
10.0,
310+
10.0
311+
]);
312+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
313+
303314
opts = {
304315
'dtype': 'float32'
305316
};
@@ -338,6 +349,17 @@ tape( 'the function applies a callback to each indexed element in an input ndarr
338349
o = strides2offset( sh, st );
339350
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
340351

352+
opts = {};
353+
y = map( x, opts, scale );
354+
355+
expected = new Float64Array([
356+
10.0,
357+
10.0,
358+
10.0,
359+
10.0
360+
]);
361+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
362+
341363
opts = {
342364
'dtype': 'float32'
343365
};
@@ -503,3 +525,85 @@ tape( 'the function applies a callback to each indexed element in an input ndarr
503525
return z * 10.0;
504526
}
505527
});
528+
529+
tape( 'the function supports providing a callback execution context', function test( t ) {
530+
var expected;
531+
var ctx;
532+
var ord;
533+
var sh;
534+
var st;
535+
var dt;
536+
var o;
537+
var x;
538+
var y;
539+
540+
dt = 'float64';
541+
ord = 'row-major';
542+
sh = [ 2, 1, 2 ];
543+
st = shape2strides( sh, ord );
544+
o = strides2offset( sh, st );
545+
546+
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
547+
548+
ctx = {
549+
'count': 0
550+
};
551+
y = map( x, scale, ctx );
552+
553+
expected = new Float64Array([
554+
10.0,
555+
10.0,
556+
10.0,
557+
10.0
558+
]);
559+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
560+
t.strictEqual( ctx.count, 4, 'returns expected value' );
561+
562+
t.end();
563+
564+
function scale( z ) {
565+
this.count += 1; // eslint-disable-line no-invalid-this
566+
return z * 10.0;
567+
}
568+
});
569+
570+
tape( 'the function supports providing a callback execution context (options)', function test( t ) {
571+
var expected;
572+
var ctx;
573+
var ord;
574+
var sh;
575+
var st;
576+
var dt;
577+
var o;
578+
var x;
579+
var y;
580+
581+
dt = 'float64';
582+
ord = 'row-major';
583+
sh = [ 2, 1, 2 ];
584+
st = shape2strides( sh, ord );
585+
o = strides2offset( sh, st );
586+
587+
x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord );
588+
589+
ctx = {
590+
'count': 0
591+
};
592+
y = map( x, {}, scale, ctx );
593+
594+
expected = new Float64Array([
595+
10.0,
596+
10.0,
597+
10.0,
598+
10.0
599+
]);
600+
t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' );
601+
t.strictEqual( ctx.count, 4, 'returns expected value' );
602+
603+
t.end();
604+
605+
function scale( z ) {
606+
this.count += 1; // eslint-disable-line no-invalid-this
607+
return z * 10.0;
608+
}
609+
});

0 commit comments

Comments
 (0)