Skip to content

Commit 3a12298

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 08cc97d commit 3a12298

File tree

3 files changed

+300
-2
lines changed

3 files changed

+300
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
4646
* - 'P': permute only
4747
* - 'S': scale only
4848
* - 'B': both permute and scale
49-
* - The matrix `A` is overwritten by the balanced matrix.
49+
*
50+
* The matrix `A` is overwritten by the balanced matrix. Scale factors are stored in the `scale` array.
5051
*
5152
* @private
5253
* @param {string} job - indicates the operations to be performed
@@ -197,7 +198,7 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
197198
return 0;
198199
}
199200

200-
// Balance the submatrix in rows K to L, iterative loop for norm reduction
201+
// Balance the submatrix in rows K to L, iterative loop for norm reduction (job = 'B')
201202
sfmin1 = dlamch( 'S' ) / dlamch( 'P' );
202203
sfmax1 = 1.0 / sfmin1;
203204
sfmin2 = sfmin1 * sclfac;
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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+
/* eslint-disable array-element-newline */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var tape = require( 'tape' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var dgebal = require( './../lib/dgebal.js' );
28+
29+
30+
// TESTS //
31+
32+
tape( 'main export is a function', function test( t ) {
33+
t.ok( true, __filename );
34+
t.strictEqual( typeof dgebal, 'function', 'main export is a function' );
35+
t.end();
36+
});
37+
38+
tape( 'the function has an arity of 7', function test( t ) {
39+
t.strictEqual( dgebal.length, 7, 'returns expected value' );
40+
t.end();
41+
});
42+
43+
tape( 'the function throws an error if provided an invalid first argument', function test( t ) {
44+
var values;
45+
var scale;
46+
var out;
47+
var A;
48+
var i;
49+
50+
values = [
51+
'foo',
52+
'bar',
53+
'beep',
54+
'boop'
55+
];
56+
57+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
58+
out = new Float64Array( 2 );
59+
scale = new Float64Array( 2 );
60+
61+
for ( i = 0; i < values.length; i++ ) {
62+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
63+
}
64+
t.end();
65+
66+
function badValue( value ) {
67+
return function badValue() {
68+
dgebal( value, 'B', 2, A, 2, out, scale );
69+
};
70+
}
71+
});
72+
73+
tape( 'the function throws an error if provided an invalid second argument', function test( t ) {
74+
var values;
75+
var scale;
76+
var out;
77+
var A;
78+
var i;
79+
80+
values = [
81+
'foo',
82+
'bar',
83+
'beep',
84+
'boop'
85+
];
86+
87+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
88+
out = new Float64Array( 2 );
89+
scale = new Float64Array( 2 );
90+
91+
for ( i = 0; i < values.length; i++ ) {
92+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
93+
}
94+
t.end();
95+
96+
function badValue( value ) {
97+
return function badValue() {
98+
dgebal( 'row-major', value, 2, A, 2, out, scale );
99+
};
100+
}
101+
});
102+
103+
tape( 'the function throws an error if provided an invalid second argument', function test( t ) {
104+
var values;
105+
var scale;
106+
var out;
107+
var A;
108+
var i;
109+
110+
values = [
111+
0,
112+
1
113+
];
114+
115+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
116+
out = new Float64Array( 2 );
117+
scale = new Float64Array( 2 );
118+
119+
for ( i = 0; i < values.length; i++ ) {
120+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
121+
}
122+
t.end();
123+
124+
function badValue( value ) {
125+
return function badValue() {
126+
dgebal( 'row-major', 'B', 2, A, value, out, scale );
127+
};
128+
}
129+
});
130+
131+
tape( 'the function returns invalid indices and leaves the input array unchanged for N = 0', function test( t ) {
132+
var expectedOut;
133+
var scale;
134+
var info;
135+
var out;
136+
var A;
137+
138+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
139+
out = new Float64Array( 2 );
140+
scale = new Float64Array( 2 );
141+
142+
info = dgebal( 'row-major', 'B', 0, A, 2, out, scale );
143+
144+
expectedOut = new Float64Array( [ 0.0, -1.0 ] );
145+
146+
t.strictEqual( info, 0, 'returns expected value' );
147+
t.deepEqual( out, expectedOut, 'returns expected value' );
148+
t.end();
149+
});
150+
151+
tape( 'the function returns expected values for job = N (row-major)', function test( t ) {
152+
var expectedScale;
153+
var expectedOut;
154+
var expectedA;
155+
var scale;
156+
var info;
157+
var out;
158+
var A;
159+
160+
A = new Float64Array([
161+
1.0, 2.0, 3.0,
162+
4.0, 5.0, 6.0,
163+
7.0, 8.0, 9.0
164+
]);
165+
out = new Float64Array( 2 );
166+
scale = new Float64Array( 3 );
167+
168+
expectedOut = new Float64Array( [ 0.0, 2.0 ] );
169+
expectedScale = new Float64Array( [ 1.0, 1.0, 1.0 ] );
170+
expectedA = new Float64Array([
171+
1.0, 2.0, 3.0,
172+
4.0, 5.0, 6.0,
173+
7.0, 8.0, 9.0
174+
]);
175+
176+
info = dgebal( 'row-major', 'N', 3, A, 3, out, scale );
177+
t.strictEqual( info, 0, 'returns expected value' );
178+
t.deepEqual( out, expectedOut, 'returns expected value' );
179+
t.deepEqual( A, expectedA, 'returns expected value' );
180+
t.deepEqual( scale, expectedScale, 'returns expected value' );
181+
t.end();
182+
});
183+
184+
tape( 'the function returns expected values for job = N (column-major)', function test( t ) {
185+
var expectedScale;
186+
var expectedOut;
187+
var expectedA;
188+
var scale;
189+
var info;
190+
var out;
191+
var A;
192+
193+
A = new Float64Array([
194+
1.0, 4.0, 7.0,
195+
2.0, 5.0, 8.0,
196+
3.0, 6.0, 9.0
197+
]);
198+
out = new Float64Array( 2 );
199+
scale = new Float64Array( 3 );
200+
201+
expectedOut = new Float64Array( [ 0.0, 2.0 ] );
202+
expectedScale = new Float64Array( [ 1.0, 1.0, 1.0 ] );
203+
expectedA = new Float64Array([
204+
1.0, 4.0, 7.0,
205+
2.0, 5.0, 8.0,
206+
3.0, 6.0, 9.0
207+
]);
208+
209+
info = dgebal( 'column-major', 'N', 3, A, 3, out, scale );
210+
t.strictEqual( info, 0, 'returns expected value' );
211+
t.deepEqual( out, expectedOut, 'returns expected value' );
212+
t.deepEqual( A, expectedA, 'returns expected value' );
213+
t.deepEqual( scale, expectedScale, 'returns expected value' );
214+
t.end();
215+
});
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) 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 proxyquire = require( 'proxyquire' );
25+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
26+
var dgebal = 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 dgebal, '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 dgebal.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 dgebal = proxyquire( './../lib', {
51+
'@stdlib/utils/try-require': tryRequire
52+
});
53+
54+
t.strictEqual( dgebal, 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 dgebal;
68+
var main;
69+
70+
main = require( './../lib/dgebal.js' );
71+
72+
dgebal = proxyquire( './../lib', {
73+
'@stdlib/utils/try-require': tryRequire
74+
});
75+
76+
t.strictEqual( dgebal, 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)