Skip to content

Commit fab8873

Browse files
committed
test: add initial 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 9bb5c38 commit fab8873

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

lib/node_modules/@stdlib/lapack/base/dppequ/lib/dppequ.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var base = require( './base.js' );
3737
* @param {Float64Array} S - array to store the scale factors of `A`
3838
* @param {Float64Array} out - array to store the output
3939
* @throws {TypeError} first argument must be a valid order
40+
* @throws {RangeError} third argument must be a nonnegative integer
4041
* @returns {integer} status code
4142
*
4243
* @example
@@ -54,6 +55,9 @@ function dppequ( order, uplo, N, AP, S, out ) {
5455
if ( !isLayout( order ) ) {
5556
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
5657
}
58+
if ( N < 0 ) {
59+
throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', N ) );
60+
}
5761
return base( order, uplo, N, AP, 1, 0, S, 1, 0, out, 1, 0 );
5862
}
5963

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var dppequ = require( './../lib/dppequ.js' );
26+
27+
28+
// TESTS //
29+
30+
tape( 'main export is a function', function test( t ) {
31+
t.ok( true, __filename );
32+
t.strictEqual( typeof dppequ, 'function', 'main export is a function' );
33+
t.end();
34+
});
35+
36+
tape( 'the function has an arity of 6', function test( t ) {
37+
t.strictEqual( dppequ.length, 6, 'returns expected value' );
38+
t.end();
39+
});
40+
41+
tape( 'the function throws an error if provided an invalid third argument', function test( t ) {
42+
var values;
43+
var out;
44+
var AP;
45+
var S;
46+
var i;
47+
48+
values = [
49+
-1,
50+
-2,
51+
-3,
52+
-4,
53+
-5
54+
];
55+
56+
AP = new Float64Array( [ 1.0, 2.0, 3.0, 5.0, 6.0, 9.0 ] );
57+
S = new Float64Array( 3 );
58+
out = new Float64Array( 2 );
59+
60+
for ( i = 0; i < values.length; i++ ) {
61+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
62+
}
63+
t.end();
64+
65+
function badValue( value ) {
66+
return function badValue() {
67+
dppequ( 'row-major', 'L', value, AP, S, out );
68+
};
69+
}
70+
});
71+
72+
tape( 'the function throws an error if provided a first argument which is not a valid order', function test( t ) {
73+
var values;
74+
var out;
75+
var AP;
76+
var S;
77+
var i;
78+
79+
values = [
80+
'foo',
81+
'bar',
82+
'beep',
83+
'boop',
84+
-5,
85+
NaN,
86+
true,
87+
false,
88+
null,
89+
void 0,
90+
[],
91+
{},
92+
function noop() {}
93+
];
94+
95+
AP = new Float64Array( [ 1.0, 2.0, 3.0, 5.0, 6.0, 9.0 ] );
96+
S = new Float64Array( 3 );
97+
out = new Float64Array( 2 );
98+
99+
for ( i = 0; i < values.length; i++ ) {
100+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
101+
}
102+
t.end();
103+
104+
function badValue( value ) {
105+
return function badValue() {
106+
dppequ( value, 'L', 3, AP, S, out );
107+
};
108+
}
109+
});
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var proxyquire = require( 'proxyquire' );
25+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
26+
var dppequ = require( './../lib' );
27+
28+
29+
// VARIABLES //
30+
31+
var opts = {
32+
'skip': IS_BROWSER
33+
};
34+
35+
36+
// TESTS //
37+
38+
tape( 'main export is a function', function test( t ) {
39+
t.ok( true, __filename );
40+
t.strictEqual( typeof dppequ, 'function', 'main export is a function' );
41+
t.end();
42+
});
43+
44+
tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) {
45+
t.strictEqual( typeof dppequ.ndarray, 'function', 'method is a function' );
46+
t.end();
47+
});
48+
49+
tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) {
50+
var dppequ = proxyquire( './../lib', {
51+
'@stdlib/utils/try-require': tryRequire
52+
});
53+
54+
t.strictEqual( dppequ, mock, 'returns expected value' );
55+
t.end();
56+
57+
function tryRequire() {
58+
return mock;
59+
}
60+
61+
function mock() {
62+
// Mock...
63+
}
64+
});
65+
66+
tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) {
67+
var dppequ;
68+
var main;
69+
70+
main = require( './../lib/dppequ.js' );
71+
72+
dppequ = proxyquire( './../lib', {
73+
'@stdlib/utils/try-require': tryRequire
74+
});
75+
76+
t.strictEqual( dppequ, main, 'returns expected value' );
77+
t.end();
78+
79+
function tryRequire() {
80+
return new Error( 'Cannot find module' );
81+
}
82+
});

0 commit comments

Comments
 (0)