Skip to content

Commit 8c1a65d

Browse files
committed
refactor: add missing check & test case
--- 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: passed - 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 69f6621 commit 8c1a65d

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isFunction = require( '@stdlib/assert/is-function' );
2525
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
2626
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
27+
var getShape = require( '@stdlib/ndarray/shape' );
2728
var format = require( '@stdlib/string/format' );
2829
var base = require( './base.js' );
2930

@@ -84,6 +85,7 @@ function findIndex( x ) {
8485
var opts;
8586
var ctx;
8687
var cb;
88+
var sh;
8789

8890
nargs = arguments.length;
8991
if ( !isndarrayLike( x ) ) {
@@ -148,6 +150,11 @@ function findIndex( x ) {
148150
opts.dtype = options.dtype;
149151
}
150152
}
153+
// Resolve the list of non-reduced dimensions:
154+
sh = getShape( x );
155+
if ( sh.length < 1 ) {
156+
throw new RangeError( 'invalid argument. First argument must have at least one dimension.' );
157+
}
151158
return base( x, opts, cb, ctx );
152159
}
153160

lib/node_modules/@stdlib/blas/ext/find-index/test/test.assign.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@ tape( 'the function throws an error if provided a first argument which is not an
187187
}
188188
});
189189

190+
tape( 'the function throws an error if provided a zero-dimensional input ndarray-like object', function test( t ) {
191+
var values;
192+
var i;
193+
var y;
194+
195+
y = zeros( [], {
196+
'dtype': 'int32'
197+
});
198+
199+
values = [
200+
[]
201+
];
202+
for ( i = 0; i < values.length; i++ ) {
203+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
204+
}
205+
t.end();
206+
207+
function badValue( value ) {
208+
return function badValue() {
209+
findIndex( zeros( value ), y, clbk );
210+
};
211+
}
212+
});
213+
190214
tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) {
191215
var values;
192216
var i;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ tape( 'the function throws an error if provided a first argument which is not an
165165
}
166166
});
167167

168+
tape( 'the function throws an error if provided a zero-dimensional input ndarray-like object', function test( t ) {
169+
var values;
170+
var i;
171+
172+
values = [
173+
[]
174+
];
175+
for ( i = 0; i < values.length; i++ ) {
176+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
177+
}
178+
t.end();
179+
180+
function badValue( value ) {
181+
return function badValue() {
182+
findIndex( zeros( value ), clbk );
183+
};
184+
}
185+
});
186+
168187
tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) {
169188
var values;
170189
var x;

0 commit comments

Comments
 (0)