improved test coverage

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@592093 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2007-11-05 17:11:29 +00:00
parent 8d7e160b5a
commit e21865e806
2 changed files with 80 additions and 30 deletions

View File

@ -445,6 +445,24 @@ public class GaussNewtonEstimatorTest
}
public void testMaxIterations() {
Circle circle = new Circle(98.680, 47.345);
circle.addPoint( 30.0, 68.0);
circle.addPoint( 50.0, -6.0);
circle.addPoint(110.0, -20.0);
circle.addPoint( 35.0, 15.0);
circle.addPoint( 45.0, 97.0);
try {
GaussNewtonEstimator estimator = new GaussNewtonEstimator(4, 1.0e-14, 1.0e-14);
estimator.estimate(circle);
fail("an exception should have been caught");
} catch (EstimationException ee) {
// expected behavior
} catch (Exception e) {
fail("wrong exception type caught");
}
}
public void testCircleFitting() throws EstimationException {
Circle circle = new Circle(98.680, 47.345);
circle.addPoint( 30.0, 68.0);

View File

@ -446,6 +446,38 @@ public class LevenbergMarquardtEstimatorTest
}
public void testControlParameters() throws EstimationException {
Circle circle = new Circle(98.680, 47.345);
circle.addPoint( 30.0, 68.0);
circle.addPoint( 50.0, -6.0);
circle.addPoint(110.0, -20.0);
circle.addPoint( 35.0, 15.0);
circle.addPoint( 45.0, 97.0);
checkEstimate(circle, 100.0, 1000, 1.0e-10, 1.0e-10, 1.0e-10, false);
checkEstimate(circle, 1.0e-12, 10, 1.0e-20, 1.0e-20, 1.0e-20, true);
}
private void checkEstimate(EstimationProblem problem,
double initialStepBoundFactor, int maxCostEval,
double costRelativeTolerance, double parRelativeTolerance,
double orthoTolerance, boolean shouldFail) {
try {
LevenbergMarquardtEstimator estimator = new LevenbergMarquardtEstimator();
estimator.setInitialStepBoundFactor(initialStepBoundFactor);
estimator.setMaxCostEval(maxCostEval);
estimator.setCostRelativeTolerance(costRelativeTolerance);
estimator.setParRelativeTolerance(parRelativeTolerance);
estimator.setOrthoTolerance(orthoTolerance);
estimator.estimate(problem);
assertTrue(! shouldFail);
} catch (EstimationException ee) {
System.out.println(ee.getClass().getName() + " " + ee.getMessage());
assertTrue(shouldFail);
} catch (Exception e) {
fail("wrong exception type caught");
}
}
public void testCircleFitting() throws EstimationException {
Circle circle = new Circle(98.680, 47.345);
circle.addPoint( 30.0, 68.0);