import junit.framework.*;
import java.util.Random;

public class RootApproximatorTest extends TestCase {

    private double[] x;
    private final double DELTA = 0.000001;
    private RootApproximator[] xroots;
    Random generator;
    public final long RANDOM_SEED = 91165;
    public final int CASES = 5;
    public void setUp() {
	generator = new Random(RANDOM_SEED);
	x = new double[CASES];
	xroots = new RootApproximator[CASES];
	x[0] = 0.0;
	x[1] = Numeric.EPSILON;
	x[2] = 2.0;
	x[3] = 10001;
	x[4] = 1/Numeric.EPSILON;
	for (int i=0; i< CASES; i++) {
	    xroots[i] = new RootApproximator(x[i]);
	}
    }

    public static void main(String args[]) {
	junit.textui.TestRunner.run(
		       RootApproximatorTest.class);
    }
    public void testEins() {
	for (int i=0; i < x.length; i++)
	    {
		Assert.assertEquals("Fall "+ i, 
				    Math.pow(x[i],0.5),
				    xroots[i].getRoot(),
				    DELTA);
	    }
    }
    public void testZwei() {
	for (int i=0; i < x.length; i++)
	    {
		Assert.assertEquals("Fall "+ i, 
				    xroots[i].getRoot() * 
				    xroots[i].getRoot(),x[i],
				    DELTA);
	    }
    }
}
