1 /* 2 * RootFindLinear_Test.java 3 * 4 * Created on July 24, 2007, 11:30 AM 5 * 6 * $Id: RootFindLinear_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $ 7 */ 8 9 package org.lcsim.recon.tracking.trfutil; 10 11 import junit.framework.TestCase; 12 13 /** 14 * 15 * @author Norman Graf 16 */ 17 public class RootFindLinear_Test extends TestCase 18 { 19 private boolean debug; 20 /** Creates a new instance of RootFindLinear_Test */ 21 public void testRootFindLinear() 22 { 23 String component = "RootFindLinear"; 24 String ok_prefix = component+ " (I): "; 25 String error_prefix = component+ " test (E): "; 26 27 if(debug) System.out.println( ok_prefix 28 + "--------------- testing component" + component 29 + ". -------------"); 30 //******************************************* 31 if(debug) System.out.println( ok_prefix+" Test constructor"); 32 33 Assert.assertTrue( RootFindSin.OK == 0 ); 34 double y0 = 0.345; 35 double x0 = Math.asin(y0); 36 RootFindSin sfind = new RootFindSin(y0); 37 StatusDouble sd = sfind.solve(0.0,0.8); 38 if(debug) System.out.println(sd); 39 double xf = sd.value(); 40 double yf = Math.sin(xf); 41 if(debug) System.out.println( "Predict:" + x0 + " " + y0); 42 if(debug) System.out.println( " Found:" + xf + " " + yf); 43 Assert.assertTrue( sd.status() == RootFindSin.OK ); 44 double dif = Math.abs(xf - x0); 45 Assert.assertTrue( dif < 1.e-10 ); 46 47 48 //******************************************* 49 if(debug) System.out.println( ok_prefix 50 + "-------------------- All tests passed. -------------------"); 51 //******************************************* 52 } 53 54 static class RootFindSin extends RootFindLinear 55 { 56 private double _val; 57 58 public RootFindSin(double val) 59 { 60 _val = val; 61 } 62 63 public StatusDouble evaluate(double x) 64 { 65 return new StatusDouble(0,Math.sin(x)-_val); 66 } 67 } 68 } 69 70