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