public double derivative (final double x) {
return 2*x;
}
};
final NewtonSafe newtonsafe = new NewtonSafe();
double root = newtonsafe.solve(f, accuracy, guess, xMin, xMax);
// assertEquals(1.0, root, accuracy);
if (Math.abs(1.0-root)> accuracy) {
fail("expected: 1.0" + " but root is: " + root);
}
// assertEquals(100, newtonsafe.getMaxEvaluations());
if(newtonsafe.getMaxEvaluations() != 100){
fail("expected: 100" + " but was: " + newtonsafe.getMaxEvaluations());
}
root = newtonsafe.solve(f, accuracy, 0.01, 0.1);
// assertEquals(1.0, root, accuracy);
if (Math.abs(1.0-root)> accuracy) {
fail("expected: 1.0" + " but root is: " + root);
}
//assertEquals(10, newtonsafe.getNumEvaluations());
if(newtonsafe.getNumEvaluations() != 10){
fail("expected: 10" + " but was: " + newtonsafe.getNumEvaluations());
}
}