View Javadoc

1   /*
2    * Surface_Test.java
3    *
4    * Created on July 24, 2007, 11:57 AM
5    *
6    * $Id: Surface_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $
7    */
8   
9   package org.lcsim.recon.tracking.trfbase;
10  
11  import junit.framework.TestCase;
12  import org.lcsim.recon.tracking.trfutil.Assert;
13  
14  /**
15   *
16   * @author Norman Graf
17   */
18  public class Surface_Test extends TestCase
19  {
20      private boolean debug;
21      /** Creates a new instance of Surface_Test */
22      public void testSurface()
23      {
24                 String component = "Surface";
25          String ok_prefix = component + " (I): ";
26          String error_prefix = component + " test (E): ";
27          
28          if(debug) System.out.println("-------- Testing component " + component
29                  + ". --------" );
30          
31          //********************************************************************
32          
33          if(debug) System.out.println("Testing constructors." );
34          SurfTest tst1 = new SurfTest(123.);
35          if(debug) System.out.println( tst1 );
36          SurfTest tst2 = new SurfTest(246.);
37          if(debug) System.out.println( tst2 );
38          BSurfTest btst1 = new BSurfTest(123.,456.);
39          if(debug) System.out.println( btst1 );
40          BSurfTest btst2 = new BSurfTest(246.,369.);
41          if(debug) System.out.println( btst2 );
42          
43          //********************************************************************
44          
45          if(debug) System.out.println("Check SurfTest type." );
46          if(debug) System.out.println( Surface.staticType());
47          if(debug) System.out.println( SurfTest.staticType());
48          if(debug) System.out.println( tst1.type());
49          Assert.assertTrue( tst1.type().equals(SurfTest.staticType()) );
50          if(debug) System.out.println( tst1.pureType());
51          Assert.assertTrue( tst1.pureType().equals(SurfTest.staticType()) );
52          if(debug) System.out.println( tst1.genericType());
53          Assert.assertTrue( tst1.genericType().equals(Surface.staticType()) );
54          
55          //********************************************************************
56          
57          if(debug) System.out.println("Check BSurfTest type." );
58          if(debug) System.out.println( BSurfTest.staticType());
59          if(debug) System.out.println( btst1.type());
60          Assert.assertTrue( btst1.type() == BSurfTest.staticType() );
61          if(debug) System.out.println( btst1.pureType());
62          Assert.assertTrue( btst1.pureType() == SurfTest.staticType() );
63          if(debug) System.out.println( btst1.genericType());
64          Assert.assertTrue( btst1.genericType() == Surface.staticType() );
65          
66          //********************************************************************
67          
68          if(debug) System.out.println("Testing purity." );
69          if ( ! tst1.isPure() )
70          {
71              if(debug) System.out.println(error_prefix +"Pure test class is not pure." );
72              System.exit(1);
73          }
74          if ( btst1.isPure() )
75          {
76              if(debug) System.out.println(error_prefix +"Bounded test class is pure." );
77              System.exit(2);
78          }
79          
80          //********************************************************************
81          
82          if(debug) System.out.println("Testing equality." );
83          Assert.assertTrue( tst1.boundEqual(tst1) );
84          Assert.assertTrue( tst1.equals(tst1) );
85          Assert.assertTrue( ! tst1.boundEqual(tst2) );
86          Assert.assertTrue( !tst1.equals(tst2) );
87          Assert.assertTrue( ! tst1.boundEqual(btst1) );
88          Assert.assertTrue( ! btst1.boundEqual(tst1) );
89          if(debug) System.out.println(btst1);
90          if(debug) System.out.println(tst1);
91          Assert.assertTrue( tst1.pureEqual(btst1) );
92          Assert.assertTrue( btst1.pureEqual(tst1) );
93          
94          //********************************************************************
95          
96          if(debug) System.out.println("Testing ordering." );
97          Assert.assertTrue( ! tst1.pureLessThan(tst1) );
98          Assert.assertTrue( tst1.pureLessThan(tst2) || tst2.pureLessThan(tst1) );
99          Assert.assertTrue( ! (tst1.pureLessThan(tst2) && tst2.pureLessThan(tst1)) );
100         Assert.assertTrue( ! btst1.pureLessThan(tst1) );
101         Assert.assertTrue( ! btst1.pureLessThan(btst1) );
102         Assert.assertTrue( btst1.pureLessThan(tst2) || tst2.pureLessThan(btst1) );
103         
104         //********************************************************************
105         
106         if(debug) System.out.println("Testing assignment." );
107         SurfTest tst3 = tst1;
108         if ( tst3 != tst1 )
109         {
110             if(debug) System.out.println(error_prefix + "Failure: tst3 != tst1." );
111             System.exit(7);
112         }
113         BSurfTest btst3 = btst1;
114         if ( btst3 != btst1 )
115         {
116             if(debug) System.out.println(error_prefix + "Failure: btst3 != btst1." );
117             System.exit(8);
118         }
119         
120         //********************************************************************
121         
122         if(debug) System.out.println("Testing types." );
123         if(debug) System.out.println( tst1.type() );
124         if(debug) System.out.println( tst2.type() );
125         if(debug) System.out.println( btst1.type() );
126         if(debug) System.out.println( btst2.type() );
127         
128         Assert.assertTrue( tst1.type() == tst2.type() );
129         
130         Assert.assertTrue( btst1.type() == btst2.type() );
131         Assert.assertTrue( tst1.type() != btst1.type() );
132         
133         //********************************************************************
134         
135         if(debug) System.out.println("Testing pure types." );
136         if(debug) System.out.println( tst1.pureType() );
137         if(debug) System.out.println( btst1.pureType() );
138         Assert.assertTrue( tst1.pureType().equals(tst1.type()) );
139         Assert.assertTrue( tst1.pureType().equals(btst1.pureType()) );
140         
141         //********************************************************************
142         
143         if(debug) System.out.println("Test curvature." );
144         TrackVector vec = new TrackVector();
145         vec.set(4,0.0012345);
146         if(debug) System.out.println( "expect " + vec.get(4) + "; found " + tst1.qOverP(vec) );
147         Assert.assertTrue( tst1.qOverP(vec) == vec.get(4) );
148         
149         //********************************************************************
150         
151         if(debug) System.out.println( ok_prefix
152                 + "------------- All tests passed. -------------" );
153         
154         //********************************************************************
155     }
156     
157 }