1
2
3
4
5
6
7 package net.sourceforge.kamiwaai.geometricalgebra;
8
9 import junit.framework.TestCase;
10
11 /***
12 * @author Ginanjar Utama
13 *
14 * To change the template for this generated type comment go to Window -
15 * Preferences - Java - Code Generation - Code and Comments
16 */
17 public class ComplexQuaternionTest extends TestCase {
18 ComplexNumber c1 = new ComplexNumber(1.0, 2.0);
19 ComplexNumber c2 = new ComplexNumber(3.0, 4.0);
20 ComplexNumber c3 = new ComplexNumber(5.0, 6.0);
21 ComplexNumber c4 = new ComplexNumber(7.0, 8.0);
22 ComplexNumber[] c1234 = { c1, c2, c3, c4 };
23 ComplexNumber[] c2341 = { c2, c3, c4, c1 };
24 ComplexQuat cq1 = new ComplexQuat(c1234);
25 ComplexQuat cq2 = new ComplexQuat(c2341);
26
27 public void testAddComplexQuaternion() {
28 ComplexNumber c12 = new ComplexNumber(c1.add(c2));
29 ComplexNumber c23 = new ComplexNumber(c2.add(c3));
30 ComplexNumber c34 = new ComplexNumber(c3.add(c4));
31 ComplexNumber c41 = new ComplexNumber(c4.add(c1));
32 ComplexNumber[] c12341 = {c12, c23, c34, c41};
33 ComplexQuat cq1addcq2 = new ComplexQuat(c12341);
34 assertEquals(cq1addcq2, cq1.add(cq2));
35 assertFalse(cq1.equals(cq1.add(cq2)));
36 }
37
38 public void testSubComplexQuaternion() {
39 ComplexNumber c12 = new ComplexNumber(c1.sub(c2));
40 ComplexNumber c23 = new ComplexNumber(c2.sub(c3));
41 ComplexNumber c34 = new ComplexNumber(c3.sub(c4));
42 ComplexNumber c41 = new ComplexNumber(c4.sub(c1));
43 ComplexNumber[] c12341 = {c12, c23, c34, c41};
44 ComplexQuat cq1subcq2 = new ComplexQuat(c12341);
45 assertEquals(cq1subcq2, cq1.sub(cq2));
46 assertFalse(cq1.equals(cq1.sub(cq2)));
47 }
48 public void testMultiplyComplexQuaternion() {
49
50 ComplexNumber c12 = new ComplexNumber(26.0, -132.0);
51 ComplexNumber c23 = new ComplexNumber(-22.0, 136.0);
52 ComplexNumber c34 = new ComplexNumber(-10.0, -12.0);
53 ComplexNumber c41 = new ComplexNumber(-14.0, 64.0);
54 ComplexNumber[] c12341 = {c12, c23, c34, c41};
55 ComplexQuat cq1multcq2 = new ComplexQuat(c12341);
56 assertEquals(cq1multcq2, cq1.mult(cq2));
57 assertFalse(cq1.equals(cq1.mult(cq2)));
58 }
59 public static void main(String[] args) {
60 ComplexNumber c1 = new ComplexNumber(1.0, 2.0);
61 ComplexNumber c2 = new ComplexNumber(3.0, 4.0);
62 ComplexNumber c3 = new ComplexNumber(5.0, 6.0);
63 ComplexNumber c4 = new ComplexNumber(7.0, 8.0);
64 ComplexNumber[] c1234 = { c1, c2, c3, c4 };
65 ComplexNumber[] c2341 = { c2, c3, c4, c1 };
66 ComplexQuat cq1 = new ComplexQuat(c1234);
67 ComplexQuat cq2 = new ComplexQuat(c2341);
68
69 System.out.println(cq1);
70 System.out.println(cq2);
71
72
73
74
75 ComplexQuat cq1multcq2 = cq1.mult(cq2);
76 System.out.println(cq1multcq2);
77 }
78 }