Skip to content

Commit d08aa12

Browse files
committed
test: add tests for a fromIndex ndarray
--- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent a51a1a2 commit d08aa12

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var tape = require( 'tape' );
2424
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
2525
var ndarray = require( '@stdlib/ndarray/ctor' );
2626
var zeros = require( '@stdlib/ndarray/zeros' );
27+
var Int32Array = require( '@stdlib/array/int32' );
2728
var ndarray2array = require( '@stdlib/ndarray/to-array' );
2829
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
2930
var getDType = require( '@stdlib/ndarray/dtype' );
@@ -384,6 +385,32 @@ tape( 'the function throws an error if provided a first argument which is not an
384385
}
385386
});
386387

388+
tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) {
389+
var values;
390+
var opts;
391+
var i;
392+
393+
opts = {
394+
'dtype': 'generic'
395+
};
396+
397+
values = [
398+
scalar2ndarray( 10.0 ),
399+
scalar2ndarray( -3.0 ),
400+
scalar2ndarray( 0.0 )
401+
];
402+
for ( i = 0; i < values.length; i++ ) {
403+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
404+
}
405+
t.end();
406+
407+
function badValue( value ) {
408+
return function badValue() {
409+
indexOf( value, scalar2ndarray( 2.0 ), scalar2ndarray( 0, opts ), {} ); // eslint-disable-line max-len
410+
};
411+
}
412+
});
413+
387414
tape( 'the function throws an error if provided a third argument which is not an ndarray-like object, an integer, or an object', function test( t ) {
388415
var values;
389416
var x;
@@ -987,6 +1014,74 @@ tape( 'the function supports specifying the operation dimension (column-major)',
9871014
t.end();
9881015
});
9891016

1017+
tape( 'the function supports specifying the `keepdims` option (row-major)', function test( t ) {
1018+
var expected;
1019+
var actual;
1020+
var xbuf;
1021+
var x;
1022+
1023+
xbuf = [ -1.0, 2.0, -3.0, 2.0 ];
1024+
x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
1025+
1026+
actual = indexOf( x, 2.0, {
1027+
'keepdims': true
1028+
});
1029+
expected = [ [ 1 ], [ 1 ] ];
1030+
1031+
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
1032+
t.strictEqual( getDType( actual ), 'generic', 'returns expected value' );
1033+
t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' );
1034+
t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' );
1035+
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
1036+
1037+
actual = indexOf( x, 2.0, 0, {
1038+
'keepdims': true
1039+
});
1040+
expected = [ [ 1 ], [ 1 ] ];
1041+
1042+
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
1043+
t.strictEqual( getDType( actual ), 'generic', 'returns expected value' );
1044+
t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' );
1045+
t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' );
1046+
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
1047+
1048+
t.end();
1049+
});
1050+
1051+
tape( 'the function supports specifying the `keepdims` option (column-major)', function test( t ) {
1052+
var expected;
1053+
var actual;
1054+
var xbuf;
1055+
var x;
1056+
1057+
xbuf = [ -1.0, 2.0, -3.0, 2.0 ];
1058+
x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' );
1059+
1060+
actual = indexOf( x, 2.0, {
1061+
'keepdims': true
1062+
});
1063+
expected = [ [ 0 ], [ 1 ] ];
1064+
1065+
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
1066+
t.strictEqual( getDType( actual ), 'generic', 'returns expected value' );
1067+
t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' );
1068+
t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' );
1069+
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
1070+
1071+
actual = indexOf( x, 2.0, 0, {
1072+
'keepdims': true
1073+
});
1074+
expected = [ [ 0 ], [ 1 ] ];
1075+
1076+
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
1077+
t.strictEqual( getDType( actual ), 'generic', 'returns expected value' );
1078+
t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' );
1079+
t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' );
1080+
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
1081+
1082+
t.end();
1083+
});
1084+
9901085
tape( 'the function supports specifying the output array data type', function test( t ) {
9911086
var expected;
9921087
var actual;
@@ -1325,3 +1420,39 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)',
13251420

13261421
t.end();
13271422
});
1423+
1424+
tape( 'the function supports providing a from index (1d ndarray)', function test( t ) {
1425+
var searchElement;
1426+
var expected;
1427+
var fromIdx;
1428+
var actual;
1429+
var xbuf;
1430+
var x;
1431+
1432+
/*
1433+
* [
1434+
* 1.0, -2.0,
1435+
* 2.0, -3.0,
1436+
* 3.0, -4.0,
1437+
* 2.0, -3.0,
1438+
* 5.0, -6.0
1439+
* ]
1440+
*/
1441+
xbuf = [ 1.0, -2.0, 2.0, -3.0, 3.0, -4.0, 2.0, -3.0, 5.0, -6.0 ];
1442+
x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' );
1443+
1444+
fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' );
1445+
searchElement = new ndarray( 'generic', [ 2.0, -3.0 ], [ 2 ], [ 1 ], 0, 'row-major' );
1446+
actual = indexOf( x, searchElement, fromIdx, {
1447+
'dim': 0
1448+
});
1449+
expected = [ 3, 3 ];
1450+
1451+
t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' );
1452+
t.strictEqual( getDType( actual ), 'generic', 'returns expected value' );
1453+
t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' );
1454+
t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' );
1455+
t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );
1456+
1457+
t.end();
1458+
});

0 commit comments

Comments
 (0)