Extract Transformation.main to junit test.
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 12 Jul 2012 02:44:32 +0000 (02:44 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 12 Jul 2012 02:44:32 +0000 (02:44 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@887 180e2498-e6e9-4542-8430-84ac67f01cd8

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

index 2c54697409da1b9ab6cd8baba4a13ce7c0722238..8656a4f25762e7cd857cb61e31cb722f2cd22137 100644 (file)
@@ -257,23 +257,4 @@ public class Transformation implements java.io.Serializable {
                return this.translate.equals(o.translate);
        }
        
-       public static void main(String[] arg) {
-               Transformation t;
-               
-               t = new Transformation();
-               t.print("Empty");
-               t = new Transformation(1,2,3);
-               t.print("1,2,3");
-               t = new Transformation(new Coordinate(2,3,4));
-               t.print("coord 2,3 4");
-               
-               t = Transformation.rotate_y(0.01);
-               t.print("rotate_y 0.01");
-               
-               t = new Transformation(-1,0,0);
-               t = t.applyTransformation(Transformation.rotate_y(0.01));
-               t = t.applyTransformation(new Transformation(1,0,0));
-               t.print("shift-rotate-shift");
-       }
-       
 }
diff --git a/core/test/net/sf/openrocket/util/TransformationTest.java b/core/test/net/sf/openrocket/util/TransformationTest.java
new file mode 100644 (file)
index 0000000..25b8941
--- /dev/null
@@ -0,0 +1,82 @@
+package net.sf.openrocket.util;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+
+public class TransformationTest {
+       @Test
+       public void oldMainTest() {
+               Transformation t;
+
+               t = new Transformation();
+               {
+                       Coordinate a = t.transform( new Coordinate(1,0,0) );
+                       assertEquals( new Coordinate(1,0,0), a );
+                       a = t.transform( new Coordinate(0,1,0) );
+                       assertEquals( new Coordinate(0,1,0), a );
+                       a = t.transform( new Coordinate(0,0,1) );
+                       assertEquals( new Coordinate(0,0,1), a );
+               }
+
+               t = new Transformation(1,2,3);
+               {
+                       Coordinate a = t.transform( new Coordinate(1,0,0) );
+                       assertEquals( new Coordinate(2,2,3), a );
+                       a = t.transform( new Coordinate(0,1,0) );
+                       assertEquals( new Coordinate(1,3,3), a );
+                       a = t.transform( new Coordinate(0,0,1) );
+                       assertEquals( new Coordinate(1,2,4), a );
+               }
+               
+               
+               t = new Transformation(new Coordinate(2,3,4));
+               {
+                       Coordinate a = t.transform( new Coordinate(1,0,0) );
+                       assertEquals( new Coordinate(3,3,4), a );
+                       a = t.transform( new Coordinate(0,1,0) );
+                       assertEquals( new Coordinate(2,4,4), a );
+                       a = t.transform( new Coordinate(0,0,1) );
+                       assertEquals( new Coordinate(2,3,5), a );
+               }
+
+               // FIXME - is this correct?  shouldn't a rotation preserve coordinate length?
+               t = Transformation.rotate_y(0.01);
+               {
+                       Coordinate a = t.transform( new Coordinate(1,0,0) );
+                       // we need to test individual coordinates due to error.
+                       assertEquals( 1, a.x, .001);
+                       assertEquals( 0, a.y, .001);
+                       assertEquals( -.01, a.z, .001);
+                       a = t.transform( new Coordinate(0,1,0) );
+                       assertEquals( new Coordinate(0,1,0), a );
+                       a = t.transform( new Coordinate(0,0,1) );
+                       // we need to test individual coordinates due to error.
+                       assertEquals( .01, a.x, .001);
+                       assertEquals( 0, a.y, .001);
+                       assertEquals( 1, a.z, .001);
+               }
+
+               t = new Transformation(-1,0,0);
+               t = t.applyTransformation(Transformation.rotate_y(0.01));
+               t = t.applyTransformation(new Transformation(1,0,0));
+               {
+                       Coordinate a = t.transform( new Coordinate(1,0,0) );
+                       // we need to test individual coordinates due to error.
+                       assertEquals( 1, a.x, .001);
+                       assertEquals( 0, a.y, .001);
+                       assertEquals( -.02, a.z, .001);
+                       a = t.transform( new Coordinate(0,1,0) );
+                       assertEquals( 0, a.x, .001);
+                       assertEquals( 1, a.y, .001);
+                       assertEquals( -.01, a.z, .001);
+                       a = t.transform( new Coordinate(0,0,1) );
+                       // we need to test individual coordinates due to error.
+                       assertEquals( .01, a.x, .001);
+                       assertEquals( 0, a.y, .001);
+                       assertEquals( .99, a.z, .001);
+               }
+       }
+
+
+}