From: kruland2607 Date: Thu, 12 Jul 2012 02:44:32 +0000 (+0000) Subject: Extract Transformation.main to junit test. X-Git-Tag: upstream/12.09^2~112 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=56d377c0a24425c152247985e114c21e62ee8173;p=debian%2Fopenrocket Extract Transformation.main to junit test. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@887 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/src/net/sf/openrocket/util/Transformation.java b/core/src/net/sf/openrocket/util/Transformation.java index 2c546974..8656a4f2 100644 --- a/core/src/net/sf/openrocket/util/Transformation.java +++ b/core/src/net/sf/openrocket/util/Transformation.java @@ -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 index 00000000..25b8941b --- /dev/null +++ b/core/test/net/sf/openrocket/util/TransformationTest.java @@ -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); + } + } + + +}