Commit in lcsim/test/org/lcsim/recon/tracking/trfutil on MAIN
StatusInt_t.java+49added 1.1
RandomRegistry_t.java+95added 1.1
Pair_t.java+63added 1.1
StatusValue_t.java+50added 1.1
RootFinder_t.java+49added 1.1
TRFMath_t.java+95added 1.1
ArraySmearer_t.java+87added 1.1
RootFindLinear_t.java+69added 1.1
RandomSimulator_t.java+119added 1.1
RandomGenerator_t.java+152added 1.1
StatusDouble_t.java+49added 1.1
+877
11 added files
Component tests for trfutil.

lcsim/test/org/lcsim/recon/tracking/trfutil
StatusInt_t.java added at 1.1
diff -N StatusInt_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ StatusInt_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,49 @@
+/*
+ * StatusInt_t.java
+ *
+ * Created on July 24, 2007, 11:27 AM
+ *
+ * $Id: StatusInt_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class StatusInt_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of StatusInt_t */
+    public void testStatusInt()
+    {
+        String component = "StatusInt";
+        String ok_prefix = component+ " (I): ";
+        String error_prefix = component+ " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "--------------- testing component" + component
+                + ". -------------");
+        //*******************************************
+        if(debug) System.out.println( ok_prefix+" Test constructor");
+        
+        int value = 12;
+        int status = 137;
+        
+        StatusInt sv = new StatusInt(status, value);
+        
+        if(debug) System.out.println(sv);
+        
+        Assert.assertTrue(sv.status() == status);
+        Assert.assertTrue(sv.value() == value);
+        
+        //*******************************************
+        if(debug) System.out.println( ok_prefix
+                + "-------------------- All tests passed. -------------------");
+        //*******************************************
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
RandomRegistry_t.java added at 1.1
diff -N RandomRegistry_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RandomRegistry_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,95 @@
+/*
+ * RandomRegistry_t.java
+ *
+ * Created on July 24, 2007, 11:25 AM
+ *
+ * $Id: RandomRegistry_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class RandomRegistry_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of RandomRegistry_t */
+    public void testRandomRegistry()
+    {
+        String component = "RandomRegistry";
+        String ok_prefix = component + " (I): ";
+        String error_prefix = component + " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "---------- Testing component " + component
+                + ". ----------" );;
+                
+                //********************************************************************
+                
+                if(debug) System.out.println( ok_prefix + "Create generators." );;
+                double min = 2.0;
+                double max = 5.0;
+                long seed = 246813579L;
+                RandomGeneratorTest rgen1 = new RandomGeneratorTest(min,max,seed);
+                RandomGeneratorTest rgen2 = new RandomGeneratorTest(2*min,2*max,2*seed);
+                RandomGeneratorTest rgen3 = new RandomGeneratorTest(3*min,3*max,3*seed);
+                if(debug) System.out.println( rgen1 );
+                if(debug) System.out.println( rgen2 );
+                if(debug) System.out.println( rgen3 );
+                
+                //********************************************************************
+                
+                if(debug) System.out.println( ok_prefix + "Create registry." );
+                RandomRegistry reg = new RandomRegistry();
+                reg.addGenerator(rgen1);
+                reg.addGenerator(rgen2);
+                reg.addGenerator(rgen3);
+                if(debug) System.out.println( reg );
+                Assert.assertTrue( reg.generatorCount() == 3 );
+                Assert.assertTrue( reg.stateCount() == 0 );
+                Assert.assertTrue( reg.record() == 0 );
+                Assert.assertTrue( reg.record() == 1 );
+                Assert.assertTrue( reg.stateCount() == 2 );
+                
+                //********************************************************************
+                
+                if(debug) System.out.println( ok_prefix + "Check set." );
+                double save1 = rgen2.flat();
+                double save2 = rgen2.flat();
+                rgen2.flat();
+                rgen2.flat();
+                Assert.assertTrue( rgen2.flat() != save1 );
+                Assert.assertTrue( reg.record() == 2 );
+                reg.set(1);
+                Assert.assertTrue( rgen2.flat() == save1 );
+                Assert.assertTrue( rgen2.flat() == save2 );
+                reg.set(2);
+                Assert.assertTrue( rgen2.flat() != save1 );
+                
+                //********************************************************************
+                
+                if(debug) System.out.println( ok_prefix + "Check set for gauss." );
+                // Note odd number of gauss calls.
+                rgen3.gauss();
+                Assert.assertTrue( reg.record() == 3 );
+                double gsave1 = rgen3.gauss();
+                double gsave2 = rgen3.gauss();
+                Assert.assertTrue( rgen3.gauss()!=gsave1 );
+                reg.set(3);
+                Assert.assertTrue(   rgen3.gauss() == gsave1  );
+                Assert.assertTrue(   rgen3.gauss() == gsave2  );
+                
+                //********************************************************************
+                
+                if(debug) System.out.println( ok_prefix
+                        + "------------- All tests passed. -------------" );
+                
+                //********************************************************************
+                
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
Pair_t.java added at 1.1
diff -N Pair_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Pair_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,63 @@
+/*
+ * Pair_t.java
+ *
+ * Created on July 24, 2007, 11:37 AM
+ *
+ * $Id: Pair_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class Pair_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of Pair_t */
+    public void testPair()
+    {
+        String component = "Pair";
+        String ok_prefix = component + " (I): ";
+        String error_prefix = component + " test (E): ";
+        
+        if(debug) System.out.println("-------- Testing component " + component
+                + ". --------" );
+        
+        //********************************************************************
+        
+        if(debug) System.out.println("Testing Constructor");
+        
+        Integer int1 = new Integer(1);
+        Integer int2 = new Integer(2);
+        
+        Pair pair = new Pair(int1, int2);
+        
+        if(debug) System.out.println("pair= "+pair);
+        
+        Assert.assertTrue(pair.first().equals(int1));
+        Assert.assertTrue(pair.second().equals(int2));
+        
+        Object obj1 = new Integer(1);
+        Object obj2 = new Integer(2);
+        Assert.assertTrue(obj1!=int1);
+        Assert.assertTrue(obj2!=int2);
+        Pair pair2 = new Pair(obj1, obj2);
+        Assert.assertTrue(pair.equals(pair2));
+        
+        Integer int3 = new Integer(3);
+        Pair pair3 = new Pair(int1, int3);
+        Assert.assertTrue(pair.notEquals(pair3));
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( "------------- All tests passed. -------------" );
+        
+        
+        //********************************************************************
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
StatusValue_t.java added at 1.1
diff -N StatusValue_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ StatusValue_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,50 @@
+/*
+ * StatusValue_t.java
+ *
+ * Created on July 24, 2007, 11:26 AM
+ *
+ * $Id: StatusValue_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class StatusValue_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of StatusValue_t */
+    public void testStatusValue()
+    {
+        String component = "StatusValue";
+        String ok_prefix = component+ " (I): ";
+        String error_prefix = component + " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "---------- Testing component "+ component
+                + ". ----------" );
+        //***********************************************
+        if(debug) System.out.println( ok_prefix+ "Test constructor");
+        
+        String value = "Value";
+        int status = 137;
+        
+        StatusValue sv = new StatusValue(status, value);
+        
+        if(debug) System.out.println(sv);
+        
+        Assert.assertTrue(sv.status() == status);
+        Assert.assertTrue(sv.value() == value);
+        
+        
+        //***********************************************
+        if(debug) System.out.println( ok_prefix
+                + "----------------------- All tests passed. --------------");
+        //***********************************************
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
RootFinder_t.java added at 1.1
diff -N RootFinder_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RootFinder_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,49 @@
+/*
+ * RootFinder_t.java
+ *
+ * Created on July 24, 2007, 11:33 AM
+ *
+ * $Id: RootFinder_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class RootFinder_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of RootFinder_t */
+    public void testRootFinder()
+    {
+        String component = "RootFinder";
+        String ok_prefix = component+ " (I): ";
+        String error_prefix = component+ " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "--------------- testing component" + component
+                + ". -------------");
+        //*******************************************
+        if(debug) System.out.println( ok_prefix+" Test constructor");
+        
+        RootFinderTest rfind = new RootFinderTest();
+        
+        StatusDouble eval = rfind.evaluate(3.2);
+        StatusDouble soln = rfind.solve(2.34,5.67);
+        Assert.assertTrue( eval.status() == 1 );
+        Assert.assertTrue( eval.value() == 3.2 );
+        Assert.assertTrue( soln.status() == 2 );
+        Assert.assertTrue( soln.value() == 2.34*5.67 );
+        
+        
+        //*******************************************
+        if(debug) System.out.println( ok_prefix
+                + "-------------------- All tests passed. -------------------");
+        //*******************************************
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
TRFMath_t.java added at 1.1
diff -N TRFMath_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TRFMath_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,95 @@
+/*
+ * TRFMath_t.java
+ *
+ * Created on July 24, 2007, 11:34 AM
+ *
+ * $Id: TRFMath_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class TRFMath_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of TRFMath_t */
+    public void testTRFMath()
+    {
+        String ok_prefix = "TRFMath (I): ";
+        String error_prefix = "TRFMath test (E): ";
+        
+        if(debug) System.out.println("-------- Testing component TRFMath. --------" );
+        
+        //********************************************************************
+        
+        if(debug) System.out.println("Test mathematical constants." );
+        if(debug) System.out.println("   pi: " + Math.PI );
+        if(debug) System.out.println(" 2*pi: " + TRFMath.TWOPI );
+        if(debug) System.out.println(" pi/2: " + TRFMath.PI2 );
+        Assert.assertTrue( TRFMath.TWOPI == 2.0*Math.PI );
+        Assert.assertTrue( TRFMath.PI2 == 0.5*Math.PI );
+        
+        //********************************************************************
+        
+        if(debug) System.out.println("Test physical constants." );
+        if(debug) System.out.println("c (cm/sec): " + TRFMath.CLIGHT );
+        if(debug) System.out.println("pT/(q*B*Rc): " + TRFMath.BFAC );
+        Assert.assertTrue( TRFMath.CLIGHT > 0.0 );
+        Assert.assertTrue( TRFMath.BFAC > 0.0 );
+        Assert.assertTrue( Math.abs( (TRFMath.CLIGHT - 3.e10) / TRFMath.CLIGHT ) < 0.01 );
+        Assert.assertTrue( Math.abs( (TRFMath.BFAC - 0.003) / TRFMath.BFAC ) < 0.01 );
+        
+        //********************************************************************
+        
+        if(debug) System.out.println("Test fmod1 and fmod2." );
+        double val[] =  { -2.7, -1.7, -0.7, 0.3,  1.3, 2.3, 200.3 };
+        double val2[] = { -0.7,  0.3, -0.7, 0.3, -0.7, 0.3,   0.3 };
+        double range1 = 1.0;
+        double range2 = 2.0;
+        double maxdiff = 1.e-10;
+        for ( int i=0; i<7; ++i )
+        {
+            double x1 = TRFMath.fmod1( val[i], range1 );
+            double x2 = TRFMath.fmod2( val[i], range2 );
+            if(debug) System.out.println(x1 + ' ' + x2 );
+            Assert.assertTrue( Math.abs(x1-0.3) < maxdiff );
+            Assert.assertTrue( Math.abs(x2-val2[i]) < maxdiff );
+            double x1m = TRFMath.fmod1( val[i], -range1 );
+            double x2m = TRFMath.fmod2( val[i], -range2 );
+            if(debug) System.out.println(x1m + ' ' + x2m );
+            Assert.assertTrue( Math.abs(x1m-x1) < maxdiff );
+            Assert.assertTrue( Math.abs(x2m-x2) < maxdiff );
+            if(debug) System.out.println("----------------" );
+        }
+        
+        //********************************************************************
+        
+        //********************************************************************
+        
+        if(debug) System.out.println("Test asinrat." );
+        {
+            Assert.assertTrue( TRFMath.asinrat(0.0) == 1.0 );
+            double[] vals = {1.e-15, 0.00004, 0.003, 1.0, -.137 };
+            double close = 1.e-12;
+            for ( int i = 0; i<vals.length; ++i)
+            {
+                double x = vals[i];
+                double asx1 = Math.asin(x);
+                double asx2 = TRFMath.asinrat(x)*x;
+                double dif = Math.abs(asx2-asx1);
+                if(debug) System.out.println(x + " " + asx1 + " " + asx2 + " " + dif );
+                Assert.assertTrue( dif < close );
+            }
+            
+            //********************************************************************
+            
+            if(debug) System.out.println("------------- All tests passed. -------------" );
+        }
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
ArraySmearer_t.java added at 1.1
diff -N ArraySmearer_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ArraySmearer_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,87 @@
+package org.lcsim.recon.tracking.trfutil;
+import junit.framework.TestCase;
+public class ArraySmearer_t extends TestCase
+{
+    private boolean debug;
+    public void testArraySmearer()
+    {
+        double[] _pulls = new double[3];
+        double[][] _pulsum = new double[2][3];
+        double[] _pullerr = new double[3];
+        double[][] cov1 =  new double[1][1];
+        // Single variable, should be gaussian smeared...
+        cov1[0][0] = 3.;
+        ArraySmearer as = new ArraySmearer( cov1 );
+        if(debug) System.out.println(as);
+        double[] vec1 = { 1.0 };
+        double[] tmp = new double[1];
+        int nsamples = 1000;
+        for (int k = 0 ; k<nsamples ; ++k )
+        {
+            System.arraycopy(vec1, 0, tmp, 0, 1);
+            as.smear(tmp);
+            for (int i = 0; i<tmp.length ; ++i )
+            {
+                _pulls[i] = vec1[i] - tmp[i];
+                _pulsum[0][i] += _pulls[i];
+                _pulsum[1][i] += _pulls[i]*_pulls[i];
+            }
+        }
+        double fac=1./Math.sqrt((double)(nsamples));
+        for (int i=0; i<vec1.length; ++i)
+        {
+            _pulsum[0][i]=_pulsum[0][i]/(double)nsamples;
+            _pulsum[1][i]=Math.sqrt(_pulsum[1][i]/((double)nsamples)-_pulsum[0][i]*_pulsum[0][i]);
+            _pullerr[i]=fac*_pulsum[1][i];
+            if(debug) System.out.println("Mean: "+_pulsum[0][i]+" +/- "+_pullerr[i]+" sigma= "+_pulsum[1][i]/Math.sqrt(cov1[i][i]));
+        }
+        
+        
+        // 2x2
+        double[][] cov2 =  new double[2][2];
+        // covariance matrix should be square, symmetric
+        // and have positive-definite determinant
+        cov2[0][0] = 4.;
+        cov2[1][1] = 16.;
+        cov2[0][1] = 1.;
+        cov2[1][0] = 1.;
+        ArraySmearer as2 = new ArraySmearer( cov2 );
+        if(debug) System.out.println(as2);
+        double[] vec2 =
+        { 1.0, 1.0 };
+        double[] tmp2 = new double[2];
+        for (int i = 0; i< tmp2.length ; ++i )
+        {
+            _pulls[i] = 0.;
+            _pulsum[0][i] = 0.;
+            _pulsum[1][i] = 0.;
+        }
+        int nsamples2 = 1000;
+        for (int k = 0 ; k<nsamples2 ; ++k )
+        {
+            System.arraycopy(vec2, 0, tmp2, 0, 2);
+            as2.smear(tmp2);
+            
+            for (int i = 0; i<tmp2.length ; ++i )
+            {
+                _pulls[i] = vec2[i] - tmp2[i];
+                _pulsum[0][i] += _pulls[i];
+                _pulsum[1][i] += _pulls[i]*_pulls[i];
+            }
+        }
+        double fac2=1./Math.sqrt((double)(nsamples2));
+        for (int i=0; i<vec2.length; ++i)
+        {
+            if(debug) System.out.println("_pulsum[0]["+i+"]= "+_pulsum[0][i]);
+            _pulsum[0][i]=_pulsum[0][i]/(double)nsamples2;
+            _pulsum[1][i]=Math.sqrt(_pulsum[1][i]/((double)nsamples2)-_pulsum[0][i]*_pulsum[0][i]);
+            _pullerr[i]=fac2*_pulsum[1][i];
+            
+            if(debug) System.out.println("Mean: "+_pulsum[0][i]+" +/- "+_pullerr[i]+" sigma= "+_pulsum[1][i]/Math.sqrt(cov2[i][i]));
+        }
+        
+        //TODO introduce real tests with Assertions
+        
+    }
+}
+

lcsim/test/org/lcsim/recon/tracking/trfutil
RootFindLinear_t.java added at 1.1
diff -N RootFindLinear_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RootFindLinear_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,69 @@
+/*
+ * RootFindLinear_t.java
+ *
+ * Created on July 24, 2007, 11:30 AM
+ *
+ * $Id: RootFindLinear_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class RootFindLinear_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of RootFindLinear_t */
+    public void  testRootFindLinear()
+    {
+        String component = "RootFindLinear";
+        String ok_prefix = component+ " (I): ";
+        String error_prefix = component+ " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "--------------- testing component" + component
+                + ". -------------");
+        //*******************************************
+        if(debug) System.out.println( ok_prefix+" Test constructor");
+        
+        Assert.assertTrue( RootFindSin.OK == 0 );
+        double y0 = 0.345;
+        double x0 = Math.asin(y0);
+        RootFindSin sfind = new RootFindSin(y0);
+        StatusDouble sd = sfind.solve(0.0,0.8);
+        if(debug) System.out.println(sd);
+        double xf = sd.value();
+        double yf = Math.sin(xf);
+        if(debug) System.out.println( "Predict:" + x0 + " " + y0);
+        if(debug) System.out.println( "  Found:" + xf + " " + yf);
+        Assert.assertTrue( sd.status() == RootFindSin.OK );
+        double dif = Math.abs(xf - x0);
+        Assert.assertTrue( dif < 1.e-10 );
+        
+        
+        //*******************************************
+        if(debug) System.out.println( ok_prefix
+                + "-------------------- All tests passed. -------------------");
+        //*******************************************
+    }
+    
+}
+
+class RootFindSin extends RootFindLinear
+{
+    private double _val;
+    
+    public RootFindSin(double val)
+    {
+        _val = val;
+    }
+    
+    public StatusDouble evaluate(double x)
+    {
+        return new StatusDouble(0,Math.sin(x)-_val);
+    }
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
RandomSimulator_t.java added at 1.1
diff -N RandomSimulator_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RandomSimulator_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,119 @@
+/*
+ * RandomSimulator_t.java
+ *
+ * Created on July 24, 2007, 11:35 AM
+ *
+ * $Id: RandomSimulator_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class RandomSimulator_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of RandomSimulator_t */
+    public void testRandomSimulator()
+    {
+        String component = "RandomSimulator";
+        String ok_prefix = component + " (I): ";
+        String error_prefix = component + " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "---------- Testing component " + component
+                + ". ----------" );
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Construct generators and simulator." );
+        double min = 2.0;
+        double max = 5.0;
+        long seed1 = 246813579L;
+        long seed2 = 987654321L;
+        long seed3 = 135724689L;
+        RandomGeneratorTest rgen1 = new RandomGeneratorTest(min,max,seed1);
+        RandomGeneratorTest rgen2 = new RandomGeneratorTest(min,max,seed2);
+        RandomGeneratorTest rgen3 = new RandomGeneratorTest(min,max,seed3);
+        if(debug) System.out.println( "Generators:" );
+        if(debug) System.out.println( rgen1 );
+        if(debug) System.out.println( rgen2 );
+        if(debug) System.out.println( rgen3 );
+        RandomSimulatorTest rsim = new RandomSimulatorTest(rgen1,rgen2,rgen3);
+        if(debug) System.out.println( "Simulator:" );
+        if(debug) System.out.println( rsim );
+        // save initial values
+        List values0 = new ArrayList();
+        values0.add( new Double( rgen1.flat()) );
+        values0.add( new Double( rgen2.flat()) );
+        values0.add( new Double( rgen3.flat()) );
+        List values1 = new ArrayList();
+        values1.add( new Double( rgen1.flat()) );
+        values1.add( new Double( rgen2.flat()) );
+        values1.add( new Double( rgen3.flat()) );
+        int nval = 3;
+        Assert.assertTrue( values0.size() == nval );
+        Assert.assertTrue( values1.size() == nval );
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Construct registry." );
+        RandomRegistry reg = new RandomRegistry();
+        rsim.registerGenerators(reg);
+        int rec = reg.record();
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Check initial generators." );
+        List gens = rsim.generators();
+        Assert.assertTrue( gens.size() == nval );
+        List values = rsim.generate_values();
+        int i;
+        for ( i=0; i<nval; ++i )
+        {
+            if(debug) System.out.println( i + " " + values.get(i) + " " + values0.get(i) );
+            if(debug) System.out.println( rsim );
+            Assert.assertTrue( values.get(i).equals(values0.get(i)) );
+        }
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Check non-initial states." );
+        values = rsim.generate_values();
+        for ( i=0; i<nval; ++i )
+        {
+            if(debug) System.out.println( i + " " + values.get(i) + " " + values0.get(i) + " "
+                    + values1.get(i) );
+            Assert.assertTrue( !values.get(i).equals(values0.get(i)) );
+            Assert.assertTrue( values.get(i).equals(values1.get(i)) );
+        }
+        rsim.generate_values();
+        rsim.generate_values();
+        rsim.generate_values();
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Check reset states." );
+        reg.set(rec);
+        values = rsim.generate_values();
+        for ( i=0; i<nval; ++i )
+        {
+            if(debug) System.out.println( values.get(i) + " " + values0.get(i) );
+            Assert.assertTrue( values.get(i).equals(values0.get(i)) );
+        }
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix
+                + "------------- All tests passed. -------------" );
+        
+        //********************************************************************
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
RandomGenerator_t.java added at 1.1
diff -N RandomGenerator_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ RandomGenerator_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,152 @@
+/*
+ * RandomGenerator_t.java
+ *
+ * Created on July 24, 2007, 11:21 AM
+ *
+ * $Id: RandomGenerator_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class RandomGenerator_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of RandomGenerator_t */
+    public void testRandomGenerator()
+    {
+        String component = "RandomGenerator";
+        String ok_prefix = component + " (I): ";
+        String error_prefix = component + " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "---------- Testing component " + component
+                + ". ----------" );
+        
+        //********************************************************************
+        
+        // Verify that each generated value is different and is in range.
+        if(debug) System.out.println( ok_prefix + "Test default sequence." );
+        double min = 2.0;
+        double max = 5.0;
+        long seed = 246813579L;
+        RandomGeneratorTest rgen = new RandomGeneratorTest(min,max);
+        if(debug) System.out.println( rgen );
+        int ntest = 20;
+        int itest;
+        List values = new ArrayList();
+        Iterator ival;
+        for ( itest=0; itest<ntest; ++itest )
+        {
+            double newval;
+            if ( itest == 4 || itest == 6 || itest == 7 ) newval = rgen.gauss();
+            else newval = rgen.flat();
+            if(debug) System.out.println( newval );
+            for ( ival=values.iterator(); ival.hasNext();)
+            {
+                Assert.assertTrue( newval != ((Double) ival.next()).doubleValue() );
+            }
+            if ( itest != 4 && itest != 6 && itest != 7 )
+            {
+                Assert.assertTrue( newval >= min );
+                Assert.assertTrue( newval <= max );
+            }
+            values.add(new Double(newval));
+        }
+        
+        //********************************************************************
+        
+        // Verify that two generators starting with the same seed give the
+        // same values.
+        if(debug) System.out.println( ok_prefix + "Test sequence with seed." );
+        rgen.setSeed(seed);
+        RandomGeneratorTest rgen2 = new RandomGeneratorTest(min,max,seed);
+        for ( itest=0; itest<ntest; ++itest )
+        {
+            RandomGeneratorTest rgen3 = new RandomGeneratorTest(rgen);
+            
+            double newval;
+            double newval2;
+            double newval3;
+            if ( itest == 4 || itest == 6 || itest == 7 )
+            {
+                newval = rgen.gauss();
+                newval2 = rgen2.gauss();
+                newval3 = rgen3.gauss();
+            }
+            else
+            {
+                newval = rgen.flat();
+                newval2 = rgen2.flat();
+                newval3 = rgen3.flat();
+            }
+            if(debug) System.out.println( newval + " " + newval2 + " " + newval3 );
+            Assert.assertTrue( newval == newval2 );
+        }
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Test copy constructor." );
+        // Note that rgen is not at the beginning of its sequence.
+        // Copying the state should copy the seed and invoke the
+        // appropriate number of calls so the next value will be
+        // the same for both objects.
+        RandomGeneratorTest rgen3 = new RandomGeneratorTest(rgen);
+        for ( itest=0; itest<ntest; ++itest )
+        {
+            double newval;
+            double newval2;
+            if ( itest == 4 || itest == 6 || itest == 7 )
+            {
+                newval = rgen.gauss();
+                newval2 = rgen3.gauss();
+            }
+            else
+            {
+                newval = rgen.flat();
+                newval2 = rgen3.flat();
+            }
+            if(debug) System.out.println( newval + " " + newval2 );
+            Assert.assertTrue( newval == newval2 );
+        }
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix + "Test copying state." );
+        rgen.setSeed(seed);
+        RandomGeneratorTest rgen4 = new RandomGeneratorTest(min,max);
+        rgen4.setState(rgen);
+        for ( itest=0; itest<ntest; ++itest )
+        {
+            double newval;
+            double newval2;
+            if ( itest == 4 || itest == 6 || itest == 7 )
+            {
+                newval = rgen.gauss();
+                newval2 = rgen4.gauss();
+            }
+            else
+            {
+                newval = rgen.flat();
+                newval2 = rgen4.flat();
+            }
+            if(debug) System.out.println( newval + ' ' + newval2 );
+            Assert.assertTrue( newval == newval2 );
+        }
+        
+        //********************************************************************
+        
+        if(debug) System.out.println( ok_prefix
+                + "------------- All tests passed. -------------" );
+        //********************************************************************
+    }
+    
+}

lcsim/test/org/lcsim/recon/tracking/trfutil
StatusDouble_t.java added at 1.1
diff -N StatusDouble_t.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ StatusDouble_t.java	24 Jul 2007 22:03:09 -0000	1.1
@@ -0,0 +1,49 @@
+/*
+ * StatusDouble_t.java
+ *
+ * Created on July 24, 2007, 11:32 AM
+ *
+ * $Id: StatusDouble_t.java,v 1.1 2007/07/24 22:03:09 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfutil;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class StatusDouble_t extends TestCase
+{
+    private boolean debug;
+    /** Creates a new instance of StatusDouble_t */
+    public void testStatusDouble()
+    {
+        String component = "StatusDouble";
+        String ok_prefix = component+ " (I): ";
+        String error_prefix = component+ " test (E): ";
+        
+        if(debug) System.out.println( ok_prefix
+                + "--------------- testing component" + component
+                + ". -------------");
+        //*******************************************
+        if(debug) System.out.println( ok_prefix+" Test constructor");
+        
+        double value = 12;
+        int status = 137;
+        
+        StatusDouble sv = new StatusDouble(status, value);
+        
+        if(debug) System.out.println(sv);
+        
+        Assert.assertTrue(sv.status() == status);
+        Assert.assertTrue(sv.value() == value);
+        
+        //*******************************************
+        if(debug) System.out.println( ok_prefix
+                + "-------------------- All tests passed. -------------------");
+        //*******************************************
+    }
+    
+}
CVSspam 0.2.8