Print

Print


Commit in GeomConverter/test/org/lcsim/detector/kernel on MAIN
CoordinateTransformation3DTest.java+138added 1.1
Rotation3DTest.java+41added 1.1
+179
2 added files
JM: Dev code tests.

GeomConverter/test/org/lcsim/detector/kernel
CoordinateTransformation3DTest.java added at 1.1
diff -N CoordinateTransformation3DTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CoordinateTransformation3DTest.java	23 Feb 2007 21:47:48 -0000	1.1
@@ -0,0 +1,138 @@
+package org.lcsim.detector.kernel;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CoordinateTransformation3DTest extends TestCase
+{		
+    public CoordinateTransformation3DTest(String name)
+    {
+        super(name);
+    }
+    
+    public static junit.framework.Test suite()
+    {
+        return new TestSuite(CoordinateTransformation3DTest.class);
+    }
+    
+    protected void setUp() throws Exception
+    {}
+       
+    public void testIdentityTransformation()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testIdentityTransformation");
+    	
+    	CoordinateTransformation3D transform = new CoordinateTransformation3D();     
+    	CoordinateTransformation3D point = new CoordinateTransformation3D(new BasicHep3Vector(1.0,0.0,0.0), new Rotation3D());
+    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
+    	
+    	Hep3Vector translation = result.getTranslation();
+    	assert(translation.x() == 1.0);
+    	assert(translation.y() == 0);
+    	assert(translation.y() == 0);
+    	
+    	Rotation3D rotation = result.getRotation();
+    	assert(rotation.getMatrix().trace() == 3.0);    	
+    }    
+    
+    public void testSimpleTranslationX()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationX");
+    	
+    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(1.0,0.0,0.0));
+    	CoordinateTransformation3D point = new CoordinateTransformation3D();
+    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
+    	Hep3Vector translation = result.getTranslation();
+    	assert(translation.x() == 1.0);
+    	assert(translation.y() == 0.0);
+    	assert(translation.z() == 0.0);
+    }
+    
+    public void testSimpleTranslationY()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationY");
+    	
+    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(0.0,1.0,0.0));
+    	CoordinateTransformation3D point = new CoordinateTransformation3D();
+    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
+    	Hep3Vector translation = result.getTranslation();
+    	assert(translation.x() == 0.0);
+    	assert(translation.y() == 1.0);
+    	assert(translation.z() == 0.0);
+    }
+    
+    public void testSimpleTranslationZ()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationZ");
+    	
+    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(0.0,0.0,1.0));
+    	CoordinateTransformation3D point = new CoordinateTransformation3D();
+    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
+    	Hep3Vector translation = result.getTranslation();
+    	assert(translation.x() == 0.0);
+    	assert(translation.y() == 0.0);
+    	assert(translation.z() == 1.0);
+    }
+    
+    public void testSimpleTranslationXYZ()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationXYZ");
+    	
+    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(1.0,1.0,1.0));
+    	CoordinateTransformation3D point = new CoordinateTransformation3D();
+    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
+    	Hep3Vector translation = result.getTranslation();
+    	assert(translation.x() == 1.0);
+    	assert(translation.y() == 1.0);
+    	assert(translation.z() == 1.0);
+    }
+    
+    public void testSimpleRotationX()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testSimpleRotationX");
+    	
+    	Rotation3D rotateX = new Rotation3D();
+    	rotateX.setTaitBryan(Math.PI / 4, 0, 0);
+    	CoordinateTransformation3D transform = new CoordinateTransformation3D(rotateX);
+    	//CoordinateTransformation3D point = new CoordinateTransformation3D();
+    	Hep3Vector point = new BasicHep3Vector(1.0,0.0,0.0);
+    	Hep3Vector result = transform.rotate(point);
+    	System.out.println("Transform");
+    	transform.getRotation().printOut(System.out);
+    	System.out.printf("new point = ( %.4f %.4f %.4f )\n",result.x(),result.y(),result.z());
+    	//CoordinateTransformation3D.mult(point, transform);
+    	//Hep3Rotation rotation = result.getRotation();    	
+    	
+    	//System.out.println("transformation");
+    	//rotateX.printOut(System.out);
+    	//System.out.println();
+    	//System.out.println("transformed point");
+    	//rotation.printOut(System.out);    	
+    	
+    	//assertStrictEquals(rotation, rotateX);
+    	
+    }
+    
+    public void testRotationIdentity()
+    {
+    	System.out.println("CoordinateTransformation3DTest.testRotationIdentity");
+    	Rotation3D rotation = new Rotation3D();
+    	System.out.println("This should be the identity matrix.");
+    	rotation.printOut(System.out);
+    }
+    
+    private static final void assertStrictEquals(Rotation3D rotate1, Rotation3D rotate2)
+    {
+       	assert(rotate1.xx() == rotate2.xx());	
+    	assert(rotate1.xy() == rotate2.xy());
+    	assert(rotate1.xz() == rotate2.xz());
+    	assert(rotate1.yx() == rotate2.yx());
+    	assert(rotate1.yy() == rotate2.yy());
+    	assert(rotate1.yz() == rotate2.yz());
+    	assert(rotate1.zx() == rotate2.zx());
+    	assert(rotate1.zy() == rotate2.zy());
+    	assert(rotate1.zz() == rotate2.zz());    	
+    }
+}
\ No newline at end of file

GeomConverter/test/org/lcsim/detector/kernel
Rotation3DTest.java added at 1.1
diff -N Rotation3DTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Rotation3DTest.java	23 Feb 2007 21:47:48 -0000	1.1
@@ -0,0 +1,41 @@
+package org.lcsim.detector.kernel;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class Rotation3DTest extends TestCase
+{		
+    public Rotation3DTest(String name)
+    {
+        super(name);
+    }
+    
+    public static junit.framework.Test suite()
+    {
+        return new TestSuite(Rotation3DTest.class);
+    }
+    
+    protected void setUp() throws Exception
+    {}
+       
+    public void testIdentityIsDefault()
+    {
+    	Rotation3D rotation = new Rotation3D();
+    	assert(rotation.getMatrix().trace() == 3.0);
+    }    
+
+    public void testSimpleRotationX()
+    {
+    	Hep3Vector coordinate = new BasicHep3Vector(0.0,1.0,0.0);
+    	Rotation3D rotation = new Rotation3D();
+    	rotation.setPassiveEuler(Math.PI / 2, 0, 0);
+    	Hep3Vector result = VecOp.mult(rotation.getMatrix(),coordinate);
+    	System.out.println("90 degree X rotation");
+    	rotation.printOut(System.out);
+    	System.out.printf("original point -> ( %.4f %.4f %.4f ) \n",coordinate.x(),coordinate.y(),coordinate.z());
+    	System.out.printf("rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
+    }
+}
\ No newline at end of file
CVSspam 0.2.8