KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > tests > QuaternionTest


1 package JSci.tests;
2
3 import JSci.maths.Quaternion;
4
5 /**
6 * Testcase for quaternions.
7 * @author Mark Hale
8 */

9 public class QuaternionTest extends junitx.extensions.EqualsHashCodeTestCase {
10         private double w, x, y, z;
11         private double s, t, u, v;
12
13         public static void main(String JavaDoc arg[]) {
14                 junit.textui.TestRunner.run(QuaternionTest.class);
15         }
16         public QuaternionTest(String JavaDoc name) {
17                 super(name);
18         }
19         protected void setUp() throws Exception JavaDoc {
20                 JSci.GlobalSettings.ZERO_TOL=1.0e-10;
21                 w = Math.random();
22                 x = Math.random();
23                 y = Math.random();
24                 z = Math.random();
25                 s = Math.random();
26                 t = Math.random();
27                 u = Math.random();
28                 v = Math.random();
29                 super.setUp();
30         }
31         protected Object JavaDoc createInstance() {
32                 return new Quaternion(w, x, y, z);
33         }
34         protected Object JavaDoc createNotEqualInstance() {
35                 return new Quaternion(s, t, u, v);
36         }
37         public void testExp() {
38                 Quaternion expected = (Quaternion) createInstance();
39                 Quaternion actual=Quaternion.exp(Quaternion.log(expected));
40                 assertEquals(expected, actual);
41         }
42         public void testRotationMatrixConversion() {
43                 Quaternion expected = (Quaternion) createInstance();
44                 // normalise
45
expected = expected.divide(expected.norm());
46                 Quaternion actual = Quaternion.rotation(expected.toRotationMatrix());
47                 assertEquals(expected, actual);
48         }
49 }
50
51
Popular Tags