Skip to content

Commit 582d828

Browse files
committed
test: add tests
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 59c9027 commit 582d828

File tree

1 file changed

+174
-11
lines changed

1 file changed

+174
-11
lines changed

lib/node_modules/@stdlib/ndarray/find-last/test/test.main.js

Lines changed: 174 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,165 @@ tape( 'the function throws an error if provided an options argument which is not
364364
}
365365
});
366366

367+
tape( 'the function throws an error if provided an options argument with an invalid `dims` property', function test( t ) {
368+
var values;
369+
var x;
370+
var i;
371+
372+
x = empty( [ 2, 2 ], {
373+
'dtype': 'float64'
374+
});
375+
376+
values = [
377+
'5',
378+
NaN,
379+
true,
380+
false,
381+
null,
382+
void 0,
383+
{},
384+
function noop() {}
385+
];
386+
387+
for ( i = 0; i < values.length; i++ ) {
388+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
389+
}
390+
t.end();
391+
392+
function badValue( value ) {
393+
return function badValue() {
394+
var opts = {
395+
'dims': value
396+
};
397+
findLast( x, opts, clbk );
398+
};
399+
}
400+
});
401+
402+
tape( 'the function throws an error if provided an options argument with a `dims` property which contains out-of-bounds dimensions', function test( t ) {
403+
var values;
404+
var x;
405+
var i;
406+
407+
x = empty( [ 2, 2 ], {
408+
'dtype': 'float64'
409+
});
410+
411+
values = [
412+
[ 1, 3 ],
413+
[ 3, 0 ],
414+
[ 0, 2 ]
415+
];
416+
417+
for ( i = 0; i < values.length; i++ ) {
418+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
419+
}
420+
t.end();
421+
422+
function badValue( value ) {
423+
return function badValue() {
424+
var opts = {
425+
'dims': value
426+
};
427+
findLast( x, opts, clbk );
428+
};
429+
}
430+
});
431+
432+
tape( 'the function throws an error if provided an options argument with a `dims` property which contains duplicate dimensions', function test( t ) {
433+
var values;
434+
var x;
435+
var i;
436+
437+
x = empty( [ 2, 2 ], {
438+
'dtype': 'float64'
439+
});
440+
441+
values = [
442+
[ 0, 0 ],
443+
[ 1, 1 ]
444+
];
445+
446+
for ( i = 0; i < values.length; i++ ) {
447+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
448+
}
449+
t.end();
450+
451+
function badValue( value ) {
452+
return function badValue() {
453+
var opts = {
454+
'dims': value
455+
};
456+
findLast( x, opts, clbk );
457+
};
458+
}
459+
});
460+
461+
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 ) {
462+
var values;
463+
var x;
464+
var i;
465+
466+
x = empty( [ 2, 2 ], {
467+
'dtype': 'float64'
468+
});
469+
470+
values = [
471+
[ 0, 1, 2 ],
472+
[ 0, 1, 2, 3 ],
473+
[ 0, 1, 2, 3, 4 ]
474+
];
475+
476+
for ( i = 0; i < values.length; i++ ) {
477+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
478+
}
479+
t.end();
480+
481+
function badValue( value ) {
482+
return function badValue() {
483+
var opts = {
484+
'dims': value
485+
};
486+
findLast( x, opts, clbk );
487+
};
488+
}
489+
});
490+
491+
tape( 'the function throws an error if provided an options argument with an invalid `keepdims` property', function test( t ) {
492+
var values;
493+
var x;
494+
var i;
495+
496+
x = empty( [ 2, 2 ], {
497+
'dtype': 'float64'
498+
});
499+
500+
values = [
501+
'5',
502+
5,
503+
NaN,
504+
null,
505+
void 0,
506+
{},
507+
[],
508+
function noop() {}
509+
];
510+
511+
for ( i = 0; i < values.length; i++ ) {
512+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
513+
}
514+
t.end();
515+
516+
function badValue( value ) {
517+
return function badValue() {
518+
var opts = {
519+
'keepdims': value
520+
};
521+
findLast( x, opts, clbk );
522+
};
523+
}
524+
});
525+
367526
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 ) {
368527
var expected;
369528
var actual;
@@ -597,7 +756,7 @@ tape( 'the function supports providing an execution context', function test( t )
597756
var ctx;
598757
var x;
599758

600-
x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
759+
x = new ndarray( 'float64', new Float64Array( [ 1.0, -2.0, -3.0, -4.0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
601760

602761
ctx = {
603762
'count': 0
@@ -607,21 +766,24 @@ tape( 'the function supports providing an execution context', function test( t )
607766
values = [];
608767
arrays = [];
609768
actual = findLast( x, predicate, ctx );
610-
expected = 4.0;
769+
expected = 1.0;
611770

612771
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
613772
t.strictEqual( actual.get(), expected, 'returns expected value' );
614-
t.strictEqual( ctx.count, 1, 'returns expected value' );
773+
t.strictEqual( ctx.count, 4, 'returns expected value' );
615774

616-
expected = [ 4.0 ];
775+
expected = [ -4.0, -3.0, -2.0, 1.0 ];
617776
t.deepEqual( values, expected, 'returns expected value' );
618777

619778
expected = [
620-
[ 3 ]
779+
[ 3 ],
780+
[ 2 ],
781+
[ 1 ],
782+
[ 0 ]
621783
];
622784
t.deepEqual( indices, expected, 'returns expected value' );
623785

624-
expected = [ x ];
786+
expected = [ x, x, x, x ];
625787
t.deepEqual( arrays, expected, 'returns expected value' );
626788

627789
t.end();
@@ -645,7 +807,7 @@ tape( 'the function supports providing an execution context (options)', function
645807
var ctx;
646808
var x;
647809

648-
x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' );
810+
x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, -4.0 ] ), [ 2, 2 ], [ 1, 2 ], 0, 'column-major' );
649811

650812
ctx = {
651813
'count': 0
@@ -657,22 +819,23 @@ tape( 'the function supports providing an execution context (options)', function
657819
values = [];
658820
arrays = [];
659821
actual = findLast( x, opts, predicate, ctx );
660-
expected = [ 2.0, 4.0 ];
822+
expected = [ 2.0, 3.0 ];
661823

662824
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
663825
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
664-
t.strictEqual( ctx.count, 2, 'returns expected value' );
826+
t.strictEqual( ctx.count, 3, 'returns expected value' );
665827

666-
expected = [ 4.0, 2.0 ];
828+
expected = [ -4.0, 3.0, 2.0 ];
667829
t.deepEqual( values, expected, 'returns expected value' );
668830

669831
expected = [
670832
[ 1, 1 ],
833+
[ 0, 1 ],
671834
[ 1, 0 ]
672835
];
673836
t.deepEqual( indices, expected, 'returns expected value' );
674837

675-
expected = [ x, x ];
838+
expected = [ x, x, x ];
676839
t.deepEqual( arrays, expected, 'returns expected value' );
677840

678841
t.end();

0 commit comments

Comments
 (0)