commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdigg...@apache.org
Subject cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/analysis BisectionSolverTest.java
Date Wed, 02 Jun 2004 00:11:53 GMT
mdiggory    2004/06/01 17:11:53

  Modified:    math/src/test/org/apache/commons/math/analysis
                        BisectionSolverTest.java
  Log:
  Test Example for serialization of Solvers and Functions.
  
  Revision  Changes    Path
  1.11      +91 -1     jakarta-commons/math/src/test/org/apache/commons/math/analysis/BisectionSolverTest.java
  
  Index: BisectionSolverTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/analysis/BisectionSolverTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BisectionSolverTest.java	18 Feb 2004 03:24:20 -0000	1.10
  +++ BisectionSolverTest.java	2 Jun 2004 00:11:53 -0000	1.11
  @@ -18,6 +18,8 @@
   package org.apache.commons.math.analysis;
   
   import org.apache.commons.math.MathException;
  +import org.apache.commons.math.TestUtils;
  +import org.apache.commons.math.stat.univariate.DescriptiveStatistics;
   
   import junit.framework.TestCase;
   
  @@ -209,4 +211,92 @@
               fail(ex.getMessage());
           }
       }        
  +    
  +    /**
  +     * Test Serialization and Recovery
  +     */
  +   public void testSerialization() {
  +
  +       
  +       try {
  +           UnivariateRealFunction f = (UnivariateRealFunction)TestUtils.serializeAndRecover(new
QuinticFunction());
  +           double result;
  +           
  +           BisectionSolver solver = new BisectionSolver(f);
  +           UnivariateRealSolver solver2 = (UnivariateRealSolver)TestUtils.serializeAndRecover(solver);
  +           
  +           result = solver.solve(-0.2, 0.2);
  +           assertEquals(result, 0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(-0.2, 0.2), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(-0.1, 0.3);
  +           assertEquals(result, 0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(-0.1, 0.3), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(-0.3, 0.45);
  +           assertEquals(result, 0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(-0.3, 0.45), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.3, 0.7);
  +           assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.3, 0.7), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.2, 0.6);
  +           assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.2, 0.6), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.05, 0.95);
  +           assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.05, 0.95), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.85, 1.25);
  +           assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.85, 1.25), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.8, 1.2);
  +           assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.8, 1.2), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.85, 1.75);
  +           assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.85, 1.75), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.55, 1.45);
  +           assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.55, 1.45), result, solver2.getAbsoluteAccuracy());
  +           
  +           result = solver.solve(0.85, 5);
  +           assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
  +           assertEquals(solver2.solve(0.85, 5), result, solver2.getAbsoluteAccuracy());
  +           
  +       } catch(MathException ex){
  +           fail(ex.getMessage());
  +       }
  +       
  +       /* Test Reset */
  +       try{ 
  +           double newValue = 1.0e-2;
  +           UnivariateRealFunction f = (UnivariateRealFunction)TestUtils.serializeAndRecover(new
QuinticFunction());
  +           UnivariateRealSolver solver = new BisectionSolver(f);
  +
  +           double oldValue = solver.getRelativeAccuracy();
  +           solver.setRelativeAccuracy(newValue);
  +           solver.resetRelativeAccuracy();
  +           assertEquals(oldValue, solver.getRelativeAccuracy(), 1.0e-2);
  +       
  +           UnivariateRealSolver  solver2 = (UnivariateRealSolver)TestUtils.serializeAndRecover(solver);

  +       
  +           assertEquals(oldValue, solver2.getRelativeAccuracy(), 1.0e-2);
  +       
  +           solver2.setRelativeAccuracy(newValue);
  +           solver2.resetRelativeAccuracy();
  +       
  +           assertEquals(oldValue, solver2.getRelativeAccuracy(), 1.0e-2);
  +       
  +       } catch(MathException ex){
  +           fail(ex.getMessage());
  +       }
  +    
  +   }
  +    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message