1 |
|
package jalview.math; |
2 |
|
|
3 |
|
import static org.testng.Assert.assertEquals; |
4 |
|
import static org.testng.Assert.assertFalse; |
5 |
|
import static org.testng.Assert.assertNotSame; |
6 |
|
import static org.testng.Assert.assertNull; |
7 |
|
import static org.testng.Assert.assertTrue; |
8 |
|
import static org.testng.Assert.fail; |
9 |
|
|
10 |
|
import java.util.Arrays; |
11 |
|
import java.util.Random; |
12 |
|
|
13 |
|
import org.testng.annotations.Test; |
14 |
|
import org.testng.internal.junit.ArrayAsserts; |
15 |
|
|
|
|
| 83.8% |
Uncovered Elements: 47 (290) |
Complexity: 42 |
Complexity Density: 0.19 |
|
16 |
|
public class MatrixTest |
17 |
|
{ |
18 |
|
final static double DELTA = 0.000001d; |
19 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
4-
|
|
20 |
0 |
@Test(groups = "Timing")... |
21 |
|
public void testPreMultiply_timing() |
22 |
|
{ |
23 |
0 |
int rows = 50; |
24 |
0 |
int cols = 100; |
25 |
0 |
double[][] d1 = new double[rows][cols]; |
26 |
0 |
double[][] d2 = new double[cols][rows]; |
27 |
0 |
Matrix m1 = new Matrix(d1); |
28 |
0 |
Matrix m2 = new Matrix(d2); |
29 |
0 |
long start = System.currentTimeMillis(); |
30 |
0 |
m1.preMultiply(m2); |
31 |
0 |
long elapsed = System.currentTimeMillis() - start; |
32 |
0 |
System.out.println(rows + "x" + cols |
33 |
|
+ " multiplications of double took " + elapsed + "ms"); |
34 |
|
} |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
36 |
1 |
@Test(groups = "Functional")... |
37 |
|
public void testPreMultiply() |
38 |
|
{ |
39 |
1 |
Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }); |
40 |
1 |
Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }); |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
1 |
MatrixI m3 = m2.preMultiply(m1); |
47 |
1 |
assertEquals(m3.height(), 1); |
48 |
1 |
assertEquals(m3.width(), 1); |
49 |
1 |
assertEquals(m3.getValue(0, 0), 56d); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
1 |
m3 = m1.preMultiply(m2); |
55 |
1 |
assertEquals(m3.height(), 3); |
56 |
1 |
assertEquals(m3.width(), 3); |
57 |
1 |
assertEquals(Arrays.toString(m3.getRow(0)), "[10.0, 15.0, 20.0]"); |
58 |
1 |
assertEquals(Arrays.toString(m3.getRow(1)), "[12.0, 18.0, 24.0]"); |
59 |
1 |
assertEquals(Arrays.toString(m3.getRow(2)), "[14.0, 21.0, 28.0]"); |
60 |
|
} |
61 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
62 |
1 |
@Test(... |
63 |
|
groups = "Functional", |
64 |
|
expectedExceptions = { IllegalArgumentException.class }) |
65 |
|
public void testPreMultiply_tooManyColumns() |
66 |
|
{ |
67 |
1 |
Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
1 |
m1.preMultiply(m1); |
74 |
0 |
fail("Expected exception"); |
75 |
|
} |
76 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
77 |
1 |
@Test(... |
78 |
|
groups = "Functional", |
79 |
|
expectedExceptions = { IllegalArgumentException.class }) |
80 |
|
public void testPreMultiply_tooFewColumns() |
81 |
|
{ |
82 |
1 |
Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
1 |
m1.preMultiply(m1); |
89 |
0 |
fail("Expected exception"); |
90 |
|
} |
91 |
|
|
92 |
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 5 |
Complexity Density: 0.83 |
|
93 |
1 |
private boolean matrixEquals(Matrix m1, Matrix m2) {... |
94 |
1 |
if (m1.width() != m2.width() || m1.height() != m2.height()) |
95 |
|
{ |
96 |
0 |
return false; |
97 |
|
} |
98 |
6 |
for (int i = 0; i < m1.height(); i++) |
99 |
|
{ |
100 |
5 |
if (!Arrays.equals(m1.getRow(i), m2.getRow(i))) |
101 |
|
{ |
102 |
0 |
return false; |
103 |
|
} |
104 |
|
} |
105 |
1 |
return true; |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
108 |
1 |
@Test(groups = "Functional")... |
109 |
|
public void testPostMultiply() |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
1 |
MatrixI m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } }); |
120 |
1 |
MatrixI m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } }); |
121 |
1 |
MatrixI m3 = m1.postMultiply(m2); |
122 |
1 |
assertEquals(Arrays.toString(m3.getRow(0)), "[3020.0, 30200.0]"); |
123 |
1 |
assertEquals(Arrays.toString(m3.getRow(1)), "[5040.0, 50400.0]"); |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
1 |
m3 = m2.preMultiply(m1); |
129 |
1 |
assertEquals(Arrays.toString(m3.getRow(0)), "[3020.0, 30200.0]"); |
130 |
1 |
assertEquals(Arrays.toString(m3.getRow(1)), "[5040.0, 50400.0]"); |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
1 |
m1 = new Matrix(new double[][] { { 2 }, { 3 } }); |
138 |
1 |
m2 = new Matrix(new double[][] { { 10, 100, 1000 } }); |
139 |
1 |
m3 = m1.postMultiply(m2); |
140 |
1 |
assertEquals(m3.height(), 2); |
141 |
1 |
assertEquals(m3.width(), 3); |
142 |
1 |
assertEquals(Arrays.toString(m3.getRow(0)), "[20.0, 200.0, 2000.0]"); |
143 |
1 |
assertEquals(Arrays.toString(m3.getRow(1)), "[30.0, 300.0, 3000.0]"); |
144 |
1 |
m3 = m2.preMultiply(m1); |
145 |
1 |
assertEquals(m3.height(), 2); |
146 |
1 |
assertEquals(m3.width(), 3); |
147 |
1 |
assertEquals(Arrays.toString(m3.getRow(0)), "[20.0, 200.0, 2000.0]"); |
148 |
1 |
assertEquals(Arrays.toString(m3.getRow(1)), "[30.0, 300.0, 3000.0]"); |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
1 |
m1 = new Matrix(new double[][] { { 2, 3, 4 } }); |
159 |
1 |
m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } }); |
160 |
1 |
m3 = m1.postMultiply(m2); |
161 |
1 |
assertEquals(m3.height(), 1); |
162 |
1 |
assertEquals(m3.width(), 2); |
163 |
1 |
assertEquals(m3.getRow(0)[0], 56d); |
164 |
1 |
assertEquals(m3.getRow(0)[1], 25d); |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
1 |
m3 = m2.preMultiply(m1); |
170 |
1 |
assertEquals(m3.height(), 1); |
171 |
1 |
assertEquals(m3.width(), 2); |
172 |
1 |
assertEquals(m3.getRow(0)[0], 56d); |
173 |
1 |
assertEquals(m3.getRow(0)[1], 25d); |
174 |
|
} |
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 3 |
Complexity Density: 0.15 |
1PASS
|
|
176 |
1 |
@Test(groups = "Functional")... |
177 |
|
public void testCopy() |
178 |
|
{ |
179 |
1 |
Random r = new Random(); |
180 |
1 |
int rows = 5; |
181 |
1 |
int cols = 11; |
182 |
1 |
double[][] in = new double[rows][cols]; |
183 |
|
|
184 |
6 |
for (int i = 0; i < rows; i++) |
185 |
|
{ |
186 |
60 |
for (int j = 0; j < cols; j++) |
187 |
|
{ |
188 |
55 |
in[i][j] = r.nextDouble(); |
189 |
|
} |
190 |
|
} |
191 |
1 |
Matrix m1 = new Matrix(in); |
192 |
|
|
193 |
1 |
Matrix m2 = (Matrix) m1.copy(); |
194 |
1 |
assertNotSame(m1, m2); |
195 |
1 |
assertTrue(matrixEquals(m1, m2)); |
196 |
1 |
assertNull(m2.d); |
197 |
1 |
assertNull(m2.e); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
1 |
m1.d = Arrays.copyOf(in[2], in[2].length); |
203 |
1 |
m1.e = Arrays.copyOf(in[4], in[4].length); |
204 |
1 |
m2 = (Matrix) m1.copy(); |
205 |
1 |
assertNotSame(m2.d, m1.d); |
206 |
1 |
assertNotSame(m2.e, m1.e); |
207 |
1 |
assertEquals(m2.d, m1.d); |
208 |
1 |
assertEquals(m2.e, m1.e); |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
@param |
215 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
216 |
0 |
public static void main(String[] args) throws Exception... |
217 |
|
{ |
218 |
0 |
int n = Integer.parseInt(args[0]); |
219 |
0 |
double[][] in = new double[n][n]; |
220 |
|
|
221 |
0 |
for (int i = 0; i < n; i++) |
222 |
|
{ |
223 |
0 |
for (int j = 0; j < n; j++) |
224 |
|
{ |
225 |
0 |
in[i][j] = Math.random(); |
226 |
|
} |
227 |
|
} |
228 |
|
|
229 |
0 |
Matrix origmat = new Matrix(in); |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
0 |
MatrixI trans = origmat.transpose(); |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
0 |
MatrixI symm = trans.postMultiply(origmat); |
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
0 |
symm.tred(); |
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
0 |
symm.tqli(); |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
} |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
291 |
0 |
@Test(groups = "Timing")... |
292 |
|
public void testSign() |
293 |
|
{ |
294 |
0 |
assertEquals(Matrix.sign(-1, -2), -1d); |
295 |
0 |
assertEquals(Matrix.sign(-1, 2), 1d); |
296 |
0 |
assertEquals(Matrix.sign(-1, 0), 1d); |
297 |
0 |
assertEquals(Matrix.sign(1, -2), -1d); |
298 |
0 |
assertEquals(Matrix.sign(1, 2), 1d); |
299 |
0 |
assertEquals(Matrix.sign(1, 0), 1d); |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
@param |
306 |
|
@param |
307 |
|
@param |
308 |
|
|
309 |
|
@return |
310 |
|
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
311 |
1 |
public double[][] getSparseValues(int rows, int cols, int occupancy)... |
312 |
|
{ |
313 |
1 |
Random r = new Random(1729); |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
1 |
double[][] d = new double[rows][cols]; |
320 |
1 |
int m = 0; |
321 |
11 |
for (int i = 0; i < rows; i++) |
322 |
|
{ |
323 |
10 |
if (++m % occupancy == 0) |
324 |
|
{ |
325 |
0 |
d[i][i] = r.nextInt() % 13; |
326 |
|
} |
327 |
55 |
for (int j = 0; j < i; j++) |
328 |
|
{ |
329 |
45 |
if (++m % occupancy == 0) |
330 |
|
{ |
331 |
18 |
d[i][j] = r.nextInt() % 13; |
332 |
18 |
d[j][i] = d[i][j]; |
333 |
|
} |
334 |
|
} |
335 |
|
} |
336 |
1 |
return d; |
337 |
|
|
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
1PASS
|
|
344 |
1 |
@Test(groups = "Functional")... |
345 |
|
public void testTred_reproducible() |
346 |
|
{ |
347 |
|
|
348 |
|
|
349 |
|
|
350 |
1 |
int rows = 10; |
351 |
1 |
int cols = rows; |
352 |
1 |
double[][] d = getSparseValues(rows, cols, 3); |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
1 |
double[][] d1 = new double[rows][cols]; |
359 |
11 |
for (int row = 0; row < rows; row++) |
360 |
|
{ |
361 |
110 |
for (int col = 0; col < cols; col++) |
362 |
|
{ |
363 |
100 |
d1[row][col] = d[row][col]; |
364 |
|
} |
365 |
|
} |
366 |
1 |
Matrix m1 = new Matrix(d); |
367 |
1 |
Matrix m2 = new Matrix(d1); |
368 |
1 |
assertMatricesMatch(m1, m2); |
369 |
1 |
m1.tred(); |
370 |
1 |
m2.tred(); |
371 |
1 |
assertMatricesMatch(m1, m2); |
372 |
|
} |
373 |
|
|
|
|
| 72.7% |
Uncovered Elements: 6 (22) |
Complexity: 6 |
Complexity Density: 0.5 |
|
374 |
2 |
public static void assertMatricesMatch(MatrixI m1, MatrixI m2)... |
375 |
|
{ |
376 |
2 |
if (m1.height() != m2.height()) |
377 |
|
{ |
378 |
0 |
fail("height mismatch"); |
379 |
|
} |
380 |
2 |
if (m1.width() != m2.width()) |
381 |
|
{ |
382 |
0 |
fail("width mismatch"); |
383 |
|
} |
384 |
22 |
for (int row = 0; row < m1.height(); row++) |
385 |
|
{ |
386 |
220 |
for (int col = 0; col < m1.width(); col++) |
387 |
|
{ |
388 |
200 |
double v2 = m2.getValue(row, col); |
389 |
200 |
double v1 = m1.getValue(row, col); |
390 |
200 |
if (Math.abs(v1 - v2) > DELTA) |
391 |
|
{ |
392 |
0 |
fail(String.format("At [%d, %d] %f != %f", row, col, v1, v2)); |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
2 |
ArrayAsserts.assertArrayEquals("D vector", m1.getD(), m2.getD(), |
397 |
|
0.00001d); |
398 |
2 |
ArrayAsserts.assertArrayEquals("E vector", m1.getE(), m2.getE(), |
399 |
|
0.00001d); |
400 |
|
} |
401 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
402 |
1 |
@Test(groups = "Functional")... |
403 |
|
public void testFindMinMax() |
404 |
|
{ |
405 |
|
|
406 |
|
|
407 |
|
|
408 |
1 |
Matrix m = new Matrix(new double[][] { {} }); |
409 |
1 |
assertNull(m.findMinMax()); |
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
1 |
double[][] vals = new double[2][]; |
415 |
1 |
vals[0] = new double[] {7d, 1d, -2.3d}; |
416 |
1 |
vals[1] = new double[] {-12d, 94.3d, -102.34d}; |
417 |
1 |
m = new Matrix(vals); |
418 |
1 |
double[] minMax = m.findMinMax(); |
419 |
1 |
assertEquals(minMax[0], -102.34d); |
420 |
1 |
assertEquals(minMax[1], 94.3d); |
421 |
|
} |
422 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 5 |
Complexity Density: 0.25 |
1PASS
|
|
423 |
1 |
@Test(groups = { "Functional", "Timing" })... |
424 |
|
public void testFindMinMax_timing() |
425 |
|
{ |
426 |
1 |
Random r = new Random(); |
427 |
1 |
int size = 1000; |
428 |
1 |
double[][] vals = new double[size][size]; |
429 |
1 |
double max = -Double.MAX_VALUE; |
430 |
1 |
double min = Double.MAX_VALUE; |
431 |
1001 |
for (int i = 0; i < size; i++) |
432 |
|
{ |
433 |
1000 |
vals[i] = new double[size]; |
434 |
1001000 |
for (int j = 0; j < size; j++) |
435 |
|
{ |
436 |
|
|
437 |
1000000 |
double d = r.nextLong(); |
438 |
1000000 |
if (d > max) |
439 |
|
{ |
440 |
15 |
max = d; |
441 |
|
} |
442 |
1000000 |
if (d < min) |
443 |
|
{ |
444 |
10 |
min = d; |
445 |
|
} |
446 |
1000000 |
vals[i][j] = d; |
447 |
|
} |
448 |
|
} |
449 |
1 |
Matrix m = new Matrix(vals); |
450 |
1 |
long now = System.currentTimeMillis(); |
451 |
1 |
double[] minMax = m.findMinMax(); |
452 |
1 |
System.out.println(String.format("findMinMax for %d x %d took %dms", |
453 |
|
size, size, (System.currentTimeMillis() - now))); |
454 |
1 |
assertEquals(minMax[0], min); |
455 |
1 |
assertEquals(minMax[1], max); |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
461 |
1 |
@Test(groups = "Functional")... |
462 |
|
public void testReverseRange_maxToZero() |
463 |
|
{ |
464 |
1 |
Matrix m1 = new Matrix( |
465 |
|
new double[][] { { 2, 3.5, 4 }, { -3.4, 4, 15 } }); |
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
1 |
m1.reverseRange(true); |
471 |
1 |
assertEquals(m1.getValue(0, 0), 13d, DELTA); |
472 |
1 |
assertEquals(m1.getValue(0, 1), 11.5d, DELTA); |
473 |
1 |
assertEquals(m1.getValue(0, 2), 11d, DELTA); |
474 |
1 |
assertEquals(m1.getValue(1, 0), 18.4d, DELTA); |
475 |
1 |
assertEquals(m1.getValue(1, 1), 11d, DELTA); |
476 |
1 |
assertEquals(m1.getValue(1, 2), 0d, DELTA); |
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
|
481 |
1 |
m1.reverseRange(true); |
482 |
1 |
assertEquals(m1.getValue(0, 0), 5.4d, DELTA); |
483 |
1 |
assertEquals(m1.getValue(0, 1), 6.9d, DELTA); |
484 |
1 |
assertEquals(m1.getValue(0, 2), 7.4d, DELTA); |
485 |
1 |
assertEquals(m1.getValue(1, 0), 0d, DELTA); |
486 |
1 |
assertEquals(m1.getValue(1, 1), 7.4d, DELTA); |
487 |
1 |
assertEquals(m1.getValue(1, 2), 18.4d, DELTA); |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
493 |
1 |
@Test(groups = "Functional")... |
494 |
|
public void testReverseRange_swapMinMax() |
495 |
|
{ |
496 |
1 |
Matrix m1 = new Matrix( |
497 |
|
new double[][] { { 2, 3.5, 4 }, { -3.4, 4, 15 } }); |
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
1 |
m1.reverseRange(false); |
505 |
1 |
assertEquals(m1.getValue(0, 0), 9.6d, DELTA); |
506 |
1 |
assertEquals(m1.getValue(0, 1), 8.1d, DELTA); |
507 |
1 |
assertEquals(m1.getValue(0, 2), 7.6d, DELTA); |
508 |
1 |
assertEquals(m1.getValue(1, 0), 15d, DELTA); |
509 |
1 |
assertEquals(m1.getValue(1, 1), 7.6d, DELTA); |
510 |
1 |
assertEquals(m1.getValue(1, 2), -3.4d, DELTA); |
511 |
|
|
512 |
|
|
513 |
|
|
514 |
|
|
515 |
1 |
m1.reverseRange(false); |
516 |
1 |
assertEquals(m1.getValue(0, 0), 2d, DELTA); |
517 |
1 |
assertEquals(m1.getValue(0, 1), 3.5d, DELTA); |
518 |
1 |
assertEquals(m1.getValue(0, 2), 4d, DELTA); |
519 |
1 |
assertEquals(m1.getValue(1, 0), -3.4d, DELTA); |
520 |
1 |
assertEquals(m1.getValue(1, 1), 4d, DELTA); |
521 |
1 |
assertEquals(m1.getValue(1, 2), 15d, DELTA); |
522 |
|
} |
523 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
524 |
1 |
@Test(groups = "Functional")... |
525 |
|
public void testMultiply() |
526 |
|
{ |
527 |
1 |
Matrix m = new Matrix(new double[][] { { 2, 3.5, 4 }, { -3.4, 4, 15 } }); |
528 |
1 |
m.multiply(2d); |
529 |
1 |
assertEquals(m.getValue(0, 0), 4d, DELTA); |
530 |
1 |
assertEquals(m.getValue(0, 1), 7d, DELTA); |
531 |
1 |
assertEquals(m.getValue(0, 2), 8d, DELTA); |
532 |
1 |
assertEquals(m.getValue(1, 0), -6.8d, DELTA); |
533 |
1 |
assertEquals(m.getValue(1, 1), 8d, DELTA); |
534 |
1 |
assertEquals(m.getValue(1, 2), 30d, DELTA); |
535 |
|
} |
536 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
537 |
1 |
@Test(groups = "Functional")... |
538 |
|
public void testConstructor() |
539 |
|
{ |
540 |
1 |
double[][] values = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } }; |
541 |
1 |
Matrix m = new Matrix(values); |
542 |
1 |
assertEquals(m.getValue(0, 0), 1d, DELTA); |
543 |
|
|
544 |
|
|
545 |
|
|
546 |
|
|
547 |
1 |
assertNotSame(values[0], m.getRow(0)); |
548 |
1 |
values[0][0] = -1d; |
549 |
1 |
assertEquals(m.getValue(0, 0), 1d, DELTA); |
550 |
|
} |
551 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
552 |
1 |
@Test(groups = "Functional")... |
553 |
|
public void testEquals() |
554 |
|
{ |
555 |
1 |
double[][] values = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } }; |
556 |
1 |
Matrix m1 = new Matrix(values); |
557 |
1 |
double[][] values2 = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } }; |
558 |
1 |
Matrix m2 = new Matrix(values2); |
559 |
|
|
560 |
1 |
double delta = 0.0001d; |
561 |
1 |
assertTrue(m1.equals(m1, delta)); |
562 |
1 |
assertTrue(m1.equals(m2, delta)); |
563 |
1 |
assertTrue(m2.equals(m1, delta)); |
564 |
|
|
565 |
1 |
double[][] values3 = new double[][] { { 1, 2, 3 }, { 4, 5, 7 } }; |
566 |
1 |
m2 = new Matrix(values3); |
567 |
1 |
assertFalse(m1.equals(m2, delta)); |
568 |
1 |
assertFalse(m2.equals(m1, delta)); |
569 |
|
|
570 |
|
|
571 |
1 |
values2 = new double[][] { { 1, 2, 3 } }; |
572 |
1 |
m2 = new Matrix(values2); |
573 |
1 |
assertFalse(m2.equals(m1, delta)); |
574 |
|
|
575 |
1 |
assertFalse(m1.equals(null, delta)); |
576 |
|
} |
577 |
|
} |