1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ext.android; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
|
25 |
|
import org.testng.annotations.Test; |
26 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 4 |
Complexity Density: 0.17 |
|
27 |
|
public class SparseDoubleArrayTest |
28 |
|
{ |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
4-
|
|
30 |
0 |
@Test... |
31 |
|
public void testConstructor() |
32 |
|
{ |
33 |
0 |
double[] d = new double[] { 0d, 0d, 1.2d, 0d, 0d, 3.4d }; |
34 |
0 |
SparseDoubleArray s = new SparseDoubleArray(d); |
35 |
0 |
for (int i = 0; i < d.length; i++) |
36 |
|
{ |
37 |
0 |
assertEquals(s.get(i), d[i], "At [" + i + "]"); |
38 |
|
} |
39 |
|
} |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
4-
|
|
41 |
0 |
@Test... |
42 |
|
public void testAdd() |
43 |
|
{ |
44 |
0 |
double[] d = new double[] { 0d, 0d, 1.2d, 0d, 0d, 3.4d }; |
45 |
0 |
SparseDoubleArray s = new SparseDoubleArray(d); |
46 |
|
|
47 |
0 |
s.add(0, 3.2d); |
48 |
0 |
assertEquals(s.get(0), 3.2d); |
49 |
|
|
50 |
0 |
s.add(0, 2.5d); |
51 |
0 |
assertEquals(s.get(0), 5.7d); |
52 |
|
|
53 |
0 |
s.add(2, -5.3d); |
54 |
0 |
assertEquals(s.get(2), -4.1d); |
55 |
|
|
56 |
0 |
s.add(12, 9.8d); |
57 |
0 |
assertEquals(s.get(12), 9.8d); |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
4-
|
|
60 |
0 |
@Test... |
61 |
|
public void testDivide() |
62 |
|
{ |
63 |
0 |
double delta = 1.0e-10; |
64 |
0 |
double[] d = new double[] { 0d, 2.4d, 1.2d, 0d, -4.8d, -3.6d }; |
65 |
0 |
SparseDoubleArray s = new SparseDoubleArray(d); |
66 |
0 |
assertEquals(s.divide(0, 1d), 0d); |
67 |
0 |
assertEquals(s.divide(2, 0d), 0d); |
68 |
0 |
assertEquals(s.divide(1, 2d), 1.2d, delta); |
69 |
0 |
assertEquals(s.divide(2, -2d), -0.6d, delta); |
70 |
0 |
assertEquals(s.divide(4, 3d), -1.6d, delta); |
71 |
0 |
assertEquals(s.divide(5, -3d), 1.2d, delta); |
72 |
|
} |
73 |
|
} |