commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r488828 [5/6] - in /jakarta/commons/proper/math/trunk/src/mantissa: src/org/spaceroots/mantissa/ src/org/spaceroots/mantissa/algebra/ src/org/spaceroots/mantissa/fitting/ src/org/spaceroots/mantissa/functions/scalar/ src/org/spaceroots/mant...
Date Tue, 19 Dec 2006 22:11:11 GMT
Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/functions/vectorial/VectorialValuedPairTest.java Tue Dec 19 14:11:07 2006
@@ -31,9 +31,9 @@
     tab[0] = -8.4;
     tab[1] = -3.2;
     VectorialValuedPair pair = new VectorialValuedPair(1.2, tab);
-    assertTrue(Math.abs(pair.getX()    - 1.2) < 1.0e-10);
-    assertTrue(Math.abs(pair.getY()[0] + 8.4) < 1.0e-10);
-    assertTrue(Math.abs(pair.getY()[1] + 3.2) < 1.0e-10);
+    assertTrue(Math.abs(pair.x    - 1.2) < 1.0e-10);
+    assertTrue(Math.abs(pair.y[0] + 8.4) < 1.0e-10);
+    assertTrue(Math.abs(pair.y[1] + 3.2) < 1.0e-10);
   }
 
   public void testCopyConstructor() {
@@ -41,13 +41,14 @@
     tab[0] = -8.4;
     tab[1] = -3.2;
     VectorialValuedPair pair1 = new VectorialValuedPair(1.2, tab);
-    VectorialValuedPair pair2 = new VectorialValuedPair(pair1);
-    assertTrue(Math.abs(pair2.getX()    - pair1.getX())    < 1.0e-10);
-    assertTrue(Math.abs(pair2.getY()[0] - pair1.getY()[0]) < 1.0e-10);
-    assertTrue(Math.abs(pair2.getY()[1] - pair1.getY()[1]) < 1.0e-10);
-    assertTrue(Math.abs(pair2.getX()    - 1.2)        < 1.0e-10);
-    assertTrue(Math.abs(pair2.getY()[0] + 8.4)        < 1.0e-10);
-    assertTrue(Math.abs(pair2.getY()[1] + 3.2)        < 1.0e-10);
+    VectorialValuedPair pair2 = new VectorialValuedPair(pair1.x,
+                                                        pair1.y);
+    assertTrue(Math.abs(pair2.x    - pair1.x)    < 1.0e-10);
+    assertTrue(Math.abs(pair2.y[0] - pair1.y[0]) < 1.0e-10);
+    assertTrue(Math.abs(pair2.y[1] - pair1.y[1]) < 1.0e-10);
+    assertTrue(Math.abs(pair2.x    - 1.2)        < 1.0e-10);
+    assertTrue(Math.abs(pair2.y[0] + 8.4)        < 1.0e-10);
+    assertTrue(Math.abs(pair2.y[1] + 3.2)        < 1.0e-10);
   }
 
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/RotationTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/RotationTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/RotationTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/RotationTest.java Tue Dec 19 14:11:07 2006
@@ -59,7 +59,7 @@
     checkAngle(r.getAngle(), 2 * Math.PI / 3);
 
     try {
-      r = new Rotation(new Vector3D(0, 0, 0), 2 * Math.PI / 3);
+      new Rotation(new Vector3D(0, 0, 0), 2 * Math.PI / 3);
       fail("an exception should have been thrown");
     } catch (ArithmeticException e) {
     } catch (Exception e) {
@@ -81,10 +81,9 @@
     Vector3D u = new Vector3D(3, 2, 1);
     Vector3D v = new Vector3D(-4, 2, 2);
     Rotation r = new Rotation(u, v);
-    checkVector(r.applyTo(Vector3D.multiply(v.getNorm(), u)),
-                Vector3D.multiply(u.getNorm(), v));
+    checkVector(r.applyTo(u.multiply(v.getNorm())), v.multiply(u.getNorm()));
 
-    checkAngle(new Rotation(u, Vector3D.negate(u)).getAngle(), Math.PI);
+    checkAngle(new Rotation(u, u.negate()).getAngle(), Math.PI);
 
   }
 
@@ -96,14 +95,14 @@
     Vector3D v2 = new Vector3D(-2, 0, 2);
     Rotation r = new Rotation(u1, u2, v1, v2);
     checkVector(r.applyTo(Vector3D.plusI), Vector3D.plusK);
-    checkVector(r.applyTo(Vector3D.plusJ), Vector3D.negate(Vector3D.plusI));
+    checkVector(r.applyTo(Vector3D.plusJ), Vector3D.minusI);
 
-    r = new Rotation(u1, u2, Vector3D.negate(u1), Vector3D.negate(u2));
+    r = new Rotation(u1, u2, u1.negate(), u2.negate());
     Vector3D axis = r.getAxis();
     if (Vector3D.dotProduct(axis, Vector3D.plusK) > 0) {
       checkVector(axis, Vector3D.plusK);
     } else {
-      checkVector(axis, Vector3D.negate(Vector3D.plusK));
+      checkVector(axis, Vector3D.minusK);
     }
     checkAngle(r.getAngle(), Math.PI);
 
@@ -187,8 +186,9 @@
                         { 0.0, 1.0, 0.0 },
                         { 1.0, 0.0, 0.0 } };
       r = new Rotation(m5, 1.0e-7);
-      fail("an exception should have been thrown");
+      fail("got " + r + ", should have caught an exception");
     } catch (NotARotationMatrixException e) {
+      // expected
     } catch (Exception e) {
       fail("wrong exception caught");
     }
@@ -329,7 +329,7 @@
   }
 
   private void checkVector(Vector3D v1, Vector3D v2) {
-    assertTrue(Vector3D.subtract(v1, v2).getNorm() < 1.0e-10);
+    assertTrue(v1.subtract(v2).getNorm() < 1.0e-10);
   }
 
   private void checkAngle(double a1, double a2) {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/Vector3DTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/Vector3DTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/Vector3DTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/geometry/Vector3DTest.java Tue Dec 19 14:11:07 2006
@@ -43,29 +43,29 @@
 
     Vector3D v1 = new Vector3D(1, 2, 3);
     Vector3D v2 = new Vector3D(-3, -2, -1);
-    v1 = Vector3D.subtract(v1, v2);
+    v1 = v1.subtract(v2);
     checkVector(v1, new Vector3D(4, 4, 4));
 
-    checkVector(Vector3D.subtract(v2, v1), new Vector3D(-7, -6, -5));
+    checkVector(v2.subtract(v1), new Vector3D(-7, -6, -5));
 
   }
 
   public void testAdd() {
     Vector3D v1 = new Vector3D(1, 2, 3);
     Vector3D v2 = new Vector3D(-3, -2, -1);
-    v1 = Vector3D.add(v1, v2);
+    v1 = v1.add(v2);
     checkVector(v1, new Vector3D(-2, 0, 2));
 
-    checkVector(Vector3D.add(v2, v1), new Vector3D(-5, -2, 1));
+    checkVector(v2.add(v1), new Vector3D(-5, -2, 1));
 
   }
 
   public void testScalarProduct() {
     Vector3D v = new Vector3D(1, 2, 3);
-    v = Vector3D.multiply(3, v);
+    v = v.multiply(3);
     checkVector(v, new Vector3D(3, 6, 9));
 
-    checkVector(Vector3D.multiply(0.5, v), new Vector3D(1.5, 3, 4.5));
+    checkVector(v.multiply(0.5), new Vector3D(1.5, 3, 4.5));
 
   }
 
@@ -101,17 +101,16 @@
   public void testAngularSeparation() {
     Vector3D v1 = new Vector3D(2, -1, 4);
 
-    Vector3D  k = Vector3D.normalize(v1);
+    Vector3D  k = v1.normalize();
     Vector3D  i = k.orthogonal();
-
-    Vector3D v2 = new Vector3D(Math.cos(1.2), k, Math.sin(1.2), i);
+    Vector3D v2 = k.multiply(Math.cos(1.2)).add(i.multiply(Math.sin(1.2)));
 
     assertTrue(Math.abs(Vector3D.angle(v1, v2) - 1.2) < 1.0e-12);
 
   }
 
   private void checkVector(Vector3D v1, Vector3D v2) {
-    assertTrue(Vector3D.subtract(v1, v2).getNorm() < 1.0e-12);
+    assertTrue(v1.subtract(v2).getNorm() < 1.0e-12);
   }
   
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java Tue Dec 19 14:11:07 2006
@@ -149,7 +149,7 @@
     boolean gotIt = false;
     try {
       d.setElement(3, 3, 0.0);
-      result = d.solve(b, 1.0e-10);
+      d.solve(b, 1.0e-10);
     } catch (SingularMatrixException e) {
       gotIt = true;
     }

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java Tue Dec 19 14:11:07 2006
@@ -54,26 +54,14 @@
   }
 
   public void testElements() {
-    Matrix m = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
-
-    checkMatrix(m, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
+
+    checkMatrix(m, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testCopy() {
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     GeneralMatrix m2 = new GeneralMatrix(m1);
 
@@ -86,20 +74,12 @@
     assertTrue(m2.getRows() == m1.getRows());
     assertTrue(m2.getColumns() == m1.getColumns());
 
-    checkMatrix(m2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    checkMatrix(m2, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testDuplicate() {
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = m1.duplicate();
     assertTrue(m2 instanceof GeneralMatrix);
@@ -113,11 +93,7 @@
     assertTrue(m2.getRows() == m1.getRows());
     assertTrue(m2.getColumns() == m1.getColumns());
 
-    checkMatrix (m2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    checkMatrix (m2, new BilinearPattern(1.0, 0.01));
 
   }
 
@@ -133,53 +109,29 @@
 
   public void testAddOK() {
 
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = buildMatrix(m1.getRows(),
                             m1.getColumns(),
-                            new ElementPattern() {
-                              public double value(int i, int j) {
-                                return 100 * i - 0.01 * j;
-                              }
-                            });
+                            new BilinearPattern(100, -0.01));
 
     Matrix m3 = m1.add(m2);
 
-    checkMatrix(m3, new ElementPattern() {
-        public double value(int i, int j) {
-          return 101 * i;
-        }
-      });
+    checkMatrix(m3, new BilinearPattern(101, 0));
 
   }
 
   public void testSelfAdd() {
 
-    GeneralMatrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    GeneralMatrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = buildMatrix(m1.getRows(),
                             m1.getColumns(),
-                            new ElementPattern() {
-                              public double value(int i, int j) {
-                                return 100 * i - 0.01 * j;
-                              }
-                            });
+                            new BilinearPattern(100, -0.01));
 
     m1.selfAdd(m2);
 
-    checkMatrix(m1, new ElementPattern() {
-        public double value(int i, int j) {
-          return 101 * i;
-        }
-      });
+    checkMatrix(m1, new BilinearPattern(101, 0));
 
   }
 
@@ -195,53 +147,29 @@
 
   public void testSubOK() {
 
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = buildMatrix(m1.getRows(),
                             m1.getColumns(),
-                            new ElementPattern() {
-                              public double value(int i, int j) {
-                                return 100 * i - 0.01 * j;
-                              }
-                            });
+                            new BilinearPattern(100, -0.01));
 
     Matrix m3 = m1.sub(m2);
 
-    checkMatrix(m3, new ElementPattern() {
-        public double value(int i, int j) {
-          return 0.02 * j - 99 * i;
-        }
-      });
+    checkMatrix(m3, new BilinearPattern(-99, 0.02));
 
   }
 
   public void testSelfSub() {
 
-    GeneralMatrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    GeneralMatrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = buildMatrix(m1.getRows(),
                             m1.getColumns(),
-                            new ElementPattern() {
-                              public double value(int i, int j) {
-                                return 100 * i - 0.01 * j;
-                              }
-                            });
+                            new BilinearPattern(100, -0.01));
 
     m1.selfSub(m2);
 
-    checkMatrix(m1, new ElementPattern() {
-        public double value(int i, int j) {
-          return 0.02 * j - 99 * i;
-        }
-      });
+    checkMatrix(m1, new BilinearPattern(-99, 0.02));
 
   }
 
@@ -257,85 +185,46 @@
 
   public void testMulMOK() {
 
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
-
-    Matrix m2 = buildMatrix(m1.getColumns(), 4, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
+
+    Matrix m2 = buildMatrix(m1.getColumns(), 4, new BilinearPattern(2, -1));
 
     Matrix m3 = m1.mul(m2);
 
-    checkMatrix(m3, new ElementPattern() {
-        public double value(int i, int j) {
-          int p = 10; // must be equal to m1.getColumns()
-          return p * ((2 * i - 0.01 *j) * (p - 1) / 2.0
-                      - i* j
-                      + (p - 1) * (2 * p - 1) / 300.0);
-        }
-      });
+    checkMatrix(m3, new ComplexPattern(m1.getColumns()));
 
   }
 
   public void testMulD() {
 
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = m1.mul(2.5);
 
-    checkMatrix(m2, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2.5 * (i + 0.01 * j);
-        }
-      });
+    checkMatrix(m2, new BilinearPattern(2.5, 0.025));
 
   }
 
   public void testSelfMul() {
 
-    Matrix m = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     m.selfMul(2.5);
 
-    checkMatrix(m, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2.5 * (i + 0.01 * j);
-        }
-      });
+    checkMatrix(m, new BilinearPattern(2.5, 0.025));
 
   }
 
   public void testTranspose() {
 
-    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m1 = buildMatrix(5, 10, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = m1.getTranspose();
 
     assertTrue(m1.getRows() == m2.getColumns());
     assertTrue(m1.getColumns() == m2.getRows());
 
-    checkMatrix(m2, new ElementPattern() {
-        public double value(int i, int j) {
-          return 0.01 * i + j;
-        }
-      });
+    checkMatrix(m2, new BilinearPattern(0.01, 1.0));
 
   }
 
@@ -343,12 +232,36 @@
     return new TestSuite(GeneralMatrixTest.class);
   }
 
-  public interface ElementPattern {
+  private interface ElementPattern {
     public double value(int i, int j);
   }
 
+  private static class BilinearPattern implements ElementPattern {
+    public BilinearPattern(double coeffI, double coeffJ) {
+      this.coeffI = coeffI;
+      this.coeffJ = coeffJ;
+    }
+    public double value(int i, int j) {
+      return coeffI * i + coeffJ * j;
+    }
+    private final double coeffI;
+    private final double coeffJ;
+  }
+
+  private static class ComplexPattern implements ElementPattern {
+    public ComplexPattern(int p) {
+      this.p = p;
+    }
+    public double value(int i, int j) {
+      return p * ((2 * i - 0.01 *j) * (p - 1) / 2.0
+                  - i* j
+                  + (p - 1) * (2 * p - 1) / 300.0);
+    }
+    private final int p;
+  }
+  
   public GeneralMatrix buildMatrix(int rows, int columns,
-                                   ElementPattern pattern) {
+                                   BilinearPattern pattern) {
     GeneralMatrix m = new GeneralMatrix(rows, columns);
 
     for (int i = 0; i < m.getRows(); ++i) {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java Tue Dec 19 14:11:07 2006
@@ -54,26 +54,14 @@
   }
 
   public void testElements() {
-    Matrix m = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
-
-    checkMatrix(m, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    Matrix m = buildMatrix(5, new BilinearPattern(1.0, 0.01));
+
+    checkMatrix(m, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testCopy() {
-    GeneralSquareMatrix m1 = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
 
     GeneralSquareMatrix m2 = new GeneralSquareMatrix(m1);
 
@@ -86,20 +74,12 @@
     assertTrue(m2.getRows() == m1.getRows());
     assertTrue(m2.getColumns() == m1.getColumns());
 
-    checkMatrix(m2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    checkMatrix(m2, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testDuplicate() {
-    GeneralSquareMatrix m1 = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
 
     Matrix m2 = m1.duplicate();
     assertTrue(m2 instanceof GeneralSquareMatrix);
@@ -113,59 +93,31 @@
     assertTrue(m2.getRows() == m1.getRows());
     assertTrue(m2.getColumns() == m1.getColumns());
 
-    checkMatrix(m2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
+    checkMatrix(m2, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testSelfAdd() {
-    GeneralSquareMatrix m1 = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
-
-    GeneralSquareMatrix m2 = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - 0.03 * j;
-        }
-      });
+    GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
+
+    GeneralSquareMatrix m2 = buildMatrix(5, new BilinearPattern(2, -0.03));
 
 
     m1.selfAdd(m2);
 
-    checkMatrix(m1, new ElementPattern() {
-        public double value(int i, int j) {
-          return 3 * i - 0.02 * j;
-        }
-      });
+    checkMatrix(m1, new BilinearPattern(3, -0.02));
 
   }
 
   public void testSelfSub() {
-    GeneralSquareMatrix m1 = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.01 * j;
-        }
-      });
-
-    GeneralSquareMatrix m2 = buildMatrix(5, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - 0.03 * j;
-        }
-      });
+    GeneralSquareMatrix m1 = buildMatrix(5, new BilinearPattern(1.0, 0.01));
+
+    GeneralSquareMatrix m2 = buildMatrix(5, new BilinearPattern(2, -0.03));
 
 
     m1.selfSub(m2);
 
-    checkMatrix(m1, new ElementPattern() {
-        public double value(int i, int j) {
-          return 0.04 * j - i;
-        }
-      });
+    checkMatrix(m1, new BilinearPattern(-1, 0.04));
 
   }
 
@@ -196,15 +148,16 @@
     result = p.a.solve(p.b, 1.0e-10);
     checkSolve(p, result);
 
-    boolean gotIt = false;
     try {
       p = buildProblem3();
       result = p.a.solve(p.b, 1.0e-10);
+      fail("got " + result + ", should have caught an exception");
     } catch(SingularMatrixException e) {
-      gotIt = true;
+      // expected
+    } catch(Exception e) {
+      fail("wrong exception caught: " + e.getMessage());
     }
-    assertTrue(gotIt);
-
+ 
   }
 
   public void testInverse()
@@ -214,28 +167,21 @@
 
     a = buildProblem1().a;
     inverse = a.getInverse(1.0e-10);
-    checkMatrix(a.mul(inverse), new ElementPattern() {
-        public double value(int i, int j) {
-          return (i == j) ? 1.0 : 0.0;
-        }
-      });
+    checkMatrix(a.mul(inverse), new IdentityPattern());
     
     a = buildProblem2().a;
     inverse = a.getInverse(1.0e-10);
-    checkMatrix(a.mul(inverse), new ElementPattern() {
-        public double value(int i, int j) {
-          return (i == j) ? 1.0 : 0.0;
-        }
-      });
+    checkMatrix(a.mul(inverse), new IdentityPattern());
 
-    boolean gotIt = false;
     try {
       a = buildProblem3().a;
       inverse = a.getInverse(1.0e-10);
+      fail("got " + inverse + ", should have caught an exception");
     } catch(SingularMatrixException e) {
-      gotIt = true;
+      // expected
+    } catch(Exception e) {
+      fail("wrong exception caught: " + e.getMessage());
     }
-    assertTrue(gotIt);
 
   }
 
@@ -243,10 +189,28 @@
     return new TestSuite(GeneralSquareMatrixTest.class);
   }
 
-  public interface ElementPattern {
+  private interface ElementPattern {
     public double value(int i, int j);
   }
 
+  private static class BilinearPattern implements ElementPattern {
+    public BilinearPattern(double coeffI, double coeffJ) {
+      this.coeffI = coeffI;
+      this.coeffJ = coeffJ;
+    }
+    public double value(int i, int j) {
+      return coeffI * i + coeffJ * j;
+    }
+    private final double coeffI;
+    private final double coeffJ;
+  }
+
+  private static class IdentityPattern implements ElementPattern {
+    public double value(int i, int j) {
+      return (i == j) ? 1.0 : 0.0;
+    }
+  }
+
   public GeneralSquareMatrix buildMatrix(int order,
                                          ElementPattern pattern) {
     GeneralSquareMatrix m = new GeneralSquareMatrix(order);
@@ -270,7 +234,7 @@
     }
   }
 
-  private class LinearProblem {
+  private static class LinearProblem {
     public GeneralSquareMatrix a;
     public Matrix              x;
     public Matrix              b;

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java Tue Dec 19 14:11:07 2006
@@ -38,8 +38,7 @@
         } else {
           boolean gotIt = false;
           try {
-            l.setElement
-              (i, j, -1.3);
+            l.setElement(i, j, -1.3);
           } catch(ArrayIndexOutOfBoundsException e) {
             gotIt = true;
           }
@@ -48,58 +47,34 @@
       }
     }
 
-    checkMatrix(l, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    checkMatrix(l, new BilinearPattern(1.0, 0.1));
 
   }
 
   public void testCopy() {
 
-    LowerTriangularMatrix l1 = buildMatrix(4, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    LowerTriangularMatrix l1 = buildMatrix(4, new BilinearPattern(1.0, 0.01));
 
     LowerTriangularMatrix l2 = new LowerTriangularMatrix (l1);
 
-    checkMatrix (l2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    checkMatrix (l2, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testDuplicate() {
 
-    LowerTriangularMatrix l1 = buildMatrix(4, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    LowerTriangularMatrix l1 = buildMatrix(4, new BilinearPattern(1.0, 0.01));
 
     Matrix l2 = l1.duplicate();
     assertTrue(l2 instanceof LowerTriangularMatrix);
 
-    checkMatrix(l2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    checkMatrix(l2, new BilinearPattern(1.0, 0.01));
 
   }
 
   public void testTranspose() {
 
-    LowerTriangularMatrix l = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    LowerTriangularMatrix l = buildMatrix(7, new BilinearPattern(1.0, 0.1));
 
     Matrix transposed = l.getTranspose();
     assertTrue(transposed instanceof UpperTriangularMatrix);
@@ -114,46 +89,23 @@
   }
 
   public void testSelfAdd() {
-    LowerTriangularMatrix l1 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 3 * i - 0.2 * j;
-        }
-      });
+    LowerTriangularMatrix l1 = buildMatrix(7, new BilinearPattern(3, -0.2));
 
-    LowerTriangularMatrix l2 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - 0.4 * j; }
-      });
+    LowerTriangularMatrix l2 = buildMatrix(7, new BilinearPattern(2, -0.4));
 
     l1.selfAdd(l2);
 
-    checkMatrix(l1, new ElementPattern() {
-        public double value(int i, int j) {
-          return 5 * i - 0.6 * j;
-        }
-      });
+    checkMatrix(l1, new BilinearPattern(5, -0.6));
   }
 
   public void testSelfSub() {
-    LowerTriangularMatrix l1 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 3 * i - 0.2 * j;
-        }
-      });
+    LowerTriangularMatrix l1 = buildMatrix(7, new BilinearPattern(3, -0.2));
 
-    LowerTriangularMatrix l2 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - 0.4 * j;
-        }
-      });
+    LowerTriangularMatrix l2 = buildMatrix(7, new BilinearPattern(2, -0.4));
 
     l1.selfSub(l2);
 
-    checkMatrix(l1, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.2 * j;
-        }
-      });
+    checkMatrix(l1, new BilinearPattern(1, 0.2));
   }
 
   public void testDeterminant() {
@@ -199,7 +151,7 @@
     boolean gotIt = false;
     try {
       l.setElement(3, 3, 0.0);
-      result = l.solve(b, 1.0e-10);
+      l.solve(b, 1.0e-10);
     } catch(SingularMatrixException e) {
       gotIt = true;
     }
@@ -233,6 +185,18 @@
 
   public interface ElementPattern {
     public double value(int i, int j);
+  }
+
+  private static class BilinearPattern implements ElementPattern {
+    public BilinearPattern(double coeffI, double coeffJ) {
+      this.coeffI = coeffI;
+      this.coeffJ = coeffJ;
+    }
+    public double value(int i, int j) {
+      return coeffI * i + coeffJ * j;
+    }
+    private final double coeffI;
+    private final double coeffJ;
   }
 
   public LowerTriangularMatrix buildMatrix(int order,

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java Tue Dec 19 14:11:07 2006
@@ -46,58 +46,34 @@
       }
     }
 
-    checkMatrix(u, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    checkMatrix(u, new BilinearPattern(1.0, 0.1));
 
   }
 
   public void testCopy() {
 
-    UpperTriangularMatrix u1 = buildMatrix(4, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    UpperTriangularMatrix u1 = buildMatrix(4, new BilinearPattern(1.0, 0.1));
 
     UpperTriangularMatrix u2 = new UpperTriangularMatrix(u1);
 
-    checkMatrix(u2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    checkMatrix(u2, new BilinearPattern(1.0, 0.1));
 
   }
 
   public void testDuplicate() {
 
-    UpperTriangularMatrix u1 = buildMatrix(4, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    UpperTriangularMatrix u1 = buildMatrix(4, new BilinearPattern(1.0, 0.1));
 
     Matrix u2 = u1.duplicate();
     assertTrue(u2 instanceof UpperTriangularMatrix);
 
-    checkMatrix(u2, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    checkMatrix(u2, new BilinearPattern(1.0, 0.1));
 
   }
 
   public void testTranspose() {
 
-    UpperTriangularMatrix u = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.1 * j;
-        }
-      });
+    UpperTriangularMatrix u = buildMatrix(7, new BilinearPattern(1.0, 0.1));
 
     Matrix transposed = u.getTranspose();
     assertTrue(transposed instanceof LowerTriangularMatrix);
@@ -112,47 +88,23 @@
   }
 
   public void testSelfAdd() {
-    UpperTriangularMatrix u1 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 3 * i - 0.2 * j;
-        }
-      });
+    UpperTriangularMatrix u1 = buildMatrix(7, new BilinearPattern(3, -0.2));
 
-    UpperTriangularMatrix u2 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - 0.4 * j;
-        }
-      });
+    UpperTriangularMatrix u2 = buildMatrix(7, new BilinearPattern(2, -0.4));
 
     u1.selfAdd(u2);
 
-    checkMatrix(u1, new ElementPattern() {
-        public double value(int i, int j) {
-          return 5 * i - 0.6 * j;
-        }
-      });
+    checkMatrix(u1, new BilinearPattern(5, -0.6));
   }
 
   public void testSelfSub() {
-    UpperTriangularMatrix u1 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 3 * i - 0.2 * j;
-        }
-      });
+    UpperTriangularMatrix u1 = buildMatrix(7, new BilinearPattern(3, -0.2));
 
-    UpperTriangularMatrix u2 = buildMatrix(7, new ElementPattern() {
-        public double value(int i, int j) {
-          return 2 * i - 0.4 * j;
-        }
-      });
+    UpperTriangularMatrix u2 = buildMatrix(7, new BilinearPattern(2, -0.4));
 
     u1.selfSub(u2);
 
-    checkMatrix(u1, new ElementPattern() {
-        public double value(int i, int j) {
-          return i + 0.2 * j;
-        }
-      });
+    checkMatrix(u1, new BilinearPattern(1, 0.2));
   }
 
   public void testDeterminant() {
@@ -199,7 +151,7 @@
     boolean gotIt = false;
     try {
       u.setElement(3, 3, 0.0);
-      result = u.solve(b, 1.0e-10);
+      u.solve(b, 1.0e-10);
     } catch(SingularMatrixException e) {
       gotIt = true;
     }
@@ -233,6 +185,18 @@
 
   public interface ElementPattern {
     public double value(int i, int j);
+  }
+
+  private static class BilinearPattern implements ElementPattern {
+    public BilinearPattern(double coeffI, double coeffJ) {
+      this.coeffI = coeffI;
+      this.coeffJ = coeffJ;
+    }
+    public double value(int i, int j) {
+      return coeffI * i + coeffJ * j;
+    }
+    private final double coeffI;
+    private final double coeffJ;
   }
 
   public UpperTriangularMatrix buildMatrix(int order,

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -20,6 +20,7 @@
 import junit.framework.*;
 
 import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
 import org.spaceroots.mantissa.fitting.PolynomialFitter;
 
 public class ClassicalRungeKuttaIntegratorTest
@@ -72,11 +73,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
@@ -95,9 +94,8 @@
   public void testOrder()
   throws EstimationException, DerivativeException,
          IntegratorException {
-    PolynomialFitter fitter = new PolynomialFitter(1,
-                                                   10, 1.0e-7, 1.0e-10,
-                                                   1.0e-10);
+    PolynomialFitter fitter =
+      new PolynomialFitter(1, new LevenbergMarquardtEstimator());
 
     TestProblemAbstract[] problems = TestProblemFactory.getProblems();
     for (int k = 0; k < problems.length; ++k) {
@@ -112,11 +110,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
@@ -177,36 +173,43 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003;
 
     FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
-    integ.setStepHandler(new StepHandler() {
-                      private double maxError = 0;
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                        maxError = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-
-                        double[] interpolatedY = interpolator.getInterpolatedState ();
-                        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
-                        double dx = interpolatedY[0] - theoreticalY[0];
-                        double dy = interpolatedY[1] - theoreticalY[1];
-                        double error = dx * dx + dy * dy;
-                        if (error > maxError) {
-                          maxError = error;
-                        }
-                        if (isLast) {
-                          // even with more than 1000 evaluations per period,
-                          // RK4 is not able to integrate such an eccentric
-                          // orbit with a good accuracy
-                          assertTrue(maxError > 0.005);
-                        }
-                      }
-      });
+    integ.setStepHandler(new KeplerHandler(pb));
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  private static class KeplerHandler implements StepHandler {
+    public KeplerHandler(TestProblem3 pb) {
+      this.pb = pb;
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+    public void reset() {
+      maxError = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast) {
+
+      double[] interpolatedY = interpolator.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+      if (isLast) {
+        // even with more than 1000 evaluations per period,
+        // RK4 is not able to integrate such an eccentric
+        // orbit with a good accuracy
+        assertTrue(maxError > 0.005);
+      }
+    }
+    private double maxError = 0;
+    private TestProblem3 pb;
   }
 
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java Tue Dec 19 14:11:07 2006
@@ -25,6 +25,8 @@
 
   public ContinuousOutputModelTest(String name) {
     super(name);
+    pb    = null;
+    integ = null;
   }
 
   public void testBoundaries()

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -91,7 +91,7 @@
 
   }
 
-  private class DP54SmallLastHandler implements StepHandler {
+  private static class DP54SmallLastHandler implements StepHandler {
 
     public DP54SmallLastHandler(double minStep) {
       lastSeen = false;
@@ -170,11 +170,9 @@
     TestProblemHandler handler = new TestProblemHandler(pb);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
-    if (functions != null) {
-      for (int l = 0; l < functions.length; ++l) {
-        integ.addSwitchingFunction(functions[l],
-                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
-      }
+    for (int l = 0; l < functions.length; ++l) {
+      integ.addSwitchingFunction(functions[l],
+                                 Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
     }
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
@@ -197,43 +195,7 @@
     FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private int nbSteps = 0;
-                      private double maxError = 0;
-                      public boolean requiresDenseOutput() {
-                        return true;
-                      }
-                      public void reset() {
-                        nbSteps = 0;
-                        maxError = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast)
-                        throws DerivativeException {
-
-                        ++nbSteps;
-                        for (int a = 1; a < 10; ++a) {
-
-                          double prev   = interpolator.getPreviousTime();
-                          double curr   = interpolator.getCurrentTime();
-                          double interp = ((10 - a) * prev + a * curr) / 10;
-                          interpolator.setInterpolatedTime(interp);
-
-                          double[] interpolatedY = interpolator.getInterpolatedState ();
-                          double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
-                          double dx = interpolatedY[0] - theoreticalY[0];
-                          double dy = interpolatedY[1] - theoreticalY[1];
-                          double error = dx * dx + dy * dy;
-                          if (error > maxError) {
-                            maxError = error;
-                          }
-                        }
-                        if (isLast) {
-                          assertTrue(maxError < 7.0e-10);
-                          assertTrue(nbSteps < 400);
-                        }
-                      }
-      });
+    integ.setStepHandler(new KeplerHandler(pb));
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
@@ -254,45 +216,95 @@
     FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private boolean firstTime = true;
-                      private double  minStep = 0;
-                      private double  maxStep = 0;
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                        firstTime = true;
-                        minStep = 0;
-                        maxStep = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-
-                        double step = Math.abs(interpolator.getCurrentTime()
-                                               - interpolator.getPreviousTime());
-                        if (firstTime) {
-                          minStep   = Math.abs(step);
-                          maxStep   = minStep;
-                          firstTime = false;
-                        } else {
-                          if (step < minStep) {
-                            minStep = step;
-                          }
-                          if (step > maxStep) {
-                            maxStep = step;
-                          }
-                        }
-
-                        if (isLast) {
-                          assertTrue(minStep < (1.0 / 450.0));
-                          assertTrue(maxStep > (1.0 / 4.2));
-                        }
-                      }
-      });
+    integ.setStepHandler(new VariableHandler());
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  private static class KeplerHandler implements StepHandler {
+    public KeplerHandler(TestProblem3 pb) {
+      this.pb = pb;
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return true;
+    }
+    public void reset() {
+      nbSteps = 0;
+      maxError = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast)
+    throws DerivativeException {
+
+      ++nbSteps;
+      for (int a = 1; a < 10; ++a) {
+
+        double prev   = interpolator.getPreviousTime();
+        double curr   = interpolator.getCurrentTime();
+        double interp = ((10 - a) * prev + a * curr) / 10;
+        interpolator.setInterpolatedTime(interp);
+
+        double[] interpolatedY = interpolator.getInterpolatedState ();
+        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
+        double dx = interpolatedY[0] - theoreticalY[0];
+        double dy = interpolatedY[1] - theoreticalY[1];
+        double error = dx * dx + dy * dy;
+        if (error > maxError) {
+          maxError = error;
+        }
+      }
+      if (isLast) {
+        assertTrue(maxError < 7.0e-10);
+        assertTrue(nbSteps < 400);
+      }
+    }
+    private int nbSteps;
+    private double maxError;
+    private TestProblem3 pb;
+  }
+
+  private static class VariableHandler implements StepHandler {
+    public VariableHandler() {
+      firstTime = true;
+      minStep = 0;
+      maxStep = 0;
+    }
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+    public void reset() {
+      firstTime = true;
+      minStep = 0;
+      maxStep = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast) {
+
+      double step = Math.abs(interpolator.getCurrentTime()
+                             - interpolator.getPreviousTime());
+      if (firstTime) {
+        minStep   = Math.abs(step);
+        maxStep   = minStep;
+        firstTime = false;
+      } else {
+        if (step < minStep) {
+          minStep = step;
+        }
+        if (step > maxStep) {
+          maxStep = step;
+        }
+      }
+
+      if (isLast) {
+        assertTrue(minStep < (1.0 / 450.0));
+        assertTrue(maxStep > (1.0 / 4.2));
+      }
+    }  
+    private boolean firstTime;
+    private double  minStep;
+    private double  maxStep;
   }
 
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -130,11 +130,9 @@
     TestProblemHandler handler = new TestProblemHandler(pb);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
-    if (functions != null) {
-      for (int l = 0; l < functions.length; ++l) {
-        integ.addSwitchingFunction(functions[l],
-                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
-      }
+    for (int l = 0; l < functions.length; ++l) {
+      integ.addSwitchingFunction(functions[l],
+                                 Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
     }
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
@@ -157,43 +155,7 @@
     FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                 scalAbsoluteTolerance,
                                                                 scalRelativeTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private int nbSteps = 0;
-                      private double maxError = 0;
-                      public boolean requiresDenseOutput() {
-                        return true;
-                      }
-                      public void reset() {
-                        nbSteps = 0;
-                        maxError = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast)
-                        throws DerivativeException {
-
-                        ++nbSteps;
-                        for (int a = 1; a < 10; ++a) {
-
-                          double prev   = interpolator.getPreviousTime();
-                          double curr   = interpolator.getCurrentTime();
-                          double interp = ((10 - a) * prev + a * curr) / 10;
-                          interpolator.setInterpolatedTime(interp);
-
-                          double[] interpolatedY = interpolator.getInterpolatedState ();
-                          double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
-                          double dx = interpolatedY[0] - theoreticalY[0];
-                          double dy = interpolatedY[1] - theoreticalY[1];
-                          double error = dx * dx + dy * dy;
-                          if (error > maxError) {
-                            maxError = error;
-                          }
-                        }
-                        if (isLast) {
-                          assertTrue(maxError < 2.4e-10);
-                          assertTrue(nbSteps < 150);
-                        }
-                      }
-      });
+    integ.setStepHandler(new KeplerHandler(pb));
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
@@ -214,42 +176,7 @@
     FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private boolean firstTime = true;
-                      private double  minStep = 0;
-                      private double  maxStep = 0;
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                        firstTime = true;
-                        minStep = 0;
-                        maxStep = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-
-                        double step = Math.abs(interpolator.getCurrentTime()
-                                               - interpolator.getPreviousTime());
-                        if (firstTime) {
-                          minStep   = Math.abs(step);
-                          maxStep   = minStep;
-                          firstTime = false;
-                        } else {
-                          if (step < minStep) {
-                            minStep = step;
-                          }
-                          if (step > maxStep) {
-                            maxStep = step;
-                          }
-                        }
-
-                        if (isLast) {
-                          assertTrue(minStep < (1.0 / 100.0));
-                          assertTrue(maxStep > (1.0 / 2.0));
-                        }
-                      }
-      });
+    integ.setStepHandler(new VariableHandler());
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
@@ -267,35 +194,13 @@
     FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                 scalAbsoluteTolerance,
                                                                 scalRelativeTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-                      }
-      });
+    integ.setStepHandler(DummyStepHandler.getInstance());
     integ.integrate(pb1,
                     pb1.getInitialTime(), pb1.getInitialState(),
                     pb1.getFinalTime(), new double[pb1.getDimension()]);
     int callsWithoutDenseOutput = pb1.getCalls();
 
-    integ.setStepHandler(new StepHandler() {
-                      public boolean requiresDenseOutput() {
-                        return true;
-                      }
-                      public void reset() {
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast)
-                        throws DerivativeException {
-                        double prev = interpolator.getPreviousTime();
-                        double curr = interpolator.getCurrentTime();
-                        interpolator.setInterpolatedTime(0.5*(prev + curr));
-                      }
-      });
+    integ.setStepHandler(new InterpolatingStepHandler());
     integ.integrate(pb2,
                     pb2.getInitialTime(), pb2.getInitialState(),
                     pb2.getFinalTime(), new double[pb2.getDimension()]);
@@ -314,6 +219,104 @@
     double[] y = { Double.NaN };
     integ.integrate(stepProblem, 0.0, new double[] { 0.0 }, 10.0, y);
     assertEquals(8.0, y[0], 1.0e-12);
+  }
+
+  private static class KeplerHandler implements StepHandler {
+    public KeplerHandler(TestProblem3 pb) {
+      this.pb = pb;
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return true;
+    }
+    public void reset() {
+      nbSteps = 0;
+      maxError = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast)
+    throws DerivativeException {
+
+      ++nbSteps;
+      for (int a = 1; a < 10; ++a) {
+
+        double prev   = interpolator.getPreviousTime();
+        double curr   = interpolator.getCurrentTime();
+        double interp = ((10 - a) * prev + a * curr) / 10;
+        interpolator.setInterpolatedTime(interp);
+
+        double[] interpolatedY = interpolator.getInterpolatedState ();
+        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
+        double dx = interpolatedY[0] - theoreticalY[0];
+        double dy = interpolatedY[1] - theoreticalY[1];
+        double error = dx * dx + dy * dy;
+        if (error > maxError) {
+          maxError = error;
+        }
+      }
+      if (isLast) {
+        assertTrue(maxError < 2.4e-10);
+        assertTrue(nbSteps < 150);
+      }
+    }
+    private int nbSteps;
+    private double maxError;
+    private TestProblem3 pb;
+  }
+
+  private static class VariableHandler implements StepHandler {
+    public VariableHandler() {
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+    public void reset() {
+      firstTime = true;
+      minStep = 0;
+      maxStep = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast) {
+
+      double step = Math.abs(interpolator.getCurrentTime()
+                             - interpolator.getPreviousTime());
+      if (firstTime) {
+        minStep   = Math.abs(step);
+        maxStep   = minStep;
+        firstTime = false;
+      } else {
+        if (step < minStep) {
+          minStep = step;
+        }
+        if (step > maxStep) {
+          maxStep = step;
+        }
+      }
+
+      if (isLast) {
+        assertTrue(minStep < (1.0 / 100.0));
+        assertTrue(maxStep > (1.0 / 2.0));
+      }
+    }
+    private boolean firstTime = true;
+    private double  minStep = 0;
+    private double  maxStep = 0;
+  }
+
+  private static class InterpolatingStepHandler implements StepHandler {
+    public boolean requiresDenseOutput() {
+      return true;
+    }
+    public void reset() {
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast)
+    throws DerivativeException {
+      double prev = interpolator.getPreviousTime();
+      double curr = interpolator.getCurrentTime();
+      interpolator.setInterpolatedTime(0.5*(prev + curr));
+    }
   }
 
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -20,6 +20,7 @@
 import junit.framework.*;
 
 import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
 import org.spaceroots.mantissa.fitting.PolynomialFitter;
 
 public class EulerIntegratorTest
@@ -59,11 +60,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb,
                         pb.getInitialTime(), pb.getInitialState(),
@@ -84,9 +83,8 @@
   public void testOrder()
   throws EstimationException, DerivativeException,
          IntegratorException {
-    PolynomialFitter fitter = new PolynomialFitter(1,
-                                                   10, 1.0e-7, 1.0e-10,
-                                                   1.0e-10);
+    PolynomialFitter fitter =
+      new PolynomialFitter(1, new LevenbergMarquardtEstimator());
 
     TestProblemAbstract[] problems = TestProblemFactory.getProblems();
     for (int k = 0; k < problems.length; ++k) {
@@ -101,11 +99,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb,
                         pb.getInitialTime(), pb.getInitialState(),

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java Tue Dec 19 14:11:07 2006
@@ -55,8 +55,7 @@
     double   t0 = 0;
     double[] y0 = {0.0, 1.0, -2.0};
 
-    double[] y = new double[y0.length];
-    System.arraycopy(y0, 0, y, 0, y0.length);
+    double[] y = (double[]) y0.clone();
     double[][] yDot = { new double[y0.length] };
     EulerStepInterpolator interpolator = new EulerStepInterpolator();
     interpolator.reinitialize(new DummyEquations(), y, yDot, true);
@@ -154,7 +153,7 @@
 
   }
 
-  private class DummyEquations
+  private static class DummyEquations
     implements FirstOrderDifferentialEquations {
     public int getDimension() {
       return 0;

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java Tue Dec 19 14:11:07 2006
@@ -69,7 +69,7 @@
     return new TestSuite(FirstOrderConverterTest.class);
   }
 
-  private class Equations
+  private static class Equations
     implements SecondOrderDifferentialEquations {
       
       private int n;

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -20,6 +20,7 @@
 import junit.framework.*;
 
 import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
 import org.spaceroots.mantissa.fitting.PolynomialFitter;
 
 public class GillIntegratorTest
@@ -59,11 +60,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
@@ -82,9 +81,8 @@
   public void testOrder()
   throws EstimationException, DerivativeException,
          IntegratorException {
-    PolynomialFitter fitter = new PolynomialFitter(1,
-                                                   10, 1.0e-7, 1.0e-10,
-                                                   1.0e-10);
+    PolynomialFitter fitter =
+      new PolynomialFitter(1, new LevenbergMarquardtEstimator());
 
     TestProblemAbstract[] problems = TestProblemFactory.getProblems();
     for (int k = 0; k < problems.length; ++k) {
@@ -99,11 +97,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
@@ -164,33 +160,7 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003;
 
     FirstOrderIntegrator integ = new GillIntegrator(step);
-    integ.setStepHandler(new StepHandler() {
-                      private double maxError = 0;
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                        maxError = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-
-                        double[] interpolatedY = interpolator.getInterpolatedState ();
-                        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
-                        double dx = interpolatedY[0] - theoreticalY[0];
-                        double dy = interpolatedY[1] - theoreticalY[1];
-                        double error = dx * dx + dy * dy;
-                        if (error > maxError) {
-                          maxError = error;
-                        }
-                        if (isLast) {
-                          // even with more than 1000 evaluations per period,
-                          // RK4 is not able to integrate such an eccentric
-                          // orbit with a good accuracy
-                          assertTrue(maxError > 0.001);
-                        }
-                      }
-      });
+    integ.setStepHandler(new KeplerStepHandler(pb));
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
@@ -204,6 +174,39 @@
     double[] y = { Double.NaN };
     integ.integrate(stepProblem, 0.0, new double[] { 0.0 }, 10.0, y);
     assertEquals(8.0, y[0], 1.0e-12);
+  }
+
+  private static class KeplerStepHandler implements StepHandler {
+    public KeplerStepHandler(TestProblem3 pb) {
+      this.pb = pb;
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+    public void reset() {
+      maxError = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast) {
+
+      double[] interpolatedY = interpolator.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+      if (isLast) {
+        // even with more than 1000 evaluations per period,
+        // RK4 is not able to integrate such an eccentric
+        // orbit with a good accuracy
+        assertTrue(maxError > 0.001);
+      }
+    }
+    private double maxError;
+    private TestProblem3 pb;
   }
 
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -132,11 +132,9 @@
     TestProblemHandler handler = new TestProblemHandler(pb);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
-    if (functions != null) {
-      for (int l = 0; l < functions.length; ++l) {
-        integ.addSwitchingFunction(functions[l],
-                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
-      }
+    for (int l = 0; l < functions.length; ++l) {
+      integ.addSwitchingFunction(functions[l],
+                                 Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
     }
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
@@ -159,43 +157,7 @@
     FirstOrderIntegrator integ =
       new GraggBulirschStoerIntegrator(minStep, maxStep,
                                        absTolerance, relTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private int nbSteps = 0;
-                      private double maxError = 0;
-                      public boolean requiresDenseOutput() {
-                        return true;
-                      }
-                      public void reset() {
-                        nbSteps = 0;
-                        maxError = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast)
-                        throws DerivativeException {
-
-                        ++nbSteps;
-                        for (int a = 1; a < 100; ++a) {
-
-                          double prev   = interpolator.getPreviousTime();
-                          double curr   = interpolator.getCurrentTime();
-                          double interp = ((100 - a) * prev + a * curr) / 100;
-                          interpolator.setInterpolatedTime(interp);
-
-                          double[] interpolatedY = interpolator.getInterpolatedState ();
-                          double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
-                          double dx = interpolatedY[0] - theoreticalY[0];
-                          double dy = interpolatedY[1] - theoreticalY[1];
-                          double error = dx * dx + dy * dy;
-                          if (error > maxError) {
-                            maxError = error;
-                          }
-                        }
-                        if (isLast) {
-                          assertTrue(maxError < 2.7e-6);
-                          assertTrue(nbSteps < 80);
-                        }
-                      }
-      });
+    integ.setStepHandler(new KeplerStepHandler(pb));
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
@@ -215,42 +177,7 @@
     FirstOrderIntegrator integ =
       new GraggBulirschStoerIntegrator(minStep, maxStep,
                                        absTolerance, relTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private boolean firstTime = true;
-                      private double  minStep = 0;
-                      private double  maxStep = 0;
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                        firstTime = true;
-                        minStep = 0;
-                        maxStep = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-
-                        double step = Math.abs(interpolator.getCurrentTime()
-                                               - interpolator.getPreviousTime());
-                        if (firstTime) {
-                          minStep   = Math.abs(step);
-                          maxStep   = minStep;
-                          firstTime = false;
-                        } else {
-                          if (step < minStep) {
-                            minStep = step;
-                          }
-                          if (step > maxStep) {
-                            maxStep = step;
-                          }
-                        }
-
-                        if (isLast) {
-                          assertTrue(minStep < 8.2e-3);
-                          assertTrue(maxStep > 1.7);
-                        }
-                      }
-      });
+    integ.setStepHandler(new VariableStepHandler());
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
@@ -267,6 +194,88 @@
     assertEquals(8.0, y[0], 1.0e-12);
   }
 
+  private static class KeplerStepHandler implements StepHandler {
+    public KeplerStepHandler(TestProblem3 pb) {
+      this.pb = pb;
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return true;
+    }
+    public void reset() {
+      nbSteps = 0;
+      maxError = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast)
+    throws DerivativeException {
+
+      ++nbSteps;
+      for (int a = 1; a < 100; ++a) {
+
+        double prev   = interpolator.getPreviousTime();
+        double curr   = interpolator.getCurrentTime();
+        double interp = ((100 - a) * prev + a * curr) / 100;
+        interpolator.setInterpolatedTime(interp);
+
+        double[] interpolatedY = interpolator.getInterpolatedState ();
+        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
+        double dx = interpolatedY[0] - theoreticalY[0];
+        double dy = interpolatedY[1] - theoreticalY[1];
+        double error = dx * dx + dy * dy;
+        if (error > maxError) {
+          maxError = error;
+        }
+      }
+      if (isLast) {
+        assertTrue(maxError < 2.7e-6);
+        assertTrue(nbSteps < 80);
+      }
+    }
+    private int nbSteps;
+    private double maxError;
+    private TestProblem3 pb;
+  }
+
+  public static class VariableStepHandler implements StepHandler {
+    public VariableStepHandler() {
+      reset();
+    }
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+    public void reset() {
+      firstTime = true;
+      minStep = 0;
+      maxStep = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast) {
+
+      double step = Math.abs(interpolator.getCurrentTime()
+                             - interpolator.getPreviousTime());
+      if (firstTime) {
+        minStep   = Math.abs(step);
+        maxStep   = minStep;
+        firstTime = false;
+      } else {
+        if (step < minStep) {
+          minStep = step;
+        }
+        if (step > maxStep) {
+          maxStep = step;
+        }
+      }
+
+      if (isLast) {
+        assertTrue(minStep < 8.2e-3);
+        assertTrue(maxStep > 1.7);
+      }
+    }
+    private boolean firstTime;
+    private double  minStep;
+    private double  maxStep;
+  }
   public static Test suite() {
     return new TestSuite(GraggBulirschStoerIntegratorTest.class);
   }

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/HighamHall54IntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/HighamHall54IntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/HighamHall54IntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/HighamHall54IntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -115,11 +115,9 @@
     TestProblemHandler handler = new TestProblemHandler(pb);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
-    if (functions != null) {
-      for (int l = 0; l < functions.length; ++l) {
-        integ.addSwitchingFunction(functions[l],
-                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
-      }
+    for (int l = 0; l < functions.length; ++l) {
+      integ.addSwitchingFunction(functions[l],
+                                 Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
     }
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
@@ -142,37 +140,45 @@
     FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                             scalAbsoluteTolerance,
                                                             scalRelativeTolerance);
-    integ.setStepHandler(new StepHandler() {
-                      private int nbSteps = 0;
-                      private double maxError = 0;
-                      public boolean requiresDenseOutput() {
-                        return false;
-                      }
-                      public void reset() {
-                        nbSteps = 0;
-                        maxError = 0;
-                      }
-                      public void handleStep(StepInterpolator interpolator,
-                                             boolean isLast) {
-
-                        ++nbSteps;
-                        double[] interpolatedY = interpolator.getInterpolatedState ();
-                        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
-                        double dx = interpolatedY[0] - theoreticalY[0];
-                        double dy = interpolatedY[1] - theoreticalY[1];
-                        double error = dx * dx + dy * dy;
-                        if (error > maxError) {
-                          maxError = error;
-                        }
-                        if (isLast) {
-                          assertTrue(maxError < 1.54e-10);
-                          assertTrue(nbSteps < 520);
-                        }
-                      }
-      });
+    integ.setStepHandler(new KeplerHandler(pb));
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  private static class KeplerHandler implements StepHandler {
+    public KeplerHandler(TestProblem3 pb) {
+      this.pb = pb;
+      nbSteps = 0;
+      maxError = 0;
+    }
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+    public void reset() {
+      nbSteps = 0;
+      maxError = 0;
+    }
+    public void handleStep(StepInterpolator interpolator,
+                           boolean isLast) {
+
+      ++nbSteps;
+      double[] interpolatedY = interpolator.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+      if (isLast) {
+        assertTrue(maxError < 1.54e-10);
+        assertTrue(nbSteps < 520);
+      }
+    }
+    private TestProblem3 pb;
+    private int nbSteps;
+    private double maxError;
   }
 
   public static Test suite() {

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/MidpointIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/MidpointIntegratorTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/MidpointIntegratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/MidpointIntegratorTest.java Tue Dec 19 14:11:07 2006
@@ -20,6 +20,7 @@
 import junit.framework.*;
 
 import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
 import org.spaceroots.mantissa.fitting.PolynomialFitter;
 
 public class MidpointIntegratorTest
@@ -58,11 +59,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb,
                         pb.getInitialTime(), pb.getInitialState(),
@@ -81,9 +80,8 @@
 
   public void testOrder()
   throws EstimationException, DerivativeException, IntegratorException {
-    PolynomialFitter fitter = new PolynomialFitter(1,
-                                                   10, 1.0e-7, 1.0e-10,
-                                                   1.0e-10);
+    PolynomialFitter fitter =
+      new PolynomialFitter(1, new LevenbergMarquardtEstimator());
 
     TestProblemAbstract[] problems = TestProblemFactory.getProblems();
     for (int k = 0; k < problems.length; ++k) {
@@ -98,11 +96,9 @@
         TestProblemHandler handler = new TestProblemHandler(pb);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
-        if (functions != null) {
-          for (int l = 0; l < functions.length; ++l) {
-            integ.addSwitchingFunction(functions[l],
-                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
-          }
+        for (int l = 0; l < functions.length; ++l) {
+          integ.addSwitchingFunction(functions[l],
+                                     Double.POSITIVE_INFINITY, 1.0e-6 * step);
         }
         integ.integrate(pb,
                         pb.getInitialTime(), pb.getInitialState(),

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/StepNormalizerTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/StepNormalizerTest.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/StepNormalizerTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/StepNormalizerTest.java Tue Dec 19 14:11:07 2006
@@ -24,6 +24,8 @@
 
   public StepNormalizerTest(String name) {
     super(name);
+    pb    = null;
+    integ = null;
   }
 
   public void testBoundaries()

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem1.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem1.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem1.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem1.java Tue Dec 19 14:11:07 2006
@@ -56,8 +56,7 @@
    */
   public TestProblem1(TestProblem1 problem) {
     super(problem);
-    y = new double[problem.y.length];
-    System.arraycopy(problem.y, 0, y, 0, problem.y.length);
+    y = (double[]) problem.y.clone();
   }
 
   /**

Modified: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem2.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem2.java?view=diff&rev=488828&r1=488827&r2=488828
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem2.java (original)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem2.java Tue Dec 19 14:11:07 2006
@@ -57,8 +57,7 @@
    */
   public TestProblem2(TestProblem2 problem) {
     super(problem);
-    y = new double[problem.y.length];
-    System.arraycopy(problem.y, 0, y, 0, problem.y.length);
+    y = (double[]) problem.y.clone();
   }
 
   /**



---------------------------------------------------------------------
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