Skip to content

Commit edd9525

Browse files
committed
Add tests for setting elements in a 1d array
1 parent 70c8916 commit edd9525

2 files changed

Lines changed: 104 additions & 16 deletions

File tree

lib/node_modules/@stdlib/types/ndarray/ctor/test/test.instance.set.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
413413
t.end();
414414
});
415415

416-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major)', function test( t ) {
416+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major)', function test( t ) {
417417
var strides;
418418
var buffer;
419419
var offset;
@@ -452,7 +452,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
452452
t.end();
453453
});
454454

455-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major)', function test( t ) {
455+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major)', function test( t ) {
456456
var strides;
457457
var buffer;
458458
var offset;
@@ -491,7 +491,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
491491
t.end();
492492
});
493493

494-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major)', function test( t ) {
494+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major)', function test( t ) {
495495
var strides;
496496
var buffer;
497497
var offset;
@@ -530,7 +530,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
530530
t.end();
531531
});
532532

533-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major)', function test( t ) {
533+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major)', function test( t ) {
534534
var strides;
535535
var buffer;
536536
var offset;
@@ -569,7 +569,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
569569
t.end();
570570
});
571571

572-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major)', function test( t ) {
572+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major)', function test( t ) {
573573
var strides;
574574
var buffer;
575575
var offset;
@@ -608,7 +608,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
608608
t.end();
609609
});
610610

611-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major)', function test( t ) {
611+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major)', function test( t ) {
612612
var strides;
613613
var buffer;
614614
var offset;
@@ -647,7 +647,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
647647
t.end();
648648
});
649649

650-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major)', function test( t ) {
650+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major)', function test( t ) {
651651
var strides;
652652
var buffer;
653653
var offset;
@@ -686,7 +686,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
686686
t.end();
687687
});
688688

689-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major)', function test( t ) {
689+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major)', function test( t ) {
690690
var strides;
691691
var buffer;
692692
var offset;

lib/node_modules/@stdlib/types/ndarray/ctor/test/test.instance.set_no_codegen.js

Lines changed: 96 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,95 @@ tape( 'an ndarray constructor returns an instance which has a `set` method which
360360
}
361361
});
362362

363-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major; codegen=false)', function test( t ) {
363+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; codegen=false)', function test( t ) {
364+
var strides;
365+
var buffer;
366+
var offset;
367+
var dtype;
368+
var order;
369+
var shape;
370+
var opts;
371+
var arr;
372+
var f;
373+
374+
opts = {
375+
'codegen': false
376+
};
377+
378+
dtype = 'float64';
379+
buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
380+
shape = [ 4 ];
381+
order = 'row-major';
382+
strides = [ 1 ];
383+
offset = 0;
384+
385+
f = ctor( dtype, shape.length, opts );
386+
arr = f( buffer, shape, strides, offset, order );
387+
388+
t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' );
389+
t.strictEqual( hasProp( arr, 'set' ), true, 'has property' );
390+
t.strictEqual( isFunction( arr.set ), true, 'has method' );
391+
392+
arr.set( 0, 5.0 );
393+
arr.set( 1, 6.0 );
394+
arr.set( 2, 7.0 );
395+
arr.set( 3, 8.0 );
396+
397+
t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' );
398+
t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' );
399+
t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' );
400+
t.strictEqual( arr.get( 3 ), 8.0, 'returns expected value' );
401+
402+
t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' );
403+
404+
t.end();
405+
});
406+
407+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; codegen=false)', function test( t ) {
408+
var strides;
409+
var buffer;
410+
var offset;
411+
var dtype;
412+
var order;
413+
var shape;
414+
var opts;
415+
var arr;
416+
var f;
417+
418+
opts = {
419+
'codegen': false
420+
};
421+
422+
dtype = 'float64';
423+
buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
424+
shape = [ 4 ];
425+
order = 'column-major';
426+
strides = [ 1 ];
427+
offset = 0;
428+
429+
f = ctor( dtype, shape.length, opts );
430+
arr = f( buffer, shape, strides, offset, order );
431+
432+
t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' );
433+
t.strictEqual( hasProp( arr, 'set' ), true, 'has property' );
434+
t.strictEqual( isFunction( arr.set ), true, 'has method' );
435+
436+
arr.set( 0, 5.0 );
437+
arr.set( 1, 6.0 );
438+
arr.set( 2, 7.0 );
439+
arr.set( 3, 8.0 );
440+
441+
t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' );
442+
t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' );
443+
t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' );
444+
t.strictEqual( arr.get( 3 ), 8.0, 'returns expected value' );
445+
446+
t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' );
447+
448+
t.end();
449+
});
450+
451+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; codegen=false)', function test( t ) {
364452
var strides;
365453
var buffer;
366454
var offset;
@@ -404,7 +492,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
404492
t.end();
405493
});
406494

407-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major; codegen=false)', function test( t ) {
495+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; codegen=false)', function test( t ) {
408496
var strides;
409497
var buffer;
410498
var offset;
@@ -448,7 +536,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
448536
t.end();
449537
});
450538

451-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major; codegen=false)', function test( t ) {
539+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; codegen=false)', function test( t ) {
452540
var strides;
453541
var buffer;
454542
var offset;
@@ -492,7 +580,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
492580
t.end();
493581
});
494582

495-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (row-major; codegen=false)', function test( t ) {
583+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; codegen=false)', function test( t ) {
496584
var strides;
497585
var buffer;
498586
var offset;
@@ -536,7 +624,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
536624
t.end();
537625
});
538626

539-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major; codegen=false)', function test( t ) {
627+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; codegen=false)', function test( t ) {
540628
var strides;
541629
var buffer;
542630
var offset;
@@ -580,7 +668,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
580668
t.end();
581669
});
582670

583-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major; codegen=false)', function test( t ) {
671+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; codegen=false)', function test( t ) {
584672
var strides;
585673
var buffer;
586674
var offset;
@@ -624,7 +712,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
624712
t.end();
625713
});
626714

627-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major; codegen=false)', function test( t ) {
715+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; codegen=false)', function test( t ) {
628716
var strides;
629717
var buffer;
630718
var offset;
@@ -668,7 +756,7 @@ tape( 'an ndarray constructor returns an instance which has a `set` method for s
668756
t.end();
669757
});
670758

671-
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (column-major; codegen=false)', function test( t ) {
759+
tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; codegen=false)', function test( t ) {
672760
var strides;
673761
var buffer;
674762
var offset;

0 commit comments

Comments
 (0)