1 package org.lcsim.spacegeom; 2 // SpacePathTest.cpp 3 4 // Test the SpacePath class. 5 6 import junit.framework.TestCase; 7 8 import org.lcsim.spacegeom.CartesianPath; 9 import org.lcsim.spacegeom.CylindricalPath; 10 import org.lcsim.spacegeom.SpacePath; 11 import org.lcsim.spacegeom.SphericalPath; 12 13 public class SpacePathTest extends TestCase 14 { 15 boolean debug = false; 16 //********************************************************************** 17 18 private static final boolean myequal(double x1, double x2) 19 { 20 return Math.abs(x2-x1) < 1.e-10; 21 } 22 23 //********************************************************************** 24 25 public void testSpacePath() 26 { 27 28 String name = "SpacePoint"; 29 String ok_prefix = name + " test (I): "; 30 String error_prefix = name + " test (E): "; 31 32 if (debug) System.out.println( ok_prefix 33 + "------- Testing component " + name + ". -------" ); 34 35 double x = 1.23; 36 double y = 2.46; 37 double z = 3.69; 38 double dx = 0.23; 39 double dy = 0.45; 40 double dz = 0.67; 41 42 //********************************************************************** 43 44 if (debug) System.out.println( ok_prefix + "Testing constructors." ); 45 // Create a space path element 46 CartesianPath cart = new CartesianPath(x,y,z,dx,dy,dz); 47 if (debug) System.out.println( cart ); 48 49 // Create in cylindrical coordinates. 50 CylindricalPath cyl = new CylindricalPath( cart.getStartPoint().rxy(), cart.getStartPoint().phi(), cart.getStartPoint().z(), 51 cart.drxy(), cart.rxy_dphi(), cart.dz() ); 52 if (debug) System.out.println( cyl ); 53 54 // Create in spherical coordinates. 55 SphericalPath sph = new SphericalPath( cyl.getStartPoint().rxyz(), cyl.getStartPoint().phi(), cyl.getStartPoint().theta(), 56 cyl.drxyz(), cyl.rxyz_dtheta(), cyl.rxy_dphi() ); 57 if (debug) System.out.println( sph ); 58 59 assertTrue( myequal(sph.getStartPoint().x(),x) ); 60 assertTrue( myequal(sph.getStartPoint().y(),y) ); 61 assertTrue( myequal(sph.getStartPoint().z(),z) ); 62 assertTrue( myequal(sph.dx(),dx) ); 63 assertTrue( myequal(sph.dy(),dy) ); 64 assertTrue( myequal(sph.dz(),dz) ); 65 66 //********************************************************************** 67 68 if (debug) System.out.println( ok_prefix + "Testing assignment." ); 69 70 SpacePath dpth = new SpacePath(); 71 if (debug) System.out.println( dpth ); 72 assertTrue( dpth.magnitude() == 0.0 ); 73 dpth = sph; 74 if (debug) System.out.println( dpth ); 75 assertTrue( myequal(dpth.getStartPoint().x(),x) ); 76 assertTrue( myequal(dpth.getStartPoint().y(),y) ); 77 assertTrue( myequal(dpth.getStartPoint().z(),z) ); 78 assertTrue( myequal(dpth.dx(),dx) ); 79 assertTrue( myequal(dpth.dy(),dy) ); 80 assertTrue( myequal(dpth.dz(),dz) ); 81 82 //********************************************************************** 83 84 if (debug) System.out.println( ok_prefix + "Testing normalizations." ); 85 double n0 = dx*dx + dy*dy + dz*dz; 86 if (debug) System.out.println( n0 ); 87 double ncart = dpth.dx()*dpth.dx() + 88 dpth.dy()*dpth.dy() + 89 dpth.dz()*dpth.dz(); 90 if (debug) System.out.println( ncart ); 91 double ncyl = dpth.drxy()*dpth.drxy() + 92 // FIXME dpth.rxy_dphi()*dpth.rxy_dphi() + 93 dpth.dz()*dpth.dz(); 94 if (debug) System.out.println( ncyl ); 95 double nsph = dpth.drxyz()*dpth.drxyz(); 96 // FIXME dpth.rxy_dphi()*dpth.rxy_dphi() + 97 // FIXME dpth.rxyz_dtheta()*dpth.rxyz_dtheta(); 98 if (debug) System.out.println( nsph ); 99 assertTrue( myequal(ncart,n0) ); 100 assertTrue( myequal(ncyl,n0) ); 101 assertTrue( myequal(nsph,n0) ); 102 assertTrue( myequal( Math.sqrt(n0), dpth.magnitude() ) ); 103 104 //********************************************************************** 105 106 if (debug) System.out.println( ok_prefix 107 + "------------- All tests passed. ------------" ); 108 109 } 110 }