commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r724191 [2/2] - in /commons/proper/math/trunk/src: java/org/apache/commons/math/ java/org/apache/commons/math/analysis/ site/xdoc/ site/xdoc/userguide/ test/org/apache/commons/math/analysis/
Date Sun, 07 Dec 2008 20:24:11 GMT
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java?rev=724191&r1=724190&r2=724191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java
Sun Dec  7 12:24:10 2008
@@ -34,9 +34,10 @@
 public final class LaguerreSolverTest extends TestCase {
 
     /**
-     * Test of solver for the linear function.
+     * Test deprecated APIs.
      */
-    public void testLinearFunction() throws MathException {
+    @Deprecated
+    public void testDeprecated() throws MathException {
         double min, max, expected, result, tolerance;
 
         // p(x) = 4x - 1
@@ -52,6 +53,24 @@
     }
 
     /**
+     * Test of solver for the linear function.
+     */
+    public void testLinearFunction() throws MathException {
+        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();
+
+        min = 0.0; max = 1.0; expected = 0.25;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
      * Test of solver for the quadratic function.
      */
     public void testQuadraticFunction() throws MathException {
@@ -60,18 +79,18 @@
         // 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(f);
+        UnivariateRealSolver solver = new LaguerreSolver();
 
         min = 0.0; max = 2.0; expected = 0.5;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -4.0; max = -1.0; expected = -3.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -84,24 +103,24 @@
         // 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(f);
+        UnivariateRealSolver solver = new LaguerreSolver();
 
         min = -2.0; max = 2.0; expected = -1.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -5.0; max = -2.5; expected = -3.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 3.0; max = 6.0; expected = 4.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -114,8 +133,7 @@
 
         // 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 };
-        PolynomialFunction f = new PolynomialFunction(coefficients);
-        LaguerreSolver solver = new LaguerreSolver(f);
+        LaguerreSolver solver = new LaguerreSolver();
         result = solver.solveAll(coefficients, initial);
 
         expected = new Complex(0.0, -2.0);
@@ -150,26 +168,25 @@
     public void testParameters() throws Exception {
         double coefficients[] = { -3.0, 5.0, 2.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver(f);
+        UnivariateRealSolver solver = new LaguerreSolver();
 
         try {
             // bad interval
-            solver.solve(1, -1);
+            solver.solve(f, 1, -1);
             fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
             // no bracketing
-            solver.solve(2, 3);
+            solver.solve(f, 2, 3);
             fail("Expecting IllegalArgumentException - no bracketing");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
             // bad function
-            UnivariateRealFunction f2 = new SinFunction();
-            new LaguerreSolver(f2);
+            solver.solve(new SinFunction(), -1, 1);
             fail("Expecting IllegalArgumentException - bad function");
         } catch (IllegalArgumentException ex) {
             // expected

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java?rev=724191&r1=724190&r2=724191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java
Sun Dec  7 12:24:10 2008
@@ -35,9 +35,10 @@
 public final class MullerSolverTest extends TestCase {
 
     /**
-     * Test of solver for the sine function.
+     * Test deprecated APIs.
      */
-    public void testSinFunction() throws MathException {
+    @Deprecated
+    public void testDeprecated() throws MathException {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver(f);
         double min, max, expected, result, tolerance;
@@ -56,23 +57,72 @@
     }
 
     /**
+     * Test deprecated APIs.
+     */
+    @Deprecated
+    public void testDeprecated2() throws MathException {
+        UnivariateRealFunction f = new QuinticFunction();
+        MullerSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = -0.4; max = 0.2; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = 0.75; max = 1.5; expected = 1.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -0.9; max = -0.2; expected = -0.5;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the sine function.
+     */
+    public void testSinFunction() throws MathException {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new MullerSolver();
+        double min, max, expected, result, tolerance;
+
+        min = 3.0; max = 4.0; expected = Math.PI;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -1.0; max = 1.5; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.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(f);
+        MullerSolver solver = new MullerSolver();
         double min, max, expected, result, tolerance;
 
         min = 3.0; max = 4.0; expected = Math.PI;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -1.0; max = 1.5; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -81,25 +131,25 @@
      */
     public void testQuinticFunction() throws MathException {
         UnivariateRealFunction f = new QuinticFunction();
-        UnivariateRealSolver solver = new MullerSolver(f);
+        UnivariateRealSolver solver = new MullerSolver();
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 0.75; max = 1.5; expected = 1.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -0.9; max = -0.2; expected = -0.5;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -108,25 +158,25 @@
      */
     public void testQuinticFunction2() throws MathException {
         UnivariateRealFunction f = new QuinticFunction();
-        MullerSolver solver = new MullerSolver(f);
+        MullerSolver solver = new MullerSolver();
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 0.75; max = 1.5; expected = 1.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -0.9; max = -0.2; expected = -0.5;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -139,25 +189,25 @@
      */
     public void testExpm1Function() throws MathException {
         UnivariateRealFunction f = new Expm1Function();
-        UnivariateRealSolver solver = new MullerSolver(f);
+        UnivariateRealSolver solver = new MullerSolver();
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -20.0; max = 10.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -50.0; max = 100.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -168,25 +218,25 @@
      */
     public void testExpm1Function2() throws MathException {
         UnivariateRealFunction f = new Expm1Function();
-        MullerSolver solver = new MullerSolver(f);
+        MullerSolver solver = new MullerSolver();
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -20.0; max = 10.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -50.0; max = 100.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
+        result = solver.solve2(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -195,18 +245,18 @@
      */
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new MullerSolver(f);
+        UnivariateRealSolver solver = new MullerSolver();
 
         try {
             // bad interval
-            solver.solve(1, -1);
+            solver.solve(f, 1, -1);
             fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
             // no bracketing
-            solver.solve(2, 3);
+            solver.solve(f, 2, 3);
             fail("Expecting IllegalArgumentException - no bracketing");
         } catch (IllegalArgumentException ex) {
             // expected

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NewtonSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NewtonSolverTest.java?rev=724191&r1=724190&r2=724191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NewtonSolverTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NewtonSolverTest.java
Sun Dec  7 12:24:10 2008
@@ -26,10 +26,9 @@
  * @version $Revision$ $Date$
  */
 public final class NewtonSolverTest extends TestCase {
-    /**
-     *
-     */
-    public void testSinZero() throws MathException {
+
+    @Deprecated
+    public void testDeprecated() throws MathException {
         DifferentiableUnivariateRealFunction f = new SinFunction();
         double result;
         
@@ -46,44 +45,63 @@
     }
 
     /**
+    *
+    */
+   public void testSinZero() throws MathException {
+       DifferentiableUnivariateRealFunction f = new SinFunction();
+       double result;
+       
+       UnivariateRealSolver solver = new NewtonSolver();
+       result = solver.solve(f, 3, 4);
+       assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+
+       result = solver.solve(f, 1, 4);
+       assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+       
+       //TODO:  create abstract solver test class, move these there
+       assertEquals(result, solver.getResult(), 0);
+       assertTrue(solver.getIterationCount() > 0);
+   }
+
+   /**
      *
      */
     public void testQuinticZero() throws MathException {
         DifferentiableUnivariateRealFunction f = new QuinticFunction();
         double result;
 
-        UnivariateRealSolver solver = new BisectionSolver(f);
-        result = solver.solve(-0.2, 0.2);
+        UnivariateRealSolver solver = new NewtonSolver();
+        result = solver.solve(f, -0.2, 0.2);
         assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(-0.1, 0.3);
+        result = solver.solve(f, -0.1, 0.3);
         assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(-0.3, 0.45);
+        result = solver.solve(f, -0.3, 0.45);
         assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.3, 0.7);
+        result = solver.solve(f, 0.3, 0.7);
         assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.2, 0.6);
+        result = solver.solve(f, 0.2, 0.6);
         assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.05, 0.95);
+        result = solver.solve(f, 0.05, 0.95);
         assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.85, 1.25);
+        result = solver.solve(f, 0.85, 1.25);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.8, 1.2);
+        result = solver.solve(f, 0.8, 1.2);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.85, 1.75);
+        result = solver.solve(f, 0.85, 1.75);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.55, 1.45);
+        result = solver.solve(f, 0.55, 1.45);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
 
-        result = solver.solve(0.85, 5);
+        result = solver.solve(f, 0.85, 5);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
     }
     
@@ -94,57 +112,57 @@
         DifferentiableUnivariateRealFunction f = new QuinticFunction();
         double result;
         
-        NewtonSolver solver = new NewtonSolver(f);
+        NewtonSolver solver = new NewtonSolver();
         NewtonSolver solver2 = (NewtonSolver)TestUtils.serializeAndRecover(solver);
         
-        result = solver.solve(-0.2, 0.2);
+        result = solver.solve(f, -0.2, 0.2);
         assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(-0.2, 0.2), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, -0.2, 0.2), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(-0.1, 0.3);
+        result = solver.solve(f, -0.1, 0.3);
         assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(-0.1, 0.3), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, -0.1, 0.3), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(-0.3, 0.45);
+        result = solver.solve(f, -0.3, 0.45);
         assertEquals(result, 0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(-0.3, 0.45), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, -0.3, 0.45), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.3, 0.7);
+        result = solver.solve(f, 0.3, 0.7);
         assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.3, 0.7), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.3, 0.7), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.2, 0.6);
+        result = solver.solve(f, 0.2, 0.6);
         assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.2, 0.6), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.2, 0.6), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.05, 0.95);
+        result = solver.solve(f, 0.05, 0.95);
         assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.05, 0.95), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.05, 0.95), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.85, 1.25);
+        result = solver.solve(f, 0.85, 1.25);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.85, 1.25), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.85, 1.25), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.8, 1.2);
+        result = solver.solve(f, 0.8, 1.2);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.8, 1.2), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.8, 1.2), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.85, 1.75);
+        result = solver.solve(f, 0.85, 1.75);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.85, 1.75), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.85, 1.75), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.55, 1.45);
+        result = solver.solve(f, 0.55, 1.45);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.55, 1.45), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.55, 1.45), result, solver2.getAbsoluteAccuracy());
         
-        result = solver.solve(0.85, 5);
+        result = solver.solve(f, 0.85, 5);
         assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
-        assertEquals(solver2.solve(0.85, 5), result, solver2.getAbsoluteAccuracy());
+        assertEquals(solver2.solve(f, 0.85, 5), result, solver2.getAbsoluteAccuracy());
         
         /* Test Reset */
         double newValue = 1.0e-2;
         f = new QuinticFunction();
-        solver = new NewtonSolver(f);
+        solver = new NewtonSolver();
         
         double oldValue = solver.getRelativeAccuracy();
         solver.setRelativeAccuracy(newValue);

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java?rev=724191&r1=724190&r2=724191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java
Sun Dec  7 12:24:10 2008
@@ -33,9 +33,10 @@
 public final class RiddersSolverTest extends TestCase {
 
     /**
-     * Test of solver for the sine function.
+     * Test the deprecated APIs.
      */
-    public void testSinFunction() throws MathException {
+    @Deprecated
+    public void testDeprecated() throws MathException {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new RiddersSolver(f);
         double min, max, expected, result, tolerance;
@@ -54,29 +55,50 @@
     }
 
     /**
+     * Test of solver for the sine function.
+     */
+    public void testSinFunction() throws MathException {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new RiddersSolver();
+        double min, max, expected, result, tolerance;
+
+        min = 3.0; max = 4.0; expected = Math.PI;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -1.0; max = 1.5; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(f, min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
      * Test of solver for the quintic function.
      */
     public void testQuinticFunction() throws MathException {
         UnivariateRealFunction f = new QuinticFunction();
-        UnivariateRealSolver solver = new RiddersSolver(f);
+        UnivariateRealSolver solver = new RiddersSolver();
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 0.75; max = 1.5; expected = 1.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -0.9; max = -0.2; expected = -0.5;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -85,25 +107,25 @@
      */
     public void testExpm1Function() throws MathException {
         UnivariateRealFunction f = new Expm1Function();
-        UnivariateRealSolver solver = new RiddersSolver(f);
+        UnivariateRealSolver solver = new RiddersSolver();
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -20.0; max = 10.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -50.0; max = 100.0; expected = 0.0;
         tolerance = Math.max(solver.getAbsoluteAccuracy(),
                     Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
+        result = solver.solve(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -112,18 +134,18 @@
      */
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new RiddersSolver(f);
+        UnivariateRealSolver solver = new RiddersSolver();
 
         try {
             // bad interval
-            solver.solve(1, -1);
+            solver.solve(f, 1, -1);
             fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
             // no bracketing
-            solver.solve(2, 3);
+            solver.solve(f, 2, 3);
             fail("Expecting IllegalArgumentException - no bracketing");
         } catch (IllegalArgumentException ex) {
             // expected

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImplTest.java?rev=724191&r1=724190&r2=724191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImplTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImplTest.java
Sun Dec  7 12:24:10 2008
@@ -28,8 +28,6 @@
     /** solver factory */
     private UnivariateRealSolverFactory factory;
     
-    /** function */
-    private DifferentiableUnivariateRealFunction function;
     /**
      * @throws java.lang.Exception
      * @see junit.framework.TestCase#tearDown()
@@ -37,7 +35,6 @@
     protected void setUp() throws Exception {
         super.setUp();
         factory = new UnivariateRealSolverFactoryImpl();
-        function = new SinFunction();
     }
     
     /**
@@ -46,67 +43,31 @@
      */
     protected void tearDown() throws Exception {
         factory = null;
-        function = null;
         super.tearDown();
     }
 
-    public void testNewBisectionSolverNull() {
-        try {
-            factory.newBisectionSolver(null);
-            fail();
-        } catch(IllegalArgumentException ex) {
-            // success
-        }
-    }
-
     public void testNewBisectionSolverValid() {
-        UnivariateRealSolver solver = factory.newBisectionSolver(function);
+        UnivariateRealSolver solver = factory.newBisectionSolver();
         assertNotNull(solver);
         assertTrue(solver instanceof BisectionSolver);
     }
 
-    public void testNewNewtonSolverNull() {
-        try {
-            factory.newNewtonSolver(null);
-            fail();
-        } catch(IllegalArgumentException ex) {
-            // success
-        }
-    }
-
     public void testNewNewtonSolverValid() {
-        UnivariateRealSolver solver = factory.newNewtonSolver(function);
+        UnivariateRealSolver solver = factory.newNewtonSolver();
         assertNotNull(solver);
         assertTrue(solver instanceof NewtonSolver);
     }
 
-    public void testNewBrentSolverNull() {
-        try {
-            factory.newBrentSolver(null);
-            fail();
-        } catch(IllegalArgumentException ex) {
-            // success
-        }
-    }
-
     public void testNewBrentSolverValid() {
-        UnivariateRealSolver solver = factory.newBrentSolver(function);
+        UnivariateRealSolver solver = factory.newBrentSolver();
         assertNotNull(solver);
         assertTrue(solver instanceof BrentSolver);
     }
 
-    public void testNewSecantSolverNull() {
-        try {
-            factory.newSecantSolver(null);
-            fail();
-        } catch(IllegalArgumentException ex) {
-            // success
-        }
-    }
-
     public void testNewSecantSolverValid() {
-        UnivariateRealSolver solver = factory.newSecantSolver(function);
+        UnivariateRealSolver solver = factory.newSecantSolver();
         assertNotNull(solver);
         assertTrue(solver instanceof SecantSolver);
     }
+
 }



Mime
View raw message