Extract Transformation.main to junit test.
This commit is contained in:
parent
960555c108
commit
357f370096
@ -257,23 +257,4 @@ public class Transformation implements java.io.Serializable {
|
|||||||
return this.translate.equals(o.translate);
|
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
82
core/test/net/sf/openrocket/util/TransformationTest.java
Normal file
82
core/test/net/sf/openrocket/util/TransformationTest.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user