Commit in lcsim/test/org/lcsim/fit/threepointcircle on MAIN
ThreePointCircleFitterTest.java+52added 1.1
Test for ThreePointCircleFitter.

lcsim/test/org/lcsim/fit/threepointcircle
ThreePointCircleFitterTest.java added at 1.1
diff -N ThreePointCircleFitterTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ThreePointCircleFitterTest.java	24 Mar 2006 02:49:21 -0000	1.1
@@ -0,0 +1,52 @@
+/*
+ * ThreePointCircleFitterTest.java
+ *
+ * Created on March 23, 2006, 4:13 PM
+ *
+ *
+ */
+
+package org.lcsim.fit.threepointcircle;
+
+import java.util.Random;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class ThreePointCircleFitterTest extends TestCase
+{
+    
+    public void testThreePointCircleFitter()
+    {
+        ThreePointCircleFitter fitter = new ThreePointCircleFitter();
+        double epsilon = .01;
+        Random r = new Random();
+        // generate a set of random circles
+        double xmax = 200.;
+        double ymax = 200.;
+        double rmax = 100.;
+        for(int i=0; i<1000; ++i)
+        {
+            double xc = r.nextDouble()*xmax;
+            double yc = r.nextDouble()*ymax;
+            double rc = r.nextDouble()*rmax;
+            boolean success = fitter.fit(nextPoint(xc, yc, rc),nextPoint(xc, yc, rc),nextPoint(xc, yc, rc));
+            assertTrue(success);
+            CircleFit fit = fitter.getFit();
+            assertEquals(fit.x0(), xc, epsilon);
+            assertEquals(fit.y0(), yc, epsilon);
+            assertEquals(fit.radius(), rc, epsilon);
+        }
+    }
+    private double[] nextPoint( double xc, double yc, double rc)
+    {
+        Random r = new Random();
+        double[] p = new double[2];
+        double phi = r.nextDouble()*2.*Math.PI;
+        p[0] = rc*Math.cos(phi)+xc;
+        p[1] = rc*Math.sin(phi)+yc;
+        return p;
+    }
+}
CVSspam 0.2.8