View Javadoc

1   package org.lcsim.spacegeom;
2   // SpacePointVecTest.cpp
3   import junit.framework.TestCase;
4   
5   import org.lcsim.spacegeom.CartesianPointVector;
6   import org.lcsim.spacegeom.CylindricalPointVector;
7   import org.lcsim.spacegeom.SpacePointVector;
8   import org.lcsim.spacegeom.SphericalPointVector;
9   
10  // Test the SpacePointVector class.
11  
12  public class SphericalPointVectorTest extends TestCase
13  {
14      boolean debug = false;
15      //**********************************************************************
16      
17      public static boolean myequal(double x1, double x2)
18      {
19          return Math.abs(x2-x1) < 1.e-10;
20      }
21      
22      //**********************************************************************
23      
24      public void testSphericalPointVector()
25      {
26          
27          String name = "SphericalPointVector";
28          String ok_prefix = name + " test (I): ";
29          String error_prefix = name + " test (E): ";
30          
31          if (debug) System.out.println( ok_prefix
32                  + "------- Testing component " + name + ". -------" );
33          
34          double x = 1.23;
35          double y = 2.46;
36          double z = 3.69;
37          double vx = 0.23;
38          double vy = 0.45;
39          double vz = 0.67;
40          
41          //**********************************************************************
42          
43          if (debug) System.out.println( ok_prefix + "Testing constructors." );
44          // Create a spacevector
45          CartesianPointVector cart = new CartesianPointVector(x,y,z,vx,vy,vz);
46          if (debug) System.out.println( cart );
47          
48          // Create in cylindrical coordinates.
49          // FIXME adjust for new definition of class. Needs to be done throughout the class
50          CylindricalPointVector cyl = new CylindricalPointVector( cart.getStartPoint().rxy(), cart.getStartPoint().phi(), cart.getStartPoint().z(),
51                  cart.v_rxy(), cart.v_phi(), cart.v_z() );
52          if (debug) System.out.println( cyl );
53          
54          // Create in spherical coordinates.
55          // FIXME adjust for new definition of class
56          SphericalPointVector sph = new SphericalPointVector( cyl.getStartPoint().rxyz(), cyl.getStartPoint().phi(), cyl.getStartPoint().theta(),
57                  cyl.v_rxyz(), cyl.v_theta(), cyl.v_phi() );
58          if (debug) System.out.println( sph );
59          
60          assertTrue( myequal(sph.getStartPoint().x(),x) );
61          assertTrue( myequal(sph.getStartPoint().y(),y) );
62          assertTrue( myequal(sph.getStartPoint().z(),z) );
63          assertTrue( myequal(sph.v_x(),vx) );
64          assertTrue( myequal(sph.v_y(),vy) );
65          assertTrue( myequal(sph.v_z(),vz) );
66          
67          // Create a cartesian coordinates from spacepoint
68          CartesianPointVector cart2 = new CartesianPointVector( sph.getStartPoint(), sph.v_x(), sph.v_y(), sph.v_z() );
69          if (debug) System.out.println( cart2 );
70          
71          // Create in cylindrical coordinates.
72          CylindricalPointVector cyl2 = new CylindricalPointVector( cart2.getStartPoint(),
73                  cart2.v_rxy(), cart2.v_phi(), cart2.v_z() );
74          if (debug) System.out.println( cyl2 );
75          
76          // Create in spherical coordinates.
77          SphericalPointVector sph2 = new SphericalPointVector( cyl2.getStartPoint(),
78                  cyl2.v_rxyz(), cyl2.v_theta(), cyl2.v_phi() );
79          if (debug) System.out.println( sph2 );
80          
81          assertTrue( myequal(sph2.getStartPoint().x(),x) );
82          assertTrue( myequal(sph2.getStartPoint().y(),y) );
83          assertTrue( myequal(sph2.getStartPoint().z(),z) );
84          assertTrue( myequal(sph2.v_x(),vx) );
85          assertTrue( myequal(sph2.v_y(),vy) );
86          assertTrue( myequal(sph2.v_z(),vz) );
87          
88          //**********************************************************************
89          
90          if (debug) System.out.println( ok_prefix + "Testing equality." );
91          assertTrue( sph.equals(sph) );
92          assertTrue( sph.equals(sph2) );
93          if( sph.notEquals(sph2) );
94          
95          //**********************************************************************
96          
97          if (debug) System.out.println( ok_prefix + "Testing assignment." );
98          SpacePointVector svec = new SpacePointVector();
99          if (debug) System.out.println( svec );
100         if (debug) System.out.println( "testing assignment svec.magnitude() and 0 " + svec.magnitude() + " " + 0. );
101         if (debug) System.out.println(  "spacepoint equal " + (svec.magnitude()==0.0) );
102         //	Assert.assertTrue( SpacePoint.equal(svec.magnitude(),0.0) );
103         svec = sph;
104         if (debug) System.out.println( svec );
105         if (debug) System.out.println( "testing assignment svec.x() and x " + svec.getStartPoint().x() + " " + x );
106         assertTrue( myequal(svec.getStartPoint().x(),x) );
107         assertTrue( myequal(svec.getStartPoint().y(),y) );
108         assertTrue( myequal(svec.getStartPoint().z(),z) );
109         assertTrue( myequal(svec.v_x(),vx) );
110         assertTrue( myequal(svec.v_y(),vy) );
111         assertTrue( myequal(svec.v_z(),vz) );
112         
113         //**********************************************************************
114         
115         if (debug) System.out.println( ok_prefix + "Testing normalizations." );
116         double n0 = vx*vx + vy*vy + vz*vz;
117         if (debug) System.out.println( "n0= " +n0 );
118         double ncart = svec.v_x()*svec.v_x() +
119                 svec.v_y()*svec.v_y() +
120                 svec.v_z()*svec.v_z();
121         if (debug) System.out.println( "ncart= " +ncart );
122         double ncyl = svec.v_rxy()*svec.v_rxy() +
123                 // FIXME or not... svec.v_phi()*svec.v_phi() +
124                 svec.v_z()*svec.v_z();
125         if (debug) System.out.println( "ncyl= " +ncyl );
126         double nsph = svec.v_rxyz()*svec.v_rxyz();
127         // FIXME not really + svec.v_theta()*svec.v_theta() + svec.v_phi()*svec.v_phi();
128         if (debug) System.out.println( "nsph= " +nsph );
129         assertTrue( myequal(ncart,n0) );
130         // FIXME I hope this never really passed 
131         assertTrue( myequal(ncyl,n0) );
132         // FIXME This isn't supposed to pass, either, is it ?
133         assertTrue( myequal(nsph,n0) );
134         assertTrue( myequal( Math.sqrt(n0), svec.magnitude() ) );
135         //
136         if (debug) System.out.println("Testing copy constructor and clone");
137         SpacePointVector spv = (SpacePointVector) svec.clone();
138         
139         //**********************************************************************
140         
141         if (debug) System.out.println( ok_prefix
142                 + "------------- All tests passed. ------------" );
143     }
144     
145 }