01: package JSci.tests;
02:
03: import JSci.maths.Quaternion;
04:
05: /**
06: * Testcase for quaternions.
07: * @author Mark Hale
08: */
09: public class QuaternionTest extends
10: junitx.extensions.EqualsHashCodeTestCase {
11: private double w, x, y, z;
12: private double s, t, u, v;
13:
14: public static void main(String arg[]) {
15: junit.textui.TestRunner.run(QuaternionTest.class);
16: }
17:
18: public QuaternionTest(String name) {
19: super (name);
20: }
21:
22: protected void setUp() throws Exception {
23: JSci.GlobalSettings.ZERO_TOL = 1.0e-10;
24: w = Math.random();
25: x = Math.random();
26: y = Math.random();
27: z = Math.random();
28: s = Math.random();
29: t = Math.random();
30: u = Math.random();
31: v = Math.random();
32: super .setUp();
33: }
34:
35: protected Object createInstance() {
36: return new Quaternion(w, x, y, z);
37: }
38:
39: protected Object createNotEqualInstance() {
40: return new Quaternion(s, t, u, v);
41: }
42:
43: public void testExp() {
44: Quaternion expected = (Quaternion) createInstance();
45: Quaternion actual = Quaternion.exp(Quaternion.log(expected));
46: assertEquals(expected, actual);
47: }
48:
49: public void testRotationMatrixConversion() {
50: Quaternion expected = (Quaternion) createInstance();
51: // normalise
52: expected = expected.divide(expected.norm());
53: Quaternion actual = Quaternion.rotation(expected
54: .toRotationMatrix());
55: assertEquals(expected, actual);
56: }
57: }
|