01: import java.util.Random;
02: 
03: /**
04:    This program verifies the computation of square root values
05:    by using an oracle.
06: */
07: public class RootApproximatorHarness6
08: {  
09:    public static void main(String[] args)
10:    {  
11:       final double SAMPLES = 100;
12:       int passcount = 0;
13:       int failcount = 0;
14:       Random generator = new Random();
15:       for (int i = 1; i <= SAMPLES; i++)
16:       {  
17:          // Generate random test value
18: 
19:          double x = 1000 * generator.nextDouble();
20:          RootApproximator r = new RootApproximator(x);
21:          double y = r.getRoot();
22: 
23:          double oracleValue = Math.pow(x, 0.5); 
24: 
25:          // Check that test value approximately equals oracle value
26: 
27:          if (Numeric.approxEqual(y, oracleValue))
28:          {
29:             System.out.print("Test passed: ");
30:             passcount++;
31:          }
32:          else
33:          {
34:             System.out.print("Test failed: ");
35:             failcount++;
36:          }
37:          System.out.println("square root = " + y 
38:                + ", oracle = " + oracleValue);
39:       }
40:       System.out.println("Pass: " + passcount);
41:       System.out.println("Fail: " + failcount);
42:    }
43: }