Skip to content

Commit 65cac76

Browse files
committed
Auto-generated commit
1 parent dbe73e0 commit 65cac76

File tree

3 files changed

+328
-40
lines changed

3 files changed

+328
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ A total of 40 issues were closed in this release:
703703
<details>
704704

705705
- [`63e3c0c`](https://github.com/stdlib-js/stdlib/commit/63e3c0c70c31fae2111b4dfb4141a3665bc0dea0) - **test:** add tests to `ndarray/find` [(#9311)](https://github.com/stdlib-js/stdlib/pull/9311) _(by Muhammad Haris, Athan Reines, stdlib-bot)_
706+
- [`582d828`](https://github.com/stdlib-js/stdlib/commit/582d8280f7d6f077f686db7348e3132971476939) - **test:** add tests _(by Athan Reines)_
707+
- [`59c9027`](https://github.com/stdlib-js/stdlib/commit/59c90279d6241a73c8d82fd92c49f64c4f068db7) - **test:** add tests _(by Athan Reines)_
706708
- [`8ea33d5`](https://github.com/stdlib-js/stdlib/commit/8ea33d58d9a5beb31e6023ceaf331fc4175c74fa) - **docs:** rename parameter _(by Athan Reines)_
707709
- [`5149a6b`](https://github.com/stdlib-js/stdlib/commit/5149a6b650b60568bd0df248c2a97a3d8ca2ca87) - **chore:** minor clean-up _(by Philipp Burckhardt)_
708710
- [`1aff763`](https://github.com/stdlib-js/stdlib/commit/1aff763c61863b7d737a699db89729d2bba0e1bc) - **feat:** add `ndarray/spread-dimensions` [(#9424)](https://github.com/stdlib-js/stdlib/pull/9424) _(by Muhammad Haris, Athan Reines)_

find-last/test/test.assign.js

Lines changed: 152 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -542,43 +542,150 @@ tape( 'the function throws an error if provided an options argument which is not
542542
}
543543
});
544544

545-
tape( 'the function finds the last elements which pass a test implemented by a predicate function along one or more ndarray dimensions (row-major)', function test( t ) {
546-
var expected;
547-
var actual;
545+
tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) {
546+
var values;
547+
var out;
548548
var x;
549-
var y;
549+
var i;
550550

551-
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
552-
y = empty( [], {
551+
x = empty( [ 2, 2 ], {
552+
'dtype': 'float64'
553+
});
554+
out = empty( [], {
553555
'dtype': 'float64'
554556
});
555557

556-
actual = assign( x, y, clbk );
557-
expected = 3.0;
558+
values = [
559+
'5',
560+
NaN,
561+
true,
562+
false,
563+
null,
564+
void 0,
565+
{},
566+
function noop() {}
567+
];
558568

559-
t.strictEqual( actual, y, 'returns expected value' );
560-
t.strictEqual( actual.get(), expected, 'returns expected value' );
569+
for ( i = 0; i < values.length; i++ ) {
570+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
571+
}
572+
t.end();
561573

562-
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
563-
y = empty( [], {
574+
function badValue( value ) {
575+
return function badValue() {
576+
var opts = {
577+
'dims': value
578+
};
579+
assign( x, out, opts, clbk );
580+
};
581+
}
582+
});
583+
584+
tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) {
585+
var values;
586+
var out;
587+
var x;
588+
var i;
589+
590+
x = empty( [ 2, 2 ], {
591+
'dtype': 'float64'
592+
});
593+
out = empty( [], {
564594
'dtype': 'float64'
565595
});
596+
values = [
597+
[ 1, 3 ],
598+
[ 3, 0 ],
599+
[ 0, 2 ]
600+
];
566601

567-
actual = assign( x, y, clbk );
568-
expected = 3.0;
602+
for ( i = 0; i < values.length; i++ ) {
603+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
604+
}
605+
t.end();
569606

570-
t.strictEqual( actual, y, 'returns expected value' );
571-
t.strictEqual( actual.get(), expected, 'returns expected value' );
607+
function badValue( value ) {
608+
return function badValue() {
609+
var opts = {
610+
'dims': value
611+
};
612+
assign( x, out, opts, clbk );
613+
};
614+
}
615+
});
616+
617+
tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) {
618+
var values;
619+
var out;
620+
var x;
621+
var i;
622+
623+
x = empty( [ 2, 2 ], {
624+
'dtype': 'float64'
625+
});
626+
out = empty( [], {
627+
'dtype': 'float64'
628+
});
629+
values = [
630+
[ 0, 0 ],
631+
[ 1, 1 ]
632+
];
633+
634+
for ( i = 0; i < values.length; i++ ) {
635+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
636+
}
572637
t.end();
638+
639+
function badValue( value ) {
640+
return function badValue() {
641+
var opts = {
642+
'dims': value
643+
};
644+
assign( x, out, opts, clbk );
645+
};
646+
}
573647
});
574648

575-
tape( 'the function finds the last elements which pass a test implemented by a predicate function along one or more ndarray dimensions (column-major)', function test( t ) {
649+
tape( 'the function throws an error if provided an options argument with a `dims` property which contains more dimensions than are present in the input ndarray', function test( t ) {
650+
var values;
651+
var out;
652+
var x;
653+
var i;
654+
655+
x = empty( [ 2, 2 ], {
656+
'dtype': 'float64'
657+
});
658+
out = empty( [], {
659+
'dtype': 'float64'
660+
});
661+
values = [
662+
[ 0, 1, 2 ],
663+
[ 0, 1, 2, 3 ],
664+
[ 0, 1, 2, 3, 4 ]
665+
];
666+
667+
for ( i = 0; i < values.length; i++ ) {
668+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
669+
}
670+
t.end();
671+
672+
function badValue( value ) {
673+
return function badValue() {
674+
var opts = {
675+
'dims': value
676+
};
677+
assign( x, out, opts, clbk );
678+
};
679+
}
680+
});
681+
682+
tape( 'the function finds the last elements which pass a test implemented by a predicate function along one or more ndarray dimensions (row-major)', function test( t ) {
576683
var expected;
577684
var actual;
578685
var x;
579686
var y;
580687

581-
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' );
688+
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
582689
y = empty( [], {
583690
'dtype': 'float64'
584691
});
@@ -588,6 +695,14 @@ tape( 'the function finds the last elements which pass a test implemented by a p
588695

589696
t.strictEqual( actual, y, 'returns expected value' );
590697
t.strictEqual( actual.get(), expected, 'returns expected value' );
698+
t.end();
699+
});
700+
701+
tape( 'the function finds the last elements which pass a test implemented by a predicate function along one or more ndarray dimensions (column-major)', function test( t ) {
702+
var expected;
703+
var actual;
704+
var x;
705+
var y;
591706

592707
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'column-major' );
593708
y = empty( [], {
@@ -619,6 +734,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct
619734
});
620735
actual = assign( x, y, opts, clbk );
621736
expected = [ 5.0, 6.0, 7.0, 8.0 ];
737+
622738
t.strictEqual( actual, y, 'returns expected value' );
623739
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
624740

@@ -630,6 +746,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct
630746
});
631747
actual = assign( x, y, opts, clbk );
632748
expected = [ 4.0, 8.0 ];
749+
633750
t.strictEqual( actual, y, 'returns expected value' );
634751
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
635752

@@ -641,6 +758,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct
641758
});
642759
actual = assign( x, y, opts, clbk );
643760
expected = 8.0;
761+
644762
t.strictEqual( actual, y, 'returns expected value' );
645763
t.deepEqual( actual.get(), expected, 'returns expected value' );
646764

@@ -652,6 +770,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct
652770
});
653771
actual = assign( x, y, opts, clbk );
654772
expected = [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ];
773+
655774
t.strictEqual( actual, y, 'returns expected value' );
656775
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
657776

@@ -752,7 +871,7 @@ tape( 'the function supports providing an execution context', function test( t )
752871
var x;
753872
var y;
754873

755-
x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
874+
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, -3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
756875
y = empty( [], {
757876
'dtype': 'float64'
758877
});
@@ -766,20 +885,23 @@ tape( 'the function supports providing an execution context', function test( t )
766885
arrays = [];
767886
actual = assign( x, y, predicate, ctx );
768887

769-
expected = 4.0;
888+
expected = 1.0;
770889
t.strictEqual( actual, y, 'returns expected value' );
771890
t.strictEqual( actual.get(), expected, 'returns expected value' );
772-
t.strictEqual( ctx.count, 1, 'returns expected value' );
891+
t.strictEqual( ctx.count, 4, 'returns expected value' );
773892

774-
expected = [ 4.0 ];
893+
expected = [ -4.0, -3.0, -2.0, 1.0 ];
775894
t.deepEqual( values, expected, 'returns expected value' );
776895

777896
expected = [
778-
[ 3 ]
897+
[ 3 ],
898+
[ 2 ],
899+
[ 1 ],
900+
[ 0 ]
779901
];
780902
t.deepEqual( indices, expected, 'returns expected value' );
781903

782-
expected = [ x ];
904+
expected = [ x, x, x, x ];
783905
t.deepEqual( arrays, expected, 'returns expected value' );
784906

785907
t.end();
@@ -804,7 +926,7 @@ tape( 'the function supports providing an execution context (options)', function
804926
var x;
805927
var y;
806928

807-
x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' );
929+
x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, -4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' );
808930
y = empty( [ 2 ], {
809931
'dtype': 'float64'
810932
});
@@ -820,21 +942,22 @@ tape( 'the function supports providing an execution context (options)', function
820942
arrays = [];
821943
actual = assign( x, y, opts, predicate, ctx );
822944

823-
expected = [ 2.0, 4.0 ];
945+
expected = [ 2.0, 3.0 ];
824946
t.strictEqual( actual, y, 'returns expected value' );
825947
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
826-
t.strictEqual( ctx.count, 2, 'returns expected value' );
948+
t.strictEqual( ctx.count, 3, 'returns expected value' );
827949

828-
expected = [ 4.0, 2.0 ];
950+
expected = [ -4.0, 3.0, 2.0 ];
829951
t.deepEqual( values, expected, 'returns expected value' );
830952

831953
expected = [
832954
[ 1, 1 ],
955+
[ 0, 1 ],
833956
[ 1, 0 ]
834957
];
835958
t.deepEqual( indices, expected, 'returns expected value' );
836959

837-
expected = [ x, x ];
960+
expected = [ x, x, x ];
838961
t.deepEqual( arrays, expected, 'returns expected value' );
839962

840963
t.end();

0 commit comments

Comments
 (0)