Skip to content

Commit 4049a3c

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: 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 18a8394 commit 4049a3c

File tree

8 files changed

+453
-0
lines changed

8 files changed

+453
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"order": "column-major",
3+
"uplo": "all",
4+
5+
"M": 3,
6+
"N": 3,
7+
8+
"A": [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ],
9+
"A_mat": [
10+
[ 1.0, 2.0, 3.0 ],
11+
[ 4.0, 5.0, 6.0 ],
12+
[ 7.0, 8.0, 9.0 ]
13+
],
14+
15+
"strideA1": 1,
16+
"strideA2": 3,
17+
"offsetA": 0,
18+
"LDA": 3,
19+
20+
"alpha": 2.0,
21+
"beta": 3.0,
22+
23+
"out": [ 3.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 3.0 ],
24+
"out_mat": [
25+
[ 3.0, 2.0, 2.0 ],
26+
[ 2.0, 3.0, 2.0 ],
27+
[ 2.0, 2.0, 3.0 ]
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"order": "row-major",
3+
"uplo": "all",
4+
5+
"M": 3,
6+
"N": 3,
7+
8+
"A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ],
9+
"A_mat": [
10+
[ 1.0, 2.0, 3.0 ],
11+
[ 4.0, 5.0, 6.0 ],
12+
[ 7.0, 8.0, 9.0 ]
13+
],
14+
15+
"strideA1": 3,
16+
"strideA2": 1,
17+
"offsetA": 0,
18+
"LDA": 3,
19+
20+
"alpha": 2.0,
21+
"beta": 3.0,
22+
23+
"out": [ 3.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.0, 2.0, 3.0 ],
24+
"out_mat": [
25+
[ 3.0, 2.0, 2.0 ],
26+
[ 2.0, 3.0, 2.0 ],
27+
[ 2.0, 2.0, 3.0 ]
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"order": "column-major",
3+
"uplo": "lower",
4+
5+
"M": 3,
6+
"N": 3,
7+
8+
"A": [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ],
9+
"A_mat": [
10+
[ 1.0, 2.0, 3.0 ],
11+
[ 4.0, 5.0, 6.0 ],
12+
[ 7.0, 8.0, 9.0 ]
13+
],
14+
15+
"strideA1": 1,
16+
"strideA2": 3,
17+
"offsetA": 0,
18+
"LDA": 3,
19+
20+
"alpha": 2.0,
21+
"beta": 3.0,
22+
23+
"out": [ 3.0, 2.0, 2.0, 2.0, 3.0, 2.0, 3.0, 6.0, 3.0 ],
24+
"out_mat": [
25+
[ 3.0, 2.0, 3.0 ],
26+
[ 2.0, 3.0, 6.0 ],
27+
[ 2.0, 2.0, 3.0 ]
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"order": "row-major",
3+
"uplo": "lower",
4+
5+
"M": 3,
6+
"N": 3,
7+
8+
"A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ],
9+
"A_mat": [
10+
[ 1.0, 2.0, 3.0 ],
11+
[ 4.0, 5.0, 6.0 ],
12+
[ 7.0, 8.0, 9.0 ]
13+
],
14+
15+
"strideA1": 3,
16+
"strideA2": 1,
17+
"offsetA": 0,
18+
"LDA": 3,
19+
20+
"alpha": 2.0,
21+
"beta": 3.0,
22+
23+
"out": [ 3.0, 2.0, 3.0, 2.0, 3.0, 6.0, 2.0, 2.0, 3.0 ],
24+
"out_mat": [
25+
[ 3.0, 2.0, 3.0 ],
26+
[ 2.0, 3.0, 6.0 ],
27+
[ 2.0, 2.0, 3.0 ]
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"order": "column-major",
3+
"uplo": "upper",
4+
5+
"M": 3,
6+
"N": 3,
7+
8+
"A": [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ],
9+
"A_mat": [
10+
[ 1.0, 2.0, 3.0 ],
11+
[ 4.0, 5.0, 6.0 ],
12+
[ 7.0, 8.0, 9.0 ]
13+
],
14+
15+
"strideA1": 1,
16+
"strideA2": 3,
17+
"offsetA": 0,
18+
"LDA": 3,
19+
20+
"alpha": 2.0,
21+
"beta": 3.0,
22+
23+
"out": [ 3.0, 4.0, 7.0, 2.0, 3.0, 8.0, 2.0, 2.0, 3.0 ],
24+
"out_mat": [
25+
[ 3.0, 2.0, 2.0 ],
26+
[ 4.0, 3.0, 2.0 ],
27+
[ 7.0, 8.0, 3.0 ]
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"order": "row-major",
3+
"uplo": "upper",
4+
5+
"M": 3,
6+
"N": 3,
7+
8+
"A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ],
9+
"A_mat": [
10+
[ 1.0, 2.0, 3.0 ],
11+
[ 4.0, 5.0, 6.0 ],
12+
[ 7.0, 8.0, 9.0 ]
13+
],
14+
15+
"strideA1": 3,
16+
"strideA2": 1,
17+
"offsetA": 0,
18+
"LDA": 3,
19+
20+
"alpha": 2.0,
21+
"beta": 3.0,
22+
23+
"out": [ 3.0, 2.0, 2.0, 4.0, 3.0, 2.0, 7.0, 8.0, 3.0 ],
24+
"out_mat": [
25+
[ 3.0, 2.0, 2.0 ],
26+
[ 4.0, 3.0, 2.0 ],
27+
[ 7.0, 8.0, 3.0 ]
28+
]
29+
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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 max-len */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var tape = require( 'tape' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var dlaset = require( './../lib/dlaset.js' );
28+
29+
30+
// FIXTURES //
31+
32+
var ALL_ROW_MAJOR = require( './fixtures/all_row_major.json' );
33+
var ALL_COL_MAJOR = require( './fixtures/all_col_major.json' );
34+
var LOWER_ROW_MAJOR = require( './fixtures/lower_row_major.json' );
35+
var LOWER_COL_MAJOR = require( './fixtures/lower_col_major.json' );
36+
var UPPER_ROW_MAJOR = require( './fixtures/upper_row_major.json' );
37+
var UPPER_COL_MAJOR = require( './fixtures/upper_col_major.json' );
38+
39+
40+
// TESTS //
41+
42+
tape( 'main export is a function', function test( t ) {
43+
t.ok( true, __filename );
44+
t.strictEqual( typeof dlaset, 'function', 'main export is a function' );
45+
t.end();
46+
});
47+
48+
tape( 'the function has an arity of 8', function test( t ) {
49+
t.strictEqual( dlaset.length, 8, 'returns expected value' );
50+
t.end();
51+
});
52+
53+
tape( 'the function throws an error if provided an invalid first argument', function test( t ) {
54+
var values;
55+
var A;
56+
var i;
57+
58+
values = [
59+
'foo',
60+
'bar',
61+
'beep',
62+
'boop'
63+
];
64+
65+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
66+
67+
for ( i = 0; i < values.length; i++ ) {
68+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
69+
}
70+
t.end();
71+
72+
function badValue( value ) {
73+
return function badValue() {
74+
dlaset( value, 'all', 2, 2, A, 2, 2.0, 3.0 );
75+
};
76+
}
77+
});
78+
79+
tape( 'the function throws an error if provided an invalid sixth argument (row-major)', function test( t ) {
80+
var values;
81+
var A;
82+
var i;
83+
84+
values = [
85+
0,
86+
1
87+
];
88+
89+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
90+
91+
for ( i = 0; i < values.length; i++ ) {
92+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
93+
}
94+
t.end();
95+
96+
function badValue( value ) {
97+
return function badValue() {
98+
dlaset( 'row-major', 'all', 2, 2, A, value, 2.0, 3.0 );
99+
};
100+
}
101+
});
102+
103+
tape( 'the function returns expected value when setting all values (row-major)', function test( t ) {
104+
var expectedOut;
105+
var data;
106+
var out;
107+
var A;
108+
109+
data = ALL_ROW_MAJOR;
110+
111+
A = new Float64Array( data.A );
112+
out = dlaset( data.order, data.uplo, data.M, data.N, A, data.LDA, data.alpha, data.beta );
113+
expectedOut = new Float64Array( data.out );
114+
115+
t.deepEqual( out, expectedOut, 'returns expected value' );
116+
t.end();
117+
});
118+
119+
tape( 'the function returns expected value when setting all values (column-major)', function test( t ) {
120+
var expectedOut;
121+
var data;
122+
var out;
123+
var A;
124+
125+
data = ALL_COL_MAJOR;
126+
127+
A = new Float64Array( data.A );
128+
out = dlaset( data.order, data.uplo, data.M, data.N, A, data.LDA, data.alpha, data.beta );
129+
expectedOut = new Float64Array( data.out );
130+
131+
t.deepEqual( out, expectedOut, 'returns expected value' );
132+
t.end();
133+
});
134+
135+
tape( 'the function returns expected value when setting lower triangular values (row-major)', function test( t ) {
136+
var expectedOut;
137+
var data;
138+
var out;
139+
var A;
140+
141+
data = LOWER_ROW_MAJOR;
142+
143+
A = new Float64Array( data.A );
144+
out = dlaset( data.order, data.uplo, data.M, data.N, A, data.LDA, data.alpha, data.beta );
145+
expectedOut = new Float64Array( data.out );
146+
147+
t.deepEqual( out, expectedOut, 'returns expected value' );
148+
t.end();
149+
});
150+
151+
tape( 'the function returns expected value when setting lower triangular values (column-major)', function test( t ) {
152+
var expectedOut;
153+
var data;
154+
var out;
155+
var A;
156+
157+
data = LOWER_COL_MAJOR;
158+
159+
A = new Float64Array( data.A );
160+
out = dlaset( data.order, data.uplo, data.M, data.N, A, data.LDA, data.alpha, data.beta );
161+
expectedOut = new Float64Array( data.out );
162+
163+
t.deepEqual( out, expectedOut, 'returns expected value' );
164+
t.end();
165+
});
166+
167+
tape( 'the function returns expected value when setting upper triangular values (row-major)', function test( t ) {
168+
var expectedOut;
169+
var data;
170+
var out;
171+
var A;
172+
173+
data = UPPER_ROW_MAJOR;
174+
175+
A = new Float64Array( data.A );
176+
out = dlaset( data.order, data.uplo, data.M, data.N, A, data.LDA, data.alpha, data.beta );
177+
expectedOut = new Float64Array( data.out );
178+
179+
t.deepEqual( out, expectedOut, 'returns expected value' );
180+
t.end();
181+
});
182+
183+
tape( 'the function returns expected value when setting upper triangular values (column-major)', function test( t ) {
184+
var expectedOut;
185+
var data;
186+
var out;
187+
var A;
188+
189+
data = UPPER_COL_MAJOR;
190+
191+
A = new Float64Array( data.A );
192+
out = dlaset( data.order, data.uplo, data.M, data.N, A, data.LDA, data.alpha, data.beta );
193+
expectedOut = new Float64Array( data.out );
194+
195+
t.deepEqual( out, expectedOut, 'returns expected value' );
196+
t.end();
197+
});

0 commit comments

Comments
 (0)