Skip to content

Commit 01544ae

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: 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 efe6e5d commit 01544ae

File tree

3 files changed

+1851
-10
lines changed

3 files changed

+1851
-10
lines changed

lib/node_modules/@stdlib/ndarray/vector/ctor/lib/main.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function arraybuffer2vector( dtype, buffer, length, stride, byteOffset, order, o
165165
N = length * stride;
166166

167167
// Adjust the byte offset to point to the element marking the beginning of the view:
168-
if ( stride < 0 ) {
168+
if ( stride < 0 ) { // TODO: the following is effectively unreachable code, as provided strides are never anything other than unity; however, we keep this around in the event that we want to extract this function to a separate package and would like to maintain generality
169169
N *= -1;
170170
o -= N * bytesPerElement( dtype );
171171
}
@@ -483,6 +483,9 @@ function vector() {
483483
if ( nargs === 2 ) {
484484
// Case: vector( dtype, options )
485485
if ( isDataType( arg0 ) ) {
486+
if ( arg1 === null ) {
487+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg1 ) );
488+
}
486489
return vectorWithDType( 0, arg0, arg1 );
487490
}
488491
// Case: vector( arg0, dtype )
@@ -501,6 +504,9 @@ function vector() {
501504
return arraybuffer2vector( DEFAULT_DTYPE, arg0, (arg0.byteLength-arg1)/bytesPerElement( DEFAULT_DTYPE ), 1, arg1, DEFAULT_ORDER );
502505
}
503506
// Case: vector( arg0, options )
507+
if ( arg1 === null ) {
508+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg1 ) );
509+
}
504510
out = vectorWithDType( arg0, DEFAULT_DTYPE, arg1 );
505511
if ( out === null ) {
506512
throw new TypeError( format( 'invalid argument. First argument must be a length, ArrayBuffer, typed array, array-like object, or iterable. Value: `%s`.', arg0 ) );
@@ -523,6 +529,9 @@ function vector() {
523529
}
524530
// Case: vector( arg0, dtype, options )
525531
if ( isDataType( arg1 ) ) {
532+
if ( arg2 === null ) {
533+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg2 ) );
534+
}
526535
out = vectorWithDType( arg0, arg1, arg2 );
527536
if ( out === null ) {
528537
throw new TypeError( format( 'invalid argument. First argument must be a length, ArrayBuffer, typed array, array-like object, or iterable. Value: `%s`.', arg0 ) );
@@ -536,15 +545,15 @@ function vector() {
536545
if ( !isNonNegativeInteger( arg1 ) ) {
537546
throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', arg1 ) );
538547
}
539-
// Case: vector( ArrayBuffer, byteOffset, options )
540-
if ( isPlainObject( arg2 ) ) {
541-
return arraybuffer2vector( DEFAULT_DTYPE, arg0, (arg0.byteLength-arg1)/bytesPerElement( DEFAULT_DTYPE ), 1, arg1, resolveOrder( arg2 ), arg2 );
542-
}
543548
// Case: vector( ArrayBuffer, byteOffset, length )
544-
if ( !isNonNegativeInteger( arg2 ) ) {
545-
throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', arg2 ) );
549+
if ( isNonNegativeInteger( arg2 ) ) {
550+
return arraybuffer2vector( DEFAULT_DTYPE, arg0, arg2, 1, arg1, DEFAULT_ORDER );
551+
}
552+
// Case: vector( ArrayBuffer, byteOffset, options )
553+
if ( arg2 === null ) {
554+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg2 ) );
546555
}
547-
return arraybuffer2vector( DEFAULT_DTYPE, arg0, arg2, 1, arg1, DEFAULT_ORDER );
556+
return arraybuffer2vector( DEFAULT_DTYPE, arg0, (arg0.byteLength-arg1)/bytesPerElement( DEFAULT_DTYPE ), 1, arg1, resolveOrder( arg2 ), arg2 );
548557
}
549558
arg3 = arguments[ 3 ];
550559

lib/node_modules/@stdlib/ndarray/vector/ctor/test/test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ tape( 'attached to the main export is a `factory` method', function test( t ) {
3737
t.strictEqual( isMethod( vector, 'factory' ), true, 'returns expected value' );
3838
t.end();
3939
});
40-
41-
// FIXME: add tests (see array/typed and ndarray/zeros)

0 commit comments

Comments
 (0)