commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1039083 [3/4] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/ main/java/org/apache/commons/math/analysis/polynomials/ main/java/org/apache/commons/math/analysis/solvers/ main/java/org/apache/commons/math/di...
Date Thu, 25 Nov 2010 16:22:01 GMT
Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original)
+++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Thu Nov 25 16:22:00 2010
@@ -70,7 +70,7 @@ EVALUATION_FAILED = erreur d''\u00e9valu
 EVALUATION = \u00e9valuation
 EXPANSION_FACTOR_SMALLER_THAN_ONE = facteur d''extension inf\u00e9rieur \u00e0 un ({0})
 FACTORIAL_NEGATIVE_PARAMETER = n doit \u00eatre positif pour le calcul de n!, or n = {0}
-FAILED_BRACKETING = nombre d''it\u00e9rations = {0}, it\u00e9rations maximum = {1}, valeur initiale = {2}, borne inf\u00e9rieure = {3}, borne sup\u00e9rieure = {4}, valeur a finale = {5}, valeur b finale = {6}, f(a) = {7}, f(b) = {8}
+FAILED_BRACKETING = nombre d''it\u00e9rations = {4}, it\u00e9rations maximum = {5}, valeur initiale = {6}, borne inf\u00e9rieure = {7}, borne sup\u00e9rieure = {8}, valeur a finale = {0}, valeur b finale = {1}, f(a) = {2}, f(b) = {3}
 FAILED_FRACTION_CONVERSION = Impossible de convertir {0} en fraction apr\u00e8s {1} it\u00e9rations
 FIRST_COLUMNS_NOT_INITIALIZED_YET = les {0} premi\u00e8res colonnes ne sont pas encore initialis\u00e9es
 FIRST_ELEMENT_NOT_ZERO = le premier \u00e9l\u00e9ment n''est pas nul : {0}
@@ -235,6 +235,7 @@ OVERFLOW_IN_SUBTRACTION = d\u00e9passeme
 PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD = acc\u00e8s impossible \u00e0 la m\u00e9thode {0}
 PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD = l''implantation de pourcentage {0} ne dispose pas de la m\u00e9thode {1}
 PERMUTATION_EXCEEDS_N = la taille de la permutation ({0}) d\u00e9passe le domaine de la permutation ({1})
+POLYNOMIAL = polyn\u00f4me
 POLYNOMIAL_INTERPOLANTS_MISMATCH_SEGMENTS = le nombre d''interpolants polyn\u00f4miaux doit correspondre au nombre de segments ({0} != {1} - 1)
 POPULATION_LIMIT_NOT_POSITIVE = la limite de population doit \u00eatre positive
 POSITION_SIZE_MISMATCH_INPUT_ARRAY = la position {0} et la taille {1} sont incompatibles avec la taille du tableau d''entr\u00e9e {2}

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java Thu Nov 25 16:22:00 2010
@@ -16,166 +16,90 @@
  */
 package org.apache.commons.math.analysis.solvers;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.util.FastMath;
-
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
  * @version $Revision$ $Date$
  */
-public final class BisectionSolverTest extends TestCase {
-
-    public void testSinZero() throws MathException {
+public final class BisectionSolverTest {
+    @Test
+    public void testSinZero() {
         UnivariateRealFunction f = new SinFunction();
         double result;
 
-        UnivariateRealSolver solver = new BisectionSolver();
+        BisectionSolver solver = new BisectionSolver();
+        solver.setMaxEvaluations(50);
         result = solver.solve(f, 3, 4);
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 1, 4);
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
     }
 
-   public void testQuinticZero() throws MathException {
+    @Test
+    public void testQuinticZero() {
         UnivariateRealFunction f = new QuinticFunction();
         double result;
 
-        UnivariateRealSolver solver = new BisectionSolver();
+        BisectionSolver solver = new BisectionSolver();
+        solver.setMaxEvaluations(50);
         result = solver.solve(f, -0.2, 0.2);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, -0.1, 0.3);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, -0.3, 0.45);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.3, 0.7);
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.2, 0.6);
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.05, 0.95);
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.85, 1.25);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.8, 1.2);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.85, 1.75);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.55, 1.45);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.85, 5);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
-        assertEquals(result, solver.getResult(), 0);
-        assertTrue(solver.getIterationCount() > 0);
+        Assert.assertTrue(solver.getEvaluations() > 0);
     }
 
+    @Test
     public void testMath369() throws Exception {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new BisectionSolver();
-        assertEquals(FastMath.PI, solver.solve(f, 3.0, 3.2, 3.1), solver.getAbsoluteAccuracy());
-    }
-
-    /**
-     *
-     */
-    public void testSetFunctionValueAccuracy(){
-        double expected = 1.0e-2;
-        UnivariateRealSolver solver = new BisectionSolver();
-        solver.setFunctionValueAccuracy(expected);
-        assertEquals(expected, solver.getFunctionValueAccuracy(), 1.0e-2);
-    }
-
-    /**
-     *
-     */
-    public void testResetFunctionValueAccuracy(){
-        double newValue = 1.0e-2;
-        UnivariateRealSolver solver = new BisectionSolver();
-        double oldValue = solver.getFunctionValueAccuracy();
-        solver.setFunctionValueAccuracy(newValue);
-        solver.resetFunctionValueAccuracy();
-        assertEquals(oldValue, solver.getFunctionValueAccuracy(), 1.0e-2);
-    }
-
-    /**
-     *
-     */
-    public void testSetAbsoluteAccuracy(){
-        double expected = 1.0e-2;
-        UnivariateRealSolver solver = new BisectionSolver();
-        solver.setAbsoluteAccuracy(expected);
-        assertEquals(expected, solver.getAbsoluteAccuracy(), 1.0e-2);
+        BisectionSolver solver = new BisectionSolver();
+        solver.setMaxEvaluations(40);
+        Assert.assertEquals(FastMath.PI, solver.solve(f, 3.0, 3.2, 3.1), solver.getAbsoluteAccuracy());
     }
 
     /**
      *
      */
-    public void testResetAbsoluteAccuracy(){
-        double newValue = 1.0e-2;
-        UnivariateRealSolver solver = new BisectionSolver();
-        double oldValue = solver.getAbsoluteAccuracy();
-        solver.setAbsoluteAccuracy(newValue);
-        solver.resetAbsoluteAccuracy();
-        assertEquals(oldValue, solver.getAbsoluteAccuracy(), 1.0e-2);
-    }
-
-    /**
-     *
-     */
-    public void testSetMaximalIterationCount(){
+    @Test
+    public void testSetMaximalEvaluationCount(){
         int expected = 100;
-        UnivariateRealSolver solver = new BisectionSolver();
-        solver.setMaximalIterationCount(expected);
-        assertEquals(expected, solver.getMaximalIterationCount());
-    }
-
-    /**
-     *
-     */
-    public void testResetMaximalIterationCount(){
-        int newValue = 10000;
-        UnivariateRealSolver solver = new BisectionSolver();
-        int oldValue = solver.getMaximalIterationCount();
-        solver.setMaximalIterationCount(newValue);
-        solver.resetMaximalIterationCount();
-        assertEquals(oldValue, solver.getMaximalIterationCount());
+        BisectionSolver solver = new BisectionSolver();
+        solver.setMaxEvaluations(expected);
+        Assert.assertEquals(expected, solver.getMaxEvaluations());
     }
-
-    /**
-     *
-     */
-    public void testSetRelativeAccuracy(){
-        double expected = 1.0e-2;
-        UnivariateRealSolver solver = new BisectionSolver();
-        solver.setRelativeAccuracy(expected);
-        assertEquals(expected, solver.getRelativeAccuracy(), 1.0e-2);
-    }
-
-    /**
-     *
-     */
-    public void testResetRelativeAccuracy(){
-        double newValue = 1.0e-2;
-        UnivariateRealSolver solver = new BisectionSolver();
-        double oldValue = solver.getRelativeAccuracy();
-        solver.setRelativeAccuracy(newValue);
-        solver.resetRelativeAccuracy();
-        assertEquals(oldValue, solver.getRelativeAccuracy(), 1.0e-2);
-    }
-
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java Thu Nov 25 16:22:00 2010
@@ -16,17 +16,16 @@
  */
 package org.apache.commons.math.analysis.solvers;
 
-import junit.framework.TestCase;
-
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.MonitoredFunction;
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
- * Testcase for UnivariateRealSolver.
+ * Testcase for {@link BrentSolver Brent} solver.
  * Because Brent-Dekker is guaranteed to converge in less than the default
  * maximum iteration count due to bisection fallback, it is quite hard to
  * debug. I include measured iteration counts plus one in order to detect
@@ -36,50 +35,32 @@ import org.apache.commons.math.util.Fast
  *
  * @version $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $
  */
-public final class BrentSolverTest extends TestCase {
-
-    public BrentSolverTest(String name) {
-        super(name);
-    }
-
-    public void testSinZero() throws MathException {
-        // The sinus function is behaved well around the root at #pi. The second
+public final class BrentSolverTest {
+    @Test
+    public void testSinZero() {
+        // The sinus function is behaved well around the root at pi. The second
         // order derivative is zero, which means linar approximating methods will
         // still converge quadratically.
         UnivariateRealFunction f = new SinFunction();
         double result;
         UnivariateRealSolver solver = new BrentSolver();
+        solver.setMaxEvaluations(10);
         // Somewhat benign interval. The function is monotone.
         result = solver.solve(f, 3, 4);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
-        // 4 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 5);
+        // System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 7);
         // Larger and somewhat less benign interval. The function is grows first.
         result = solver.solve(f, 1, 4);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
-        // 5 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 6);
-        solver = new SecantSolver();
-        result = solver.solve(f, 3, 4);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
-        // 4 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 5);
-        result = solver.solve(f, 1, 4);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
-        // 5 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 6);
-        assertEquals(result, solver.getResult(), 0);
+        // System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 8);
     }
 
-   public void testQuinticZero() throws MathException {
+    @Test
+    public void testQuinticZero() {
         // The quintic function has zeros at 0, +-0.5 and +-1.
         // Around the root of 0 the function is well behaved, with a second derivative
         // of zero a 0.
@@ -91,238 +72,144 @@ public final class BrentSolverTest exten
         double result;
         // Brent-Dekker solver.
         UnivariateRealSolver solver = new BrentSolver();
+        solver.setMaxEvaluations(20);
         // Symmetric bracket around 0. Test whether solvers can handle hitting
         // the root in the first iteration.
         result = solver.solve(f, -0.2, 0.2);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        assertTrue(solver.getIterationCount() <= 2);
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 3);
         // 1 iterations on i586 JDK 1.4.1.
         // Asymmetric bracket around 0, just for fun. Contains extremum.
         result = solver.solve(f, -0.1, 0.3);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
         // 5 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 6);
+        Assert.assertTrue(solver.getEvaluations() <= 7);
         // Large bracket around 0. Contains two extrema.
         result = solver.solve(f, -0.3, 0.45);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
         // 6 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 7);
+        Assert.assertTrue(solver.getEvaluations() <= 8);
         // Benign bracket around 0.5, function is monotonous.
         result = solver.solve(f, 0.3, 0.7);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
         // 6 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 7);
+        Assert.assertTrue(solver.getEvaluations() <= 9);
         // Less benign bracket around 0.5, contains one extremum.
         result = solver.solve(f, 0.2, 0.6);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        // 6 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 7);
+        // System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 10);
         // Large, less benign bracket around 0.5, contains both extrema.
         result = solver.solve(f, 0.05, 0.95);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        // 8 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 9);
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 11);
         // Relatively benign bracket around 1, function is monotonous. Fast growth for x>1
         // is still a problem.
         result = solver.solve(f, 0.85, 1.25);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 8 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 9);
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 11);
         // Less benign bracket around 1 with extremum.
         result = solver.solve(f, 0.8, 1.2);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 8 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 9);
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 11);
         // Large bracket around 1. Monotonous.
         result = solver.solve(f, 0.85, 1.75);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 10 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 11);
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 13);
         // Large bracket around 1. Interval contains extremum.
         result = solver.solve(f, 0.55, 1.45);
         //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 7 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 8);
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 10);
         // Very large bracket around 1 for testing fast growth behaviour.
         result = solver.solve(f, 0.85, 5);
         //System.out.println(
-       //     "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 12 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 13);
-        // Secant solver.
-        solver = new SecantSolver();
-        result = solver.solve(f, -0.2, 0.2);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        // 1 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 2);
-        result = solver.solve(f, -0.1, 0.3);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        // 5 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 6);
-        result = solver.solve(f, -0.3, 0.45);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        // 6 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 7);
-        result = solver.solve(f, 0.3, 0.7);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        // 7 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 8);
-        result = solver.solve(f, 0.2, 0.6);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        // 6 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 7);
-        result = solver.solve(f, 0.05, 0.95);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        // 8 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 9);
-        result = solver.solve(f, 0.85, 1.25);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 10 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 11);
-        result = solver.solve(f, 0.8, 1.2);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 8 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 9);
-        result = solver.solve(f, 0.85, 1.75);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 14 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 15);
-        // The followig is especially slow because the solver first has to reduce
-        // the bracket to exclude the extremum. After that, convergence is rapide.
-        result = solver.solve(f, 0.55, 1.45);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 7 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 8);
-        result = solver.solve(f, 0.85, 5);
-        //System.out.println(
-        //    "Root: " + result + " Iterations: " + solver.getIterationCount());
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        // 14 iterations on i586 JDK 1.4.1.
-        assertTrue(solver.getIterationCount() <= 15);
-        // Static solve method
-        result = UnivariateRealSolverUtils.solve(f, -0.2, 0.2);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        result = UnivariateRealSolverUtils.solve(f, -0.1, 0.3);
-        assertEquals(result, 0, 1E-8);
-        result = UnivariateRealSolverUtils.solve(f, -0.3, 0.45);
-        assertEquals(result, 0, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.3, 0.7);
-        assertEquals(result, 0.5, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.2, 0.6);
-        assertEquals(result, 0.5, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.05, 0.95);
-        assertEquals(result, 0.5, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.85, 1.25);
-        assertEquals(result, 1.0, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.8, 1.2);
-        assertEquals(result, 1.0, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.85, 1.75);
-        assertEquals(result, 1.0, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.55, 1.45);
-        assertEquals(result, 1.0, 1E-6);
-        result = UnivariateRealSolverUtils.solve(f, 0.85, 5);
-        assertEquals(result, 1.0, 1E-6);
+       //     "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 15);
     }
 
-    public void testRootEndpoints() throws Exception {
+    @Test
+    public void testRootEndpoints() {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new BrentSolver();
+        BrentSolver solver = new BrentSolver();
+        solver.setMaxEvaluations(10);
 
         // endpoint is root
         double result = solver.solve(f, FastMath.PI, 4);
-        assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 3, FastMath.PI);
-        assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, FastMath.PI, 4, 3.5);
-        assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 3, FastMath.PI, 3.07);
-        assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
 
     }
 
-    public void testBadEndpoints() throws Exception {
+    @Test
+    public void testBadEndpoints() {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new BrentSolver();
+        BrentSolver solver = new BrentSolver();
+        solver.setMaxEvaluations(10);
         try {  // bad interval
             solver.solve(f, 1, -1);
-            fail("Expecting IllegalArgumentException - bad interval");
+            Assert.fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {  // no bracket
             solver.solve(f, 1, 1.5);
-            fail("Expecting IllegalArgumentException - non-bracketing");
+            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {  // no bracket
             solver.solve(f, 1, 1.5, 1.2);
-            fail("Expecting IllegalArgumentException - non-bracketing");
+            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testInitialGuess() throws MathException {
-
+    @Test
+    public void testInitialGuess() {
         MonitoredFunction f = new MonitoredFunction(new QuinticFunction());
-        UnivariateRealSolver solver = new BrentSolver();
+        BrentSolver solver = new BrentSolver();
+        solver.setMaxEvaluations(20);
         double result;
 
         // no guess
         result = solver.solve(f, 0.6, 7.0);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
         int referenceCallsCount = f.getCallsCount();
-        assertTrue(referenceCallsCount >= 13);
+        Assert.assertTrue(referenceCallsCount >= 13);
 
         // invalid guess (it *is* a root, but outside of the range)
         try {
           result = solver.solve(f, 0.6, 7.0, 0.0);
-          fail("an IllegalArgumentException was expected");
+          Assert.fail("an IllegalArgumentException was expected");
         } catch (IllegalArgumentException iae) {
             // expected behaviour
         }
@@ -330,22 +217,20 @@ public final class BrentSolverTest exten
         // bad guess
         f.setCallsCount(0);
         result = solver.solve(f, 0.6, 7.0, 0.61);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertTrue(f.getCallsCount() > referenceCallsCount);
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(f.getCallsCount() > referenceCallsCount);
 
         // good guess
         f.setCallsCount(0);
         result = solver.solve(f, 0.6, 7.0, 0.999999);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertTrue(f.getCallsCount() < referenceCallsCount);
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(f.getCallsCount() < referenceCallsCount);
 
         // perfect guess
         f.setCallsCount(0);
         result = solver.solve(f, 0.6, 7.0, 1.0);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertEquals(0, solver.getIterationCount());
-        assertEquals(1, f.getCallsCount());
-
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(1, solver.getEvaluations());
+        Assert.assertEquals(1, f.getCallsCount());
     }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java Thu Nov 25 16:22:00 2010
@@ -22,8 +22,9 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
 import org.apache.commons.math.complex.Complex;
 import org.apache.commons.math.util.FastMath;
-
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Ignore;
 
 /**
  * Testcase for Laguerre solver.
@@ -35,144 +36,145 @@ import junit.framework.TestCase;
  *
  * @version $Revision$ $Date$
  */
-public final class LaguerreSolverTest extends TestCase {
-
+public final class LaguerreSolverTest {
     /**
      * Test of solver for the linear function.
      */
-    public void testLinearFunction() throws MathException {
+    @Test
+    public void testLinearFunction() {
         double min, max, expected, result, tolerance;
 
         // p(x) = 4x - 1
         double coefficients[] = { -1.0, 4.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver();
+        LaguerreSolver solver = new LaguerreSolver();
+        solver.setMaxEvaluations(10);
 
         min = 0.0; max = 1.0; expected = 0.25;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of solver for the quadratic function.
      */
-    public void testQuadraticFunction() throws MathException {
+    @Test
+    public void testQuadraticFunction() {
         double min, max, expected, result, tolerance;
 
         // p(x) = 2x^2 + 5x - 3 = (x+3)(2x-1)
         double coefficients[] = { -3.0, 5.0, 2.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver();
+        LaguerreSolver solver = new LaguerreSolver();
+        solver.setMaxEvaluations(10);
 
         min = 0.0; max = 2.0; expected = 0.5;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -4.0; max = -1.0; expected = -3.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of solver for the quintic function.
      */
-    public void testQuinticFunction() throws MathException {
+    @Test
+    public void testQuinticFunction() {
         double min, max, expected, result, tolerance;
 
         // p(x) = x^5 - x^4 - 12x^3 + x^2 - x - 12 = (x+1)(x+3)(x-4)(x^2-x+1)
         double coefficients[] = { -12.0, -1.0, 1.0, -12.0, -1.0, 1.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver();
+        LaguerreSolver solver = new LaguerreSolver();
+        solver.setMaxEvaluations(10);
 
         min = -2.0; max = 2.0; expected = -1.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -5.0; max = -2.5; expected = -3.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = 3.0; max = 6.0; expected = 4.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of solver for the quintic function using solveAll().
+     * XXX commented out because "solveAll" is not part of the API.
      */
-    public void testQuinticFunction2() throws MathException {
-        double initial = 0.0, tolerance;
-        Complex expected, result[];
-
-        // p(x) = x^5 + 4x^3 + x^2 + 4 = (x+1)(x^2-x+1)(x^2+4)
-        double coefficients[] = { 4.0, 0.0, 1.0, 4.0, 0.0, 1.0 };
-        LaguerreSolver solver = new LaguerreSolver();
-        result = solver.solveAll(coefficients, initial);
-
-        expected = new Complex(0.0, -2.0);
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(0.0, 2.0);
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(0.5, 0.5 * FastMath.sqrt(3.0));
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(-1.0, 0.0);
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(0.5, -0.5 * FastMath.sqrt(3.0));
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-    }
+    // public void testQuinticFunction2() {
+    //     double initial = 0.0, tolerance;
+    //     Complex expected, result[];
+
+    //     // p(x) = x^5 + 4x^3 + x^2 + 4 = (x+1)(x^2-x+1)(x^2+4)
+    //     double coefficients[] = { 4.0, 0.0, 1.0, 4.0, 0.0, 1.0 };
+    //     LaguerreSolver solver = new LaguerreSolver();
+    //     result = solver.solveAll(coefficients, initial);
+
+    //     expected = new Complex(0.0, -2.0);
+    //     tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+    //                 FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
+    //     TestUtils.assertContains(result, expected, tolerance);
+
+    //     expected = new Complex(0.0, 2.0);
+    //     tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+    //                 FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
+    //     TestUtils.assertContains(result, expected, tolerance);
+
+    //     expected = new Complex(0.5, 0.5 * FastMath.sqrt(3.0));
+    //     tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+    //                 FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
+    //     TestUtils.assertContains(result, expected, tolerance);
+
+    //     expected = new Complex(-1.0, 0.0);
+    //     tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+    //                 FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
+    //     TestUtils.assertContains(result, expected, tolerance);
+
+    //     expected = new Complex(0.5, -0.5 * FastMath.sqrt(3.0));
+    //     tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+    //                 FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
+    //     TestUtils.assertContains(result, expected, tolerance);
+    // }
 
     /**
      * Test of parameters for the solver.
      */
-    public void testParameters() throws Exception {
+    @Test
+    public void testParameters() {
         double coefficients[] = { -3.0, 5.0, 2.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver();
+        LaguerreSolver solver = new LaguerreSolver();
+        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
             solver.solve(f, 1, -1);
-            fail("Expecting IllegalArgumentException - bad interval");
+            Assert.fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            fail("Expecting IllegalArgumentException - no bracketing");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            // bad function
-            solver.solve(new SinFunction(), -1, 1);
-            fail("Expecting IllegalArgumentException - bad function");
+            Assert.fail("Expecting IllegalArgumentException - no bracketing");
         } catch (IllegalArgumentException ex) {
             // expected
         }

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java?rev=1039083&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java Thu Nov 25 16:22:00 2010
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis.solvers;
+
+import org.apache.commons.math.analysis.Expm1Function;
+import org.apache.commons.math.analysis.QuinticFunction;
+import org.apache.commons.math.analysis.SinFunction;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NoBracketingException;
+import org.apache.commons.math.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Testcase for {@link MullerSolver2 Muller} solver.
+ * <p>
+ * Muller's method converges almost quadratically near roots, but it can
+ * be very slow in regions far away from zeros. Test runs show that for
+ * reasonably good initial values, for a default absolute accuracy of 1E-6,
+ * it generally takes 5 to 10 iterations for the solver to converge.
+ * <p>
+ * Tests for the exponential function illustrate the situations where
+ * Muller solver performs poorly.
+ *
+ * @version $Revision: 1034896 $ $Date: 2010-11-13 23:27:34 +0100 (Sat, 13 Nov 2010) $
+ */
+public final class MullerSolver2Test {
+    /**
+     * Test of solver for the sine function.
+     */
+    @Test
+    public void testSinFunction() {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new MullerSolver2();
+        solver.setMaxEvaluations(10);
+        double min, max, expected, result, tolerance;
+
+        min = 3.0; max = 4.0; expected = FastMath.PI;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+
+        min = -1.0; max = 1.5; expected = 0.0;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the quintic function.
+     */
+    @Test
+    public void testQuinticFunction() {
+        UnivariateRealFunction f = new QuinticFunction();
+        UnivariateRealSolver solver = new MullerSolver2();
+        solver.setMaxEvaluations(10);
+        double min, max, expected, result, tolerance;
+
+        min = -0.4; max = 0.2; expected = 0.0;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+
+        min = 0.75; max = 1.5; expected = 1.0;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+
+        min = -0.9; max = -0.2; expected = -0.5;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the exponential function.
+     * <p>
+     * It takes 25 to 50 iterations for the last two tests to converge.
+     */
+    @Test
+    public void testExpm1Function() {
+        UnivariateRealFunction f = new Expm1Function();
+        UnivariateRealSolver solver = new MullerSolver2();
+        solver.setMaxEvaluations(55);
+        double min, max, expected, result, tolerance;
+
+        min = -1.0; max = 2.0; expected = 0.0;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+
+        min = -20.0; max = 10.0; expected = 0.0;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+
+        min = -50.0; max = 100.0; expected = 0.0;
+        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+                    FastMath.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        Assert.assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of parameters for the solver.
+     */
+    @Test
+    public void testParameters() throws Exception {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new MullerSolver2();
+        solver.setMaxEvaluations(10);
+
+        try {
+            // bad interval
+            solver.solve(f, 1, -1);
+            Assert.fail("Expecting IllegalArgumentException - bad interval");
+        } catch (NumberIsTooLargeException ex) {
+            // expected
+        }
+        try {
+            // no bracketing
+            solver.solve(f, 2, 3);
+            Assert.fail("Expecting IllegalArgumentException - no bracketing");
+        } catch (NoBracketingException ex) {
+            // expected
+        }
+    }
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java Thu Nov 25 16:22:00 2010
@@ -16,17 +16,18 @@
  */
 package org.apache.commons.math.analysis.solvers;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.Expm1Function;
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NoBracketingException;
 import org.apache.commons.math.util.FastMath;
-
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
- * Testcase for Muller solver.
+ * Testcase for {@link MullerSolver Muller} solver.
  * <p>
  * Muller's method converges almost quadratically near roots, but it can
  * be very slow in regions far away from zeros. Test runs show that for
@@ -38,102 +39,57 @@ import junit.framework.TestCase;
  *
  * @version $Revision$ $Date$
  */
-public final class MullerSolverTest extends TestCase {
-
+public final class MullerSolverTest {
     /**
      * Test of solver for the sine function.
      */
-    public void testSinFunction() throws MathException {
+    @Test
+    public void testSinFunction() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver();
+        solver.setMaxEvaluations(10);
         double min, max, expected, result, tolerance;
 
         min = 3.0; max = 4.0; expected = FastMath.PI;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -1.0; max = 1.5; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the sine function using solve2().
-     */
-    public void testSinFunction2() throws MathException {
-        UnivariateRealFunction f = new SinFunction();
-        MullerSolver solver = new MullerSolver();
-        double min, max, expected, result, tolerance;
-
-        min = 3.0; max = 4.0; expected = FastMath.PI;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -1.0; max = 1.5; expected = 0.0;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of solver for the quintic function.
      */
-    public void testQuinticFunction() throws MathException {
+    @Test
+    public void testQuinticFunction() {
         UnivariateRealFunction f = new QuinticFunction();
         UnivariateRealSolver solver = new MullerSolver();
+        solver.setMaxEvaluations(15);
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = 0.75; max = 1.5; expected = 1.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -0.9; max = -0.2; expected = -0.5;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the quintic function using solve2().
-     */
-    public void testQuinticFunction2() throws MathException {
-        UnivariateRealFunction f = new QuinticFunction();
-        MullerSolver solver = new MullerSolver();
-        double min, max, expected, result, tolerance;
-
-        min = -0.4; max = 0.2; expected = 0.0;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = 0.75; max = 1.5; expected = 1.0;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -0.9; max = -0.2; expected = -0.5;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
@@ -143,78 +99,54 @@ public final class MullerSolverTest exte
      * In fact, if not for the bisection alternative, the solver would
      * exceed the default maximal iteration of 100.
      */
-    public void testExpm1Function() throws MathException {
+    @Test
+    public void testExpm1Function() {
         UnivariateRealFunction f = new Expm1Function();
         UnivariateRealSolver solver = new MullerSolver();
+        solver.setMaxEvaluations(25);
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -20.0; max = 10.0; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -50.0; max = 100.0; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the exponential function using solve2().
-     * <p>
-     * It takes 25 to 50 iterations for the last two tests to converge.
-     */
-    public void testExpm1Function2() throws MathException {
-        UnivariateRealFunction f = new Expm1Function();
-        MullerSolver solver = new MullerSolver();
-        double min, max, expected, result, tolerance;
-
-        min = -1.0; max = 2.0; expected = 0.0;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -20.0; max = 10.0; expected = 0.0;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -50.0; max = 100.0; expected = 0.0;
-        tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
-                    FastMath.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of parameters for the solver.
      */
+    @Test
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver();
+        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
-            solver.solve(f, 1, -1);
-            fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
+            double root = solver.solve(f, 1, -1);
+            System.out.println("root=" + root);
+            Assert.fail("Expecting IllegalArgumentException - bad interval");
+        } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            fail("Expecting IllegalArgumentException - no bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting IllegalArgumentException - no bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java Thu Nov 25 16:22:00 2010
@@ -16,78 +16,78 @@
  */
 package org.apache.commons.math.analysis.solvers;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
 
 
-import junit.framework.TestCase;
-
 /**
  * @version $Revision$ $Date$
  */
-public final class NewtonSolverTest extends TestCase {
-
+public final class NewtonSolverTest {
     /**
      *
      */
-    public void testSinZero() throws MathException {
+    @Test
+    public void testSinZero() {
         DifferentiableUnivariateRealFunction f = new SinFunction();
         double result;
 
-        UnivariateRealSolver solver = new NewtonSolver();
+        NewtonSolver solver = new NewtonSolver();
+        solver.setMaxEvaluations(10);
         result = solver.solve(f, 3, 4);
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 1, 4);
-        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
 
-        assertEquals(result, solver.getResult(), 0);
-        assertTrue(solver.getIterationCount() > 0);
+        Assert.assertTrue(solver.getEvaluations() > 0);
     }
 
     /**
      *
      */
-    public void testQuinticZero() throws MathException {
+    @Test
+    public void testQuinticZero() {
         DifferentiableUnivariateRealFunction f = new QuinticFunction();
         double result;
 
-        UnivariateRealSolver solver = new NewtonSolver();
+        NewtonSolver solver = new NewtonSolver();
+        solver.setMaxEvaluations(30);
         result = solver.solve(f, -0.2, 0.2);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, -0.1, 0.3);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, -0.3, 0.45);
-        assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.3, 0.7);
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.2, 0.6);
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.05, 0.95);
-        assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.85, 1.25);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.8, 1.2);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.85, 1.75);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.55, 1.45);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
         result = solver.solve(f, 0.85, 5);
-        assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
     }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java Thu Nov 25 16:22:00 2010
@@ -16,17 +16,18 @@
  */
 package org.apache.commons.math.analysis.solvers;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.Expm1Function;
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.util.FastMath;
-
-import junit.framework.TestCase;
+import org.apache.commons.math.exception.NoBracketingException;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
- * Testcase for Ridders solver.
+ * Testcase for {@link RiddersSolver Ridders} solver.
  * <p>
  * Ridders' method converges superlinearly, more specific, its rate of
  * convergence is sqrt(2). Test runs show that for a default absolute
@@ -36,102 +37,109 @@ import junit.framework.TestCase;
  *
  * @version $Revision$ $Date$
  */
-public final class RiddersSolverTest extends TestCase {
-
+public final class RiddersSolverTest {
     /**
      * Test of solver for the sine function.
      */
-    public void testSinFunction() throws MathException {
+    @Test
+    public void testSinFunction() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new RiddersSolver();
+        solver.setMaxEvaluations(10);
         double min, max, expected, result, tolerance;
 
         min = 3.0; max = 4.0; expected = FastMath.PI;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -1.0; max = 1.5; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of solver for the quintic function.
      */
-    public void testQuinticFunction() throws MathException {
+    @Test
+    public void testQuinticFunction() {
         UnivariateRealFunction f = new QuinticFunction();
         UnivariateRealSolver solver = new RiddersSolver();
+        solver.setMaxEvaluations(15);
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = 0.75; max = 1.5; expected = 1.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -0.9; max = -0.2; expected = -0.5;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of solver for the exponential function.
      */
-    public void testExpm1Function() throws MathException {
+    @Test
+    public void testExpm1Function() {
         UnivariateRealFunction f = new Expm1Function();
         UnivariateRealSolver solver = new RiddersSolver();
+        solver.setMaxEvaluations(20);
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -20.0; max = 10.0; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
 
         min = -50.0; max = 100.0; expected = 0.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
                     FastMath.abs(expected * solver.getRelativeAccuracy()));
         result = solver.solve(f, min, max);
-        assertEquals(expected, result, tolerance);
+        Assert.assertEquals(expected, result, tolerance);
     }
 
     /**
      * Test of parameters for the solver.
      */
-    public void testParameters() throws Exception {
+    @Test
+    public void testParameters() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new RiddersSolver();
+        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
             solver.solve(f, 1, -1);
-            fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting IllegalArgumentException - bad interval");
+        } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            fail("Expecting IllegalArgumentException - no bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting IllegalArgumentException - no bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
     }

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java?rev=1039083&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java Thu Nov 25 16:22:00 2010
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis.solvers;
+
+import org.apache.commons.math.analysis.MonitoredFunction;
+import org.apache.commons.math.analysis.QuinticFunction;
+import org.apache.commons.math.analysis.SinFunction;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Testcase for {@link SecantSolver}.
+ *
+ * @version $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $
+ */
+public final class SecantSolverTest {
+    @Test
+    public void testSinZero() {
+        // The sinus function is behaved well around the root at pi. The second
+        // order derivative is zero, which means linar approximating methods will
+        // still converge quadratically.
+        UnivariateRealFunction f = new SinFunction();
+        double result;
+        UnivariateRealSolver solver = new SecantSolver();
+        solver.setMaxEvaluations(10);
+
+        result = solver.solve(f, 3, 4);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 6);
+        result = solver.solve(f, 1, 4);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 7);
+    }
+
+    @Test
+    public void testQuinticZero() {
+        // The quintic function has zeros at 0, +-0.5 and +-1.
+        // Around the root of 0 the function is well behaved, with a second derivative
+        // of zero a 0.
+        // The other roots are less well to find, in particular the root at 1, because
+        // the function grows fast for x>1.
+        // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
+        // intervals containing these values are harder for the solvers.
+        UnivariateRealFunction f = new QuinticFunction();
+        double result;
+        // Brent-Dekker solver.
+        UnivariateRealSolver solver = new SecantSolver();
+        solver.setMaxEvaluations(20);
+        result = solver.solve(f, -0.2, 0.2);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 3);
+        result = solver.solve(f, -0.1, 0.3);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 7);
+        result = solver.solve(f, -0.3, 0.45);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 8);
+        result = solver.solve(f, 0.3, 0.7);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 9);
+        result = solver.solve(f, 0.2, 0.6);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 8);
+        result = solver.solve(f, 0.05, 0.95);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 10);
+        result = solver.solve(f, 0.85, 1.25);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 12);
+        result = solver.solve(f, 0.8, 1.2);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 10);
+        result = solver.solve(f, 0.85, 1.75);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 16);
+        // The followig is especially slow because the solver first has to reduce
+        // the bracket to exclude the extremum. After that, convergence is rapide.
+        result = solver.solve(f, 0.55, 1.45);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 9);
+        result = solver.solve(f, 0.85, 5);
+        //System.out.println(
+        //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
+        Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
+        Assert.assertTrue(solver.getEvaluations() <= 16);
+    }
+
+    @Test
+    public void testRootEndpoints() {
+        UnivariateRealFunction f = new SinFunction();
+        SecantSolver solver = new SecantSolver();
+        solver.setMaxEvaluations(10);
+
+        // endpoint is root
+        double result = solver.solve(f, FastMath.PI, 4);
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+
+        result = solver.solve(f, 3, FastMath.PI);
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+
+        result = solver.solve(f, FastMath.PI, 4, 3.5);
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+
+        result = solver.solve(f, 3, FastMath.PI, 3.07);
+        Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
+
+    }
+
+    @Test
+    public void testBadEndpoints() {
+        UnivariateRealFunction f = new SinFunction();
+        SecantSolver solver = new SecantSolver();
+        solver.setMaxEvaluations(10);
+        try {  // bad interval
+            solver.solve(f, 1, -1);
+            Assert.fail("Expecting IllegalArgumentException - bad interval");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {  // no bracket
+            solver.solve(f, 1, 1.5);
+            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {  // no bracket
+            solver.solve(f, 1, 1.5, 1.2);
+            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java Thu Nov 25 16:22:00 2010
@@ -17,125 +17,168 @@
 
 package org.apache.commons.math.analysis.solvers;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.SinFunction;
+import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
  * @version $Revision$ $Date$
  */
-public class UnivariateRealSolverUtilsTest extends TestCase {
+public class UnivariateRealSolverUtilsTest {
 
     protected UnivariateRealFunction sin = new SinFunction();
 
-    public void testSolveNull() throws MathException {
+    @Test
+    public void testSolveNull() {
         try {
             UnivariateRealSolverUtils.solve(null, 0.0, 4.0);
-            fail();
+            Assert.fail();
         } catch(IllegalArgumentException ex){
             // success
         }
     }
 
-    public void testSolveBadEndpoints() throws MathException {
+    @Test
+    public void testSolveBadEndpoints() {
         try { // bad endpoints
-            UnivariateRealSolverUtils.solve(sin, -0.1, 4.0, 4.0);
-            fail("Expecting IllegalArgumentException");
+            double root = UnivariateRealSolverUtils.solve(sin, 4.0, -0.1, 1e-6);
+            System.out.println("root=" + root);
+            Assert.fail("Expecting IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testSolveBadAccuracy() throws MathException {
+    @Test
+    public void testSolveBadAccuracy() {
         try { // bad accuracy
             UnivariateRealSolverUtils.solve(sin, 0.0, 4.0, 0.0);
-//             fail("Expecting IllegalArgumentException"); // TODO needs rework since convergence behaviour was changed
+//             Assert.fail("Expecting IllegalArgumentException"); // TODO needs rework since convergence behaviour was changed
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testSolveSin() throws MathException {
+    @Test
+    public void testSolveSin() {
         double x = UnivariateRealSolverUtils.solve(sin, 1.0, 4.0);
-        assertEquals(FastMath.PI, x, 1.0e-4);
+        Assert.assertEquals(FastMath.PI, x, 1.0e-4);
     }
 
-    public void testSolveAccuracyNull()  throws MathException {
+    @Test
+    public void testSolveAccuracyNull()  {
         try {
             double accuracy = 1.0e-6;
             UnivariateRealSolverUtils.solve(null, 0.0, 4.0, accuracy);
-            fail();
+            Assert.fail();
         } catch(IllegalArgumentException ex){
             // success
         }
     }
 
-    public void testSolveAccuracySin() throws MathException {
+    @Test
+    public void testSolveAccuracySin() {
         double accuracy = 1.0e-6;
         double x = UnivariateRealSolverUtils.solve(sin, 1.0,
                 4.0, accuracy);
-        assertEquals(FastMath.PI, x, accuracy);
+        Assert.assertEquals(FastMath.PI, x, accuracy);
     }
 
-    public void testSolveNoRoot() throws MathException {
+    @Test
+    public void testSolveNoRoot() {
         try {
             UnivariateRealSolverUtils.solve(sin, 1.0, 1.5);
-            fail("Expecting IllegalArgumentException ");
+            Assert.fail("Expecting IllegalArgumentException ");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
-    public void testBracketSin() throws MathException {
+    @Test
+    public void testBracketSin() {
         double[] result = UnivariateRealSolverUtils.bracket(sin,
                 0.0, -2.0, 2.0);
-        assertTrue(sin.value(result[0]) < 0);
-        assertTrue(sin.value(result[1]) > 0);
+        Assert.assertTrue(sin.value(result[0]) < 0);
+        Assert.assertTrue(sin.value(result[1]) > 0);
     }
 
-    public void testBracketEndpointRoot() throws MathException {
+    @Test
+    public void testBracketEndpointRoot() {
         double[] result = UnivariateRealSolverUtils.bracket(sin, 1.5, 0, 2.0);
-        assertEquals(0.0, sin.value(result[0]), 1.0e-15);
-        assertTrue(sin.value(result[1]) > 0);
+        Assert.assertEquals(0.0, sin.value(result[0]), 1.0e-15);
+        Assert.assertTrue(sin.value(result[1]) > 0);
     }
 
-    public void testNullFunction() throws MathException {
+    @Test
+    public void testNullFunction() {
         try { // null function
             UnivariateRealSolverUtils.bracket(null, 1.5, 0, 2.0);
-            fail("Expecting IllegalArgumentException");
+            Assert.fail("Expecting IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
     
-    public void testBadInitial() throws MathException {
+    @Test
+    public void testBadInitial() {
         try { // initial not between endpoints
             UnivariateRealSolverUtils.bracket(sin, 2.5, 0, 2.0);
-            fail("Expecting IllegalArgumentException");
+            Assert.fail("Expecting IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
     
-    public void testBadEndpoints() throws MathException {
+    @Test
+    public void testBadEndpoints() {
         try { // endpoints not valid
             UnivariateRealSolverUtils.bracket(sin, 1.5, 2.0, 1.0);
-            fail("Expecting IllegalArgumentException");
+            Assert.fail("Expecting IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
     
-    public void testBadMaximumIterations() throws MathException {
+    @Test
+    public void testBadMaximumIterations() {
         try { // bad maximum iterations
             UnivariateRealSolverUtils.bracket(sin, 1.5, 0, 2.0, 0);
-            fail("Expecting IllegalArgumentException");
+            Assert.fail("Expecting IllegalArgumentException");
         } catch (IllegalArgumentException ex) {
             // expected
         }
     }
 
+    @Test
+    public void testMisc() {
+        UnivariateRealFunction f = new QuinticFunction();
+        double result;
+        // Static solve method
+        result = UnivariateRealSolverUtils.solve(f, -0.2, 0.2);
+        Assert.assertEquals(result, 0, 1E-8);
+        result = UnivariateRealSolverUtils.solve(f, -0.1, 0.3);
+        Assert.assertEquals(result, 0, 1E-8);
+        result = UnivariateRealSolverUtils.solve(f, -0.3, 0.45);
+        Assert.assertEquals(result, 0, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.3, 0.7);
+        Assert.assertEquals(result, 0.5, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.2, 0.6);
+        Assert.assertEquals(result, 0.5, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.05, 0.95);
+        Assert.assertEquals(result, 0.5, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.85, 1.25);
+        Assert.assertEquals(result, 1.0, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.8, 1.2);
+        Assert.assertEquals(result, 1.0, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.85, 1.75);
+        Assert.assertEquals(result, 1.0, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.55, 1.45);
+        Assert.assertEquals(result, 1.0, 1E-6);
+        result = UnivariateRealSolverUtils.solve(f, 0.85, 5);
+        Assert.assertEquals(result, 1.0, 1E-6);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java?rev=1039083&r1=1039082&r2=1039083&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java Thu Nov 25 16:22:00 2010
@@ -235,7 +235,7 @@ public class DormandPrince853IntegratorT
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
-    assertTrue(handler.getMaximalValueError() < 5.0e-8);
+    assertEquals(0, handler.getMaximalValueError(), 1.1e-7);
     assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
     integ.clearEventHandlers();



Mime
View raw message