View Javadoc

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