View Javadoc

1   /*
2    * Detector_Test.java
3    *
4    * Created on July 24, 2007, 4:31 PM
5    *
6    * $Id: Detector_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $
7    */
8   
9   package org.lcsim.recon.tracking.trflayer;
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 Detector_Test extends TestCase
19  {
20      private boolean debug;
21      /** Creates a new instance of Detector_Test */
22      public void testDetector()
23      {
24           String component = "Detector";
25          String ok_prefix = component + " (I): ";
26          String error_prefix = component + " test (E): ";
27          
28          if(debug) System.out.println(ok_prefix
29                  + "---------- Testing component " + component
30                  + ". ----------" );
31          
32          //********************************************************************
33          
34          if(debug) System.out.println(ok_prefix + "Test subclass constructor." );
35          double x1 = 5.0;
36          Layer lyr1 = new LayerTest(x1);
37          Detector det1 = new OneLayerDetectorTest("Layer One", lyr1);
38          if(debug) System.out.println(det1 );
39          Assert.assertTrue( det1.isOk() );
40          Assert.assertTrue( det1.layerNames().size() == 1 );
41          Assert.assertTrue( det1.layerNames().get(0) == "Layer One" );
42          Assert.assertTrue( det1.isAssigned( "Layer One" ) );
43          Assert.assertTrue( ! det1.isAssigned( "Layer 1" ) );
44          Assert.assertTrue( det1.layer("Layer One").typeName().equals(lyr1.typeName()) );
45          
46          
47          //********************************************************************
48          
49          if(debug) System.out.println(ok_prefix + "Test composite detector." );
50          double x2 = 2.0;
51          double x3 = 3.0;
52          Layer lyr2  = new LayerTest(x2);
53          Layer lyr3  = new LayerTest(x3);
54          Detector  det2  = new TwoLayerDetectorTest("layer 2", lyr2, "layer 3", lyr3);
55          if(debug) System.out.println(det2 );
56          TwoSubDetectorTest det3 = new TwoSubDetectorTest(det1,det2);
57          if(debug) System.out.println(det3 );
58          Assert.assertTrue( det3.isOk() );
59          Assert.assertTrue( det3.layerNames().size() == 3 );
60          Assert.assertTrue( det3.layerNames().get(0) == "Layer One" );
61          Assert.assertTrue( det3.layerNames().get(det3.layerNames().size()-1) == "layer 3" );
62          Assert.assertTrue( det3.isAssigned( "Layer One" ) );
63          Assert.assertTrue( det3.isAssigned( "layer 2" ) );
64          Assert.assertTrue( det3.isAssigned( "layer 3" ) );
65          Assert.assertTrue( ! det1.isAssigned( "Layer 1" ) );
66          Assert.assertTrue( det3.layer("Layer One").typeName().equals(lyr1.typeName()) );
67          Assert.assertTrue( det3.layer("layer 2").typeName().equals(lyr2.typeName()) );
68          
69          //********************************************************************
70          
71          //********************************************************************
72          
73          if(debug) System.out.println(ok_prefix
74                  + "------------- All tests passed. -------------" );
75          
76          //********************************************************************       
77      }
78      
79  }