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 |
|
|
25 |
|
import jalview.math.RotatableMatrix.Axis; |
26 |
|
|
27 |
|
import java.io.ByteArrayOutputStream; |
28 |
|
import java.io.PrintStream; |
29 |
|
|
30 |
|
import org.testng.annotations.BeforeMethod; |
31 |
|
import org.testng.annotations.Test; |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (82) |
Complexity: 12 |
Complexity Density: 0.19 |
|
33 |
|
public class RotatableMatrixTest |
34 |
|
{ |
35 |
|
private RotatableMatrix rm; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
37 |
4 |
@BeforeMethod(alwaysRun = true)... |
38 |
|
public void setUp() |
39 |
|
{ |
40 |
4 |
rm = new RotatableMatrix(); |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
16 |
for (int i = 1; i <= 3; i++) |
48 |
|
{ |
49 |
48 |
for (int j = 1; j <= 3; j++) |
50 |
|
{ |
51 |
36 |
rm.setValue(i - 1, j - 1, i * j / 2f); |
52 |
|
} |
53 |
|
} |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
56 |
1 |
@Test(groups = "Functional")... |
57 |
|
public void testPrint() |
58 |
|
{ |
59 |
1 |
String expected = "0.5 1.0 1.5\n1.0 2.0 3.0\n1.5 3.0 4.5\n"; |
60 |
1 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
61 |
1 |
PrintStream ps = new PrintStream(os, true); |
62 |
1 |
rm.print(ps); |
63 |
1 |
String result = new String(os.toByteArray()); |
64 |
1 |
assertEquals(result, expected); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
1PASS
|
|
67 |
1 |
@Test(groups = "Functional")... |
68 |
|
public void testPreMultiply() |
69 |
|
{ |
70 |
1 |
float[][] pre = new float[3][3]; |
71 |
1 |
int i = 1; |
72 |
4 |
for (int j = 0; j < 3; j++) |
73 |
|
{ |
74 |
12 |
for (int k = 0; k < 3; k++) |
75 |
|
{ |
76 |
9 |
pre[j][k] = i++; |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
1 |
rm.preMultiply(pre); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
4 |
for (int j = 0; j < 3; j++) |
87 |
|
{ |
88 |
12 |
for (int k = 0; k < 3; k++) |
89 |
|
{ |
90 |
9 |
float expected = 0f; |
91 |
36 |
for (int l = 0; l < 3; l++) |
92 |
|
{ |
93 |
27 |
float rm_l_k = (l + 1) * (k + 1) / 2f; |
94 |
27 |
expected += pre[j][l] * rm_l_k; |
95 |
|
} |
96 |
9 |
assertEquals(rm.getValue(j, k), expected, |
97 |
|
String.format("[%d, %d]", j, k)); |
98 |
|
} |
99 |
|
} |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
102 |
1 |
@Test(groups = "Functional")... |
103 |
|
public void testVectorMultiply() |
104 |
|
{ |
105 |
1 |
float[] result = rm.vectorMultiply(new float[] { 2f, 3f, 4.5f }); |
106 |
|
|
107 |
|
|
108 |
1 |
assertEquals(result[0], 2f * 0.5f + 3f * 1f + 4.5f * 1.5f); |
109 |
|
|
110 |
|
|
111 |
1 |
assertEquals(result[1], 2f * 1.0f + 3f * 2f + 4.5f * 3f); |
112 |
|
|
113 |
|
|
114 |
1 |
assertEquals(result[2], 2f * 1.5f + 3f * 3f + 4.5f * 4.5f); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
117 |
1 |
@Test(groups = "Functional")... |
118 |
|
public void testGetRotation() |
119 |
|
{ |
120 |
1 |
float theta = 60f; |
121 |
1 |
double cosTheta = Math.cos((theta * Math.PI / 180f)); |
122 |
1 |
double sinTheta = Math.sin((theta * Math.PI / 180f)); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
1 |
double delta = 0.0001d; |
128 |
1 |
assertEquals(cosTheta, 0.5f, delta); |
129 |
1 |
assertEquals(sinTheta, Math.sqrt(3d) / 2d, delta); |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@see |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
1 |
float[][] rot = RotatableMatrix.getRotation(theta, Axis.X); |
145 |
1 |
assertEquals(rot[0][0], 1f, delta); |
146 |
1 |
assertEquals(rot[0][1], 0f, delta); |
147 |
1 |
assertEquals(rot[0][2], 0f, delta); |
148 |
1 |
assertEquals(rot[1][0], 0f, delta); |
149 |
1 |
assertEquals(rot[1][1], cosTheta, delta); |
150 |
1 |
assertEquals(rot[1][2], sinTheta, delta); |
151 |
1 |
assertEquals(rot[2][0], 0f, delta); |
152 |
1 |
assertEquals(rot[2][1], -sinTheta, delta); |
153 |
1 |
assertEquals(rot[2][2], cosTheta, delta); |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
1 |
rot = RotatableMatrix.getRotation(theta, Axis.Y); |
163 |
1 |
assertEquals(rot[0][0], cosTheta, delta); |
164 |
1 |
assertEquals(rot[0][1], 0f, delta); |
165 |
1 |
assertEquals(rot[0][2], -sinTheta, delta); |
166 |
1 |
assertEquals(rot[1][0], 0f, delta); |
167 |
1 |
assertEquals(rot[1][1], 1f, delta); |
168 |
1 |
assertEquals(rot[1][2], 0f, delta); |
169 |
1 |
assertEquals(rot[2][0], sinTheta, delta); |
170 |
1 |
assertEquals(rot[2][1], 0f, delta); |
171 |
1 |
assertEquals(rot[2][2], cosTheta, delta); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
1 |
rot = RotatableMatrix.getRotation(theta, Axis.Z); |
181 |
1 |
assertEquals(rot[0][0], cosTheta, delta); |
182 |
1 |
assertEquals(rot[0][1], -sinTheta, delta); |
183 |
1 |
assertEquals(rot[0][2], 0f, delta); |
184 |
1 |
assertEquals(rot[1][0], sinTheta, delta); |
185 |
1 |
assertEquals(rot[1][1], cosTheta, delta); |
186 |
1 |
assertEquals(rot[1][2], 0f, delta); |
187 |
1 |
assertEquals(rot[2][0], 0f, delta); |
188 |
1 |
assertEquals(rot[2][1], 0f, delta); |
189 |
1 |
assertEquals(rot[2][2], 1f, delta); |
190 |
|
} |
191 |
|
} |