Extract Quaternion.main to junit test.
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 10 Jul 2012 18:52:13 +0000 (18:52 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 10 Jul 2012 18:52:13 +0000 (18:52 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@883 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/util/Quaternion.java
core/test/net/sf/openrocket/util/QuaternionTest.java [new file with mode: 0644]

index 5f2776626c26fcd0764be7a33a8e8fee717f72cd..e82eb9d22e31a9aca5904d6174cc16a08d7971fe 100644 (file)
@@ -318,39 +318,4 @@ public class Quaternion {
                return String.format("Quaternion[%f,%f,%f,%f,norm=%f]", w, x, y, z, this.norm());
        }
        
-       public static void main(String[] arg) {
-               
-               Quaternion q = new Quaternion(Math.random() - 0.5, Math.random() - 0.5,
-                               Math.random() - 0.5, Math.random() - 0.5);
-               q.normalize();
-               
-               q = new Quaternion(-0.998717, 0.000000, 0.050649, -0.000000);
-               
-               Coordinate coord = new Coordinate(10 * (Math.random() - 0.5),
-                               10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5));
-               
-               System.out.println("Quaternion: " + q);
-               System.out.println("Coordinate: " + coord);
-               coord = q.invRotate(coord);
-               System.out.println("Rotated: " + coord);
-               coord = q.rotate(coord);
-               System.out.println("Back:       " + coord);
-               
-
-               q = new Quaternion(0.237188, 0.570190, -0.514542, 0.594872);
-               q.normalize();
-               Coordinate c = new Coordinate(148578428.914, 8126778.954, -607.741);
-               
-               System.out.println("Rotated: " + q.rotate(c));
-               
-               //              Coordinate c = new Coordinate(0,1,0);
-               //              Coordinate rot = new Coordinate(Math.PI/4,0,0);
-               //              
-               //              System.out.println("Before: "+c);
-               //              c = rotation(rot).invRotate(c);
-               //              System.out.println("After: "+c);
-               
-
-       }
-       
 }
diff --git a/core/test/net/sf/openrocket/util/QuaternionTest.java b/core/test/net/sf/openrocket/util/QuaternionTest.java
new file mode 100644 (file)
index 0000000..26a2dc2
--- /dev/null
@@ -0,0 +1,48 @@
+package net.sf.openrocket.util;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+
+public class QuaternionTest {
+
+       @Test
+       public void oldMainTest() {
+
+               // This is normalized already
+               Quaternion q = new Quaternion(0.237188, 0.570190, -0.514542, 0.594872);
+               assertEquals( 1.0, q.norm(), 0.01);
+
+               q.normalize();
+               assertEquals( 0.237188, q.getW(), 0.00001);
+               assertEquals( 0.570190, q.getX(), 0.00001);
+               assertEquals( -0.514542, q.getY(), 0.00001);
+               assertEquals( 0.594872, q.getZ(), 0.00001);
+               assertEquals( 1.0, q.norm(), 0.01);
+
+               Coordinate c = new Coordinate(148578428.914, 8126778.954, -607.741);
+
+               Coordinate r = q.rotate(c);
+
+               System.out.println("Rotated: " + q.rotate(c));
+
+               assertEquals( -42312599.537, r.x, 0.001);
+               assertEquals( -48162747.551, r.y, 0.001);
+               assertEquals( 134281904.197, r.z, 0.001);
+
+               c = new Coordinate(0,1,0);
+               Coordinate rot = new Coordinate(Math.PI/4,0,0);
+
+               System.out.println("Before: "+c);
+               c = Quaternion.rotation(rot).invRotate(c);
+               System.out.println("After: "+c);
+               
+               assertEquals( 0.0, c.x, 0.001);
+               assertEquals( 0.707, c.y, 0.001);
+               assertEquals( -0.707, c.z, 0.001);
+
+
+       }
+
+
+}