commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r476930 [19/22] - in /jakarta/commons/proper/math/trunk/src/mantissa: ./ src/ src/org/ src/org/spaceroots/ src/org/spaceroots/mantissa/ src/org/spaceroots/mantissa/algebra/ src/org/spaceroots/mantissa/estimation/ src/org/spaceroots/mantissa...
Date Sun, 19 Nov 2006 21:36:23 GMT
Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,190 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class DiagonalMatrixTest
+  extends TestCase {
+
+  public DiagonalMatrixTest(String name) {
+    super(name);
+  }
+
+  public void testConstantDiagonal() {
+    checkMatrix(new DiagonalMatrix(5, 2.7), 2.7);
+  }
+
+  public void testNoSetOutsideOfDiagonal() {
+
+    DiagonalMatrix d = new DiagonalMatrix(4);
+
+    for (int i = 0; i < d.getRows(); ++i) {
+      for (int j = 0; j < d.getColumns(); ++j) {
+        if (i == j) {
+          d.setElement(i, j, 2.7);
+        } else {
+          boolean gotIt = false;
+          try {
+            d.setElement(i, j, -1.3);
+          } catch (ArrayIndexOutOfBoundsException e) {
+            gotIt = true;
+          }
+          assertTrue(gotIt);
+        }
+      }
+    }
+
+    checkMatrix(d, 2.7);
+
+  }
+
+  public void testCopy() {
+    DiagonalMatrix d1 = new DiagonalMatrix(7, 4.3);
+    DiagonalMatrix d2 = new DiagonalMatrix(d1);
+
+    for (int i = 0; i < d1.getRows(); ++i) {
+      d1.setElement(i, i, -1.0);
+    }
+
+    assertTrue(d2.getRows() == d1.getRows());
+    assertTrue(d2.getColumns() == d1.getColumns());
+
+    checkMatrix(d2, 4.3);
+
+  }
+
+  public void testDuplicate() {
+    DiagonalMatrix d1 = new DiagonalMatrix(6, -8.8);
+
+    Matrix d2 = d1.duplicate();
+    assertTrue(d2 instanceof DiagonalMatrix);
+
+    for (int i = 0; i < d1.getRows(); ++i) {
+      d1.setElement(i, i, -1.0);
+    }
+
+    assertTrue(d2.getRows() == d1.getRows());
+    assertTrue(d2.getColumns() == d1.getColumns());
+
+    checkMatrix(d2, -8.8);
+
+  }
+
+  public void testTranspose() {
+
+    DiagonalMatrix d = new DiagonalMatrix(5, 3.4);
+
+    Matrix transposed = d.getTranspose();
+    assertTrue(transposed instanceof DiagonalMatrix);
+
+    checkMatrix(transposed, 3.4);
+
+  }
+
+  public void testDeterminant() {
+
+    double expected;
+
+    expected = 1.0;
+    for (int k = 1; k < 10; ++k) {
+      expected *= 2;
+      DiagonalMatrix d = new DiagonalMatrix(k, 2.0);
+      assertTrue(Math.abs(d.getDeterminant(1.0e-10) - expected) < 1.0e-10);
+    }
+
+    expected = 1.0;
+    for (int k = 1; k < 10; ++k) {
+      expected *= k;
+      DiagonalMatrix d = new DiagonalMatrix(k);
+      for (int i = 0; i < k; ++i) {
+        d.setElement(i, i, i + 1);
+      }
+      assertTrue(Math.abs(d.getDeterminant(1.0e-10) - expected) < 1.0e-10);
+    }
+
+  }
+
+  public void testSolve()
+    throws SingularMatrixException {
+
+    DiagonalMatrix d = new DiagonalMatrix(6);
+    for (int i = 0; i < d.getRows(); ++i) {
+      d.setElement(i, i, i + 1.0);
+    }
+
+    GeneralMatrix b = new GeneralMatrix(6, 3);
+    for (int i = 0; i < b.getRows(); ++i) {
+      b.setElement(i, 0, i + 1.0);
+      b.setElement(i, 1, (i + 1.0) * (i + 1.0));
+      b.setElement(i, 2, 0.0);
+    }
+
+    Matrix result = d.solve(b, 1.0e-10);
+
+    assertTrue(result.getRows() == b.getRows());
+    assertTrue(result.getColumns() == b.getColumns());
+
+    for (int i = 0; i < result.getRows(); ++i) {
+      assertTrue(Math.abs(result.getElement(i, 0) - 1.0)       < 1.0e-10);
+      assertTrue(Math.abs(result.getElement(i, 1) - (i + 1.0)) < 1.0e-10);
+      assertTrue(Math.abs(result.getElement(i, 2) - 0.0)       < 1.0e-10);
+    }
+
+    boolean gotIt = false;
+    try {
+      d.setElement(3, 3, 0.0);
+      result = d.solve(b, 1.0e-10);
+    } catch (SingularMatrixException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public void testInverse()
+    throws SingularMatrixException {
+
+    DiagonalMatrix d = new DiagonalMatrix(4);
+    for (int i = 0; i < d.getRows (); ++i) {
+      d.setElement(i, i, i + 1.0);
+    }
+
+    Matrix inverse = d.getInverse(1.0e-10);
+    assertTrue(inverse instanceof DiagonalMatrix);
+
+    for (int i = 0; i < inverse.getRows(); ++i) {
+      assertTrue(Math.abs(inverse.getElement(i, i) - 1.0 / (i + 1.0)) < 1.0e-10);
+    }
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(DiagonalMatrixTest.class);
+  }
+
+  public void checkMatrix(Matrix d, double value) {
+    for (int i = 0; i < d.getRows(); ++i) {
+      for (int j = 0; j < d.getColumns(); ++j) {
+        double expected = (i == j) ? value : 0.0;
+        assertTrue(Math.abs(d.getElement(i, j) - expected) < 1.0e-10);
+      }
+    }
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/DiagonalMatrixTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,373 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class GeneralMatrixTest
+  extends TestCase {
+
+  public GeneralMatrixTest(String name) {
+    super(name);
+  }
+
+  public void testDimensions() {
+    GeneralMatrix m = new GeneralMatrix(3, 4);
+    assertTrue(m.getRows() == 3);
+    assertTrue(m.getColumns() == 4);
+  }
+
+  public void testInvalidDimensions() {
+    boolean gotIt;
+
+    gotIt = false;
+    try {
+      new GeneralMatrix(0, 2);
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+    gotIt = false;
+    try {
+      new GeneralMatrix(1, -3, null);
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  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;
+        }
+      });
+
+  }
+
+  public void testCopy() {
+    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    GeneralMatrix m2 = new GeneralMatrix(m1);
+
+    for (int i = 0; i < m1.getRows(); ++i) {
+      for (int j = 0; j < m1.getColumns(); ++j) {
+        m1.setElement(i, j, -1.0);
+      }
+    }
+
+    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;
+        }
+      });
+
+  }
+
+  public void testDuplicate() {
+    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = m1.duplicate();
+    assertTrue(m2 instanceof GeneralMatrix);
+
+    for (int i = 0; i < m1.getRows(); ++i) {
+      for (int j = 0; j < m1.getColumns(); ++j) {
+        m1.setElement(i, j, -1.0);
+      }
+    }
+
+    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;
+        }
+      });
+
+  }
+
+  public void testAddKO() {
+    boolean gotIt = false;
+    try {
+      new GeneralMatrix(2, 3).add(new GeneralMatrix(3, 2));
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+  }
+
+  public void testAddOK() {
+
+    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = buildMatrix(m1.getRows(),
+                            m1.getColumns(),
+                            new ElementPattern() {
+                              public double value(int i, int j) {
+                                return 100 * i - 0.01 * j;
+                              }
+                            });
+
+    Matrix m3 = m1.add(m2);
+
+    checkMatrix(m3, new ElementPattern() {
+        public double value(int i, int j) {
+          return 101 * i;
+        }
+      });
+
+  }
+
+  public void testSelfAdd() {
+
+    GeneralMatrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = buildMatrix(m1.getRows(),
+                            m1.getColumns(),
+                            new ElementPattern() {
+                              public double value(int i, int j) {
+                                return 100 * i - 0.01 * j;
+                              }
+                            });
+
+    m1.selfAdd(m2);
+
+    checkMatrix(m1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 101 * i;
+        }
+      });
+
+  }
+
+  public void testSubKO() {
+    boolean gotIt = false;
+    try {
+      new GeneralMatrix(2, 3).sub(new GeneralMatrix(3, 2));
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+  }
+
+  public void testSubOK() {
+
+    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = buildMatrix(m1.getRows(),
+                            m1.getColumns(),
+                            new ElementPattern() {
+                              public double value(int i, int j) {
+                                return 100 * i - 0.01 * j;
+                              }
+                            });
+
+    Matrix m3 = m1.sub(m2);
+
+    checkMatrix(m3, new ElementPattern() {
+        public double value(int i, int j) {
+          return 0.02 * j - 99 * i;
+        }
+      });
+
+  }
+
+  public void testSelfSub() {
+
+    GeneralMatrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = buildMatrix(m1.getRows(),
+                            m1.getColumns(),
+                            new ElementPattern() {
+                              public double value(int i, int j) {
+                                return 100 * i - 0.01 * j;
+                              }
+                            });
+
+    m1.selfSub(m2);
+
+    checkMatrix(m1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 0.02 * j - 99 * i;
+        }
+      });
+
+  }
+
+  public void testMulMKO() {
+    boolean gotIt = false;
+    try {
+      new GeneralMatrix(2, 3).mul(new GeneralMatrix(2, 3));
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+  }
+
+  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 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);
+        }
+      });
+
+  }
+
+  public void testMulD() {
+
+    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = m1.mul(2.5);
+
+    checkMatrix(m2, new ElementPattern() {
+        public double value(int i, int j) {
+          return 2.5 * (i + 0.01 * j);
+        }
+      });
+
+  }
+
+  public void testSelfMul() {
+
+    Matrix m = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    m.selfMul(2.5);
+
+    checkMatrix(m, new ElementPattern() {
+        public double value(int i, int j) {
+          return 2.5 * (i + 0.01 * j);
+        }
+      });
+
+  }
+
+  public void testTranspose() {
+
+    Matrix m1 = buildMatrix(5, 10, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    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;
+        }
+      });
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(GeneralMatrixTest.class);
+  }
+
+  public interface ElementPattern {
+    public double value(int i, int j);
+  }
+
+  public GeneralMatrix buildMatrix(int rows, int columns,
+                                   ElementPattern pattern) {
+    GeneralMatrix m = new GeneralMatrix(rows, columns);
+
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j){
+        m.setElement(i, j, pattern.value(i, j));
+      }
+    }
+
+    return m;
+
+  }
+
+  public void checkMatrix(Matrix m, ElementPattern pattern) {
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j) {
+        assertTrue(Math.abs(m.getElement(i, j) - pattern.value(i, j))
+                   < 1.0e-10);
+      }
+    }
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralMatrixTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,402 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class GeneralSquareMatrixTest
+  extends TestCase {
+
+  public GeneralSquareMatrixTest(String name) {
+    super(name);
+  }
+
+  public void testDimensions() {
+    GeneralSquareMatrix m = new GeneralSquareMatrix(3);
+    assertTrue(m.getRows() == 3);
+    assertTrue(m.getColumns() == 3);
+  }
+
+  public void testInvalidDimensions() {
+    boolean gotIt;
+
+    gotIt = false;
+    try {
+      new GeneralSquareMatrix(0);
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+    gotIt = false;
+    try {
+      new GeneralSquareMatrix(-3, null);
+    } catch(IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  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;
+        }
+      });
+
+  }
+
+  public void testCopy() {
+    GeneralSquareMatrix m1 = buildMatrix(5, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    GeneralSquareMatrix m2 = new GeneralSquareMatrix(m1);
+
+    for (int i = 0; i < m1.getRows(); ++i) {
+      for (int j = 0; j < m1.getColumns(); ++j) {
+        m1.setElement(i, j, -1.0);
+      }
+    }
+
+    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;
+        }
+      });
+
+  }
+
+  public void testDuplicate() {
+    GeneralSquareMatrix m1 = buildMatrix(5, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.01 * j;
+        }
+      });
+
+    Matrix m2 = m1.duplicate();
+    assertTrue(m2 instanceof GeneralSquareMatrix);
+
+    for (int i = 0; i < m1.getRows(); ++i) {
+      for (int j = 0; j < m1.getColumns(); ++j) {
+        m1.setElement(i, j, -1.0);
+      }
+    }
+
+    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;
+        }
+      });
+
+  }
+
+  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;
+        }
+      });
+
+
+    m1.selfAdd(m2);
+
+    checkMatrix(m1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 3 * i - 0.02 * j;
+        }
+      });
+
+  }
+
+  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;
+        }
+      });
+
+
+    m1.selfSub(m2);
+
+    checkMatrix(m1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 0.04 * j - i;
+        }
+      });
+
+  }
+
+  public void testDeterminant() {
+
+    GeneralSquareMatrix m1 = buildProblem1().a;
+    assertTrue(Math.abs(m1.getDeterminant(1.0e-10) - 6.0) < 1.0e-10);
+
+    GeneralSquareMatrix m2 = buildProblem2().a;
+    assertTrue(Math.abs(m2.getDeterminant(1.0e-10) + 0.9999999) < 1.0e-10);
+
+    GeneralSquareMatrix m3 = buildProblem3().a;
+    assertTrue(Math.abs(m3.getDeterminant(1.0e-10) - 0.0) < 1.0e-10);
+
+  }
+
+  public void testSolve()
+    throws SingularMatrixException {
+
+    LinearProblem p;
+    Matrix result;
+
+    p = buildProblem1();
+    result = p.a.solve(p.b, 1.0e-10);
+    checkSolve(p, result);
+
+    p = buildProblem2();
+    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);
+    } catch(SingularMatrixException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public void testInverse()
+    throws SingularMatrixException {
+
+    SquareMatrix a, inverse;
+
+    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;
+        }
+      });
+    
+    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;
+        }
+      });
+
+    boolean gotIt = false;
+    try {
+      a = buildProblem3().a;
+      inverse = a.getInverse(1.0e-10);
+    } catch(SingularMatrixException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(GeneralSquareMatrixTest.class);
+  }
+
+  public interface ElementPattern {
+    public double value(int i, int j);
+  }
+
+  public GeneralSquareMatrix buildMatrix(int order,
+                                         ElementPattern pattern) {
+    GeneralSquareMatrix m = new GeneralSquareMatrix(order);
+
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j){
+        m.setElement(i, j, pattern.value(i, j));
+      }
+    }
+
+    return m;
+
+  }
+
+  public void checkMatrix(Matrix m, ElementPattern pattern) {
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j) {
+        assertTrue(Math.abs(m.getElement(i, j) - pattern.value(i, j))
+                   < 1.0e-10);
+      }
+    }
+  }
+
+  private class LinearProblem {
+    public GeneralSquareMatrix a;
+    public Matrix              x;
+    public Matrix              b;
+    public LinearProblem(GeneralSquareMatrix a, Matrix x, Matrix b) {
+      this.a = a;
+      this.x = x;
+      this.b = b;
+    }
+  }
+
+  private LinearProblem buildProblem1() {
+
+    GeneralSquareMatrix a = new GeneralSquareMatrix(4);
+
+    a.setElement(0, 0,   2.0);
+    a.setElement(0, 1,   1.0);
+    a.setElement(0, 2,   0.0);
+    a.setElement(0, 3,   4.0);
+
+    a.setElement(1, 0,  -4.0);
+    a.setElement(1, 1,  -2.0);
+    a.setElement(1, 2,   3.0);
+    a.setElement(1, 3,  -7.0);
+
+    a.setElement(2, 0,   4.0);
+    a.setElement(2, 1,   1.0);
+    a.setElement(2, 2,  -2.0);
+    a.setElement(2, 3,   8.0);
+
+    a.setElement(3, 0,   0.0);
+    a.setElement(3, 1,  -3.0);
+    a.setElement(3, 2, -12.0);
+    a.setElement(3, 3,  -1.0);
+
+    GeneralMatrix x = new GeneralMatrix(4, 1);
+
+    x.setElement(0, 0,  3.0);
+    x.setElement(1, 0,  4.0);
+    x.setElement(2, 0, -1.0);
+    x.setElement(3, 0, -2.0);
+
+    GeneralMatrix b = new GeneralMatrix(4, 1);
+
+    b.setElement(0, 0,  2.0);
+    b.setElement(1, 0, -9.0);
+    b.setElement(2, 0,  2.0);
+    b.setElement(3, 0,  2.0);
+
+    return new LinearProblem(a, x, b);
+
+  }
+
+  private LinearProblem buildProblem2()
+  {
+
+    double epsilon = 1.0e-7;
+
+    GeneralSquareMatrix a = new GeneralSquareMatrix(2);
+
+    a.setElement(0, 0, epsilon);
+    a.setElement(0, 1, 1.0);
+
+    a.setElement(1, 0, 1.0);
+    a.setElement(1, 1, 1.0);
+
+    GeneralMatrix x = new GeneralMatrix(2, 2);
+
+    x.setElement(0, 0, 1.0 + epsilon);
+    x.setElement(1, 0, 1.0 - epsilon);
+
+    x.setElement(0, 1, epsilon);
+    x.setElement(1, 1, 1.0);
+
+    GeneralMatrix b = new GeneralMatrix(2, 2);
+
+    b.setElement(0, 0, 1.0 + epsilon * epsilon);
+    b.setElement(1, 0, 2.0);
+
+    b.setElement(0, 1, 1.0 + epsilon * epsilon);
+    b.setElement(1, 1, 1.0 + epsilon);
+
+    return new LinearProblem(a, x, b);
+
+  }
+
+  private LinearProblem buildProblem3 ()
+  {
+
+    GeneralSquareMatrix a = new GeneralSquareMatrix(3);
+
+    a.setElement(0, 0,  1.0);
+    a.setElement(0, 1,  2.0);
+    a.setElement(0, 1, -3.0);
+
+    a.setElement(1, 0,  2.0);
+    a.setElement(1, 1,  1.0);
+    a.setElement(1, 1,  3.0);
+
+    a.setElement(2, 0, -3.0);
+    a.setElement(2, 1,  0.0);
+    a.setElement(2, 1, -9.0);
+
+    GeneralMatrix x = new GeneralMatrix(3, 1);
+    GeneralMatrix b = new GeneralMatrix(3, 1);
+
+    return new LinearProblem(a, x, b);
+
+  }
+
+  private void checkSolve(LinearProblem p, Matrix result)
+  {
+
+    Matrix residual = p.a.mul(result).sub(p.b);
+    for (int i = 0; i < residual.getRows(); ++i) {
+      for (int j = 0; j < residual.getColumns(); ++j) {
+        assertTrue(Math.abs(residual.getElement(i, j)) < 1.0e-10);
+      }
+    }
+
+    for (int i = 0; i < result.getRows(); ++i) {
+      for (int j = 0; j < result.getColumns(); ++j) {
+        assertTrue(Math.abs(result.getElement(i, j) - p.x.getElement(i, j))
+                   < 1.0e-10);
+      }
+    }
+
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/GeneralSquareMatrixTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,261 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class LowerTriangularMatrixTest
+  extends TestCase {
+
+  public LowerTriangularMatrixTest(String name) {
+    super(name);
+  }
+
+  public void testNoSetOutsideOfLowerTriangle() {
+
+    LowerTriangularMatrix l = new LowerTriangularMatrix(4);
+
+    for (int i = 0; i < l.getRows(); ++i) {
+      for (int j = 0; j < l.getColumns(); ++j) {
+
+        if (i >= j) {
+          l.setElement(i, j, i + 0.1 * j);
+        } else {
+          boolean gotIt = false;
+          try {
+            l.setElement
+              (i, j, -1.3);
+          } catch(ArrayIndexOutOfBoundsException e) {
+            gotIt = true;
+          }
+          assertTrue(gotIt);
+        }
+      }
+    }
+
+    checkMatrix(l, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+  }
+
+  public void testCopy() {
+
+    LowerTriangularMatrix l1 = buildMatrix(4, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+    LowerTriangularMatrix l2 = new LowerTriangularMatrix (l1);
+
+    checkMatrix (l2, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+  }
+
+  public void testDuplicate() {
+
+    LowerTriangularMatrix l1 = buildMatrix(4, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+    Matrix l2 = l1.duplicate();
+    assertTrue(l2 instanceof LowerTriangularMatrix);
+
+    checkMatrix(l2, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+  }
+
+  public void testTranspose() {
+
+    LowerTriangularMatrix l = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+    Matrix transposed = l.getTranspose();
+    assertTrue(transposed instanceof UpperTriangularMatrix);
+
+    for (int i = 0; i < transposed.getRows(); ++i){
+      for (int j = 0; j < transposed.getColumns(); ++j) {
+        double expected = (i > j) ? 0.0 : (j + 0.1 * i);
+        assertTrue(Math.abs(transposed.getElement(i, j) - expected) < 1.0e-10);
+      }
+    }
+
+  }
+
+  public void testSelfAdd() {
+    LowerTriangularMatrix l1 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 3 * i - 0.2 * j;
+        }
+      });
+
+    LowerTriangularMatrix l2 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 2 * i - 0.4 * j; }
+      });
+
+    l1.selfAdd(l2);
+
+    checkMatrix(l1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 5 * i - 0.6 * j;
+        }
+      });
+  }
+
+  public void testSelfSub() {
+    LowerTriangularMatrix l1 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 3 * i - 0.2 * j;
+        }
+      });
+
+    LowerTriangularMatrix l2 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 2 * i - 0.4 * j;
+        }
+      });
+
+    l1.selfSub(l2);
+
+    checkMatrix(l1, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.2 * j;
+        }
+      });
+  }
+
+  public void testDeterminant() {
+
+    LowerTriangularMatrix l = buildMatrix(4, new ElementPattern() {
+        public double value(int i, int j) {
+          return (i == j) ? 2.0 : 1.0;
+        }
+      });
+
+    assertTrue(Math.abs(l.getDeterminant(1.0e-10) - Math.pow(2.0, l.getRows()))
+               < 1.0e-10);
+
+  }
+
+  public void testSolve()
+    throws SingularMatrixException {
+
+    LowerTriangularMatrix l = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 1.0;
+        }
+      });
+
+    GeneralMatrix b = new GeneralMatrix(l.getRows(), 3);
+    for (int i = 0; i < b.getRows(); ++i) {
+      b.setElement(i, 0, i + 1.0);
+      b.setElement(i, 1, (i + 1.0) * (i + 2.0) / 2.0);
+      b.setElement(i, 2, 0.0);
+    }
+
+    Matrix result = l.solve(b, 1.0e-10);
+
+    assertTrue(result.getRows() == b.getRows());
+    assertTrue(result.getColumns() == b.getColumns());
+
+    for (int i = 0; i < result.getRows(); ++i) {
+      assertTrue(Math.abs(result.getElement(i, 0) - 1.0)       < 1.0e-10);
+      assertTrue(Math.abs(result.getElement(i, 1) - (i + 1.0)) < 1.0e-10);
+      assertTrue(Math.abs(result.getElement(i, 2) - 0.0)       < 1.0e-10);
+    }
+
+    boolean gotIt = false;
+    try {
+      l.setElement(3, 3, 0.0);
+      result = l.solve(b, 1.0e-10);
+    } catch(SingularMatrixException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public void testInverse()
+    throws SingularMatrixException {
+
+    LowerTriangularMatrix l = buildMatrix(5, new ElementPattern() {
+        public double value(int i, int j) {
+          return 1.0;
+        }
+      });
+
+    Matrix inverse = l.getInverse(1.0e-10);
+    assertTrue(inverse instanceof LowerTriangularMatrix);
+
+    checkMatrix(inverse, new ElementPattern() {
+        public double value(int i, int j) {
+          return (i == j) ? 1.0 : ((i == j + 1) ? -1.0 : 0.0);
+        }
+      });
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(LowerTriangularMatrixTest.class);
+  }
+
+  public interface ElementPattern {
+    public double value(int i, int j);
+  }
+
+  public LowerTriangularMatrix buildMatrix(int order,
+                                           ElementPattern pattern) {
+    LowerTriangularMatrix m = new LowerTriangularMatrix(order);
+
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j <= i; ++j) {
+        m.setElement(i, j, pattern.value(i, j));
+      }
+    }
+
+    return m;
+
+  }
+
+  public void checkMatrix(Matrix m, ElementPattern pattern) {
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j) {
+        double expected = (j <= i) ? pattern.value(i, j) : 0.0;
+        assertTrue(Math.abs(m.getElement(i, j) - expected) < 1.0e-10);
+      }
+    }
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/LowerTriangularMatrixTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class MatrixFactoryTest
+  extends TestCase {
+
+  public MatrixFactoryTest(String name) {
+    super(name);
+  }
+
+  public void testInvalidDimensions() {
+    boolean gotIt;
+
+    gotIt = false;
+    try {
+      MatrixFactory.buildMatrix(0, 2, null, 1, 1);
+    } catch (IllegalArgumentException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public void testDiagonal() {
+    Matrix m = MatrixFactory.buildMatrix(3, 3, null, 0, 0);
+    assertTrue(m instanceof DiagonalMatrix);
+  }
+
+  public void testLowerTriangular() {
+    Matrix m = MatrixFactory.buildMatrix(3, 3, null, 1, 0);
+    assertTrue(m instanceof LowerTriangularMatrix);
+  }
+
+  public void testUpperTriangular() {
+    Matrix m = MatrixFactory.buildMatrix(3, 3, null, 0, 1);
+    assertTrue(m instanceof UpperTriangularMatrix);
+  }
+
+  public void testSquare() {
+    Matrix m = MatrixFactory.buildMatrix(3, 3, null, 1, 1);
+    assertTrue(m instanceof GeneralSquareMatrix);
+  }
+
+  public void testGeneral() {
+    Matrix m = MatrixFactory.buildMatrix(3, 4, null, 0, 0);
+    assertTrue(m instanceof GeneralMatrix);
+  }
+
+  public static Test suite() {
+    return new TestSuite(MatrixFactoryTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/MatrixFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class NonNullRangeTest
+  extends TestCase {
+
+  public NonNullRangeTest(String name) {
+    super(name);
+  }
+
+  public void testPublicAttributes() {
+    NonNullRange r = new NonNullRange(2, 7);
+    assertTrue(r.begin == 2);
+    assertTrue(r.end   == 7);
+  }
+
+  public void testCopy() {
+    NonNullRange r1 = new NonNullRange(2, 7);
+    NonNullRange r2 = new NonNullRange(r1);
+    assertTrue(r2.begin == r1.begin);
+    assertTrue(r1.end   == r1.end);
+  }
+
+  public void testIntersection() {
+    NonNullRange r1 = new NonNullRange(-4, 8);
+    NonNullRange r2 = new NonNullRange(3, 12);
+    NonNullRange r3 = NonNullRange.intersection(r1, r2);
+    assertTrue(r3.begin == 3);
+    assertTrue(r3.end   == 8);
+  }
+
+  public void testReunion() {
+    NonNullRange r1 = new NonNullRange(-4, 8);
+    NonNullRange r2 = new NonNullRange(3, 12);
+    NonNullRange r3 = NonNullRange.reunion(r1, r2);
+    assertTrue(r3.begin == -4);
+    assertTrue(r3.end   == 12);
+  }
+
+  public static Test suite() {
+    return new TestSuite(NonNullRangeTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/NonNullRangeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,272 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class SymetricalMatrixTest
+  extends TestCase {
+
+  public SymetricalMatrixTest(String name) {
+    super(name);
+  }
+
+  public void testBuildWAAt() {
+
+    double[] a = { 1.0, 2.0, 3.0 };
+    SymetricalMatrix s = new SymetricalMatrix(0.99, a);
+
+    checkMatrix(s, new ElementPattern() {
+        public double value(int i, int j) {
+          return 0.99 * (i + 1) * (j + 1);
+        }
+      });
+
+  }
+
+  public void testNoSetOutsideOfDiagonal() {
+
+    SymetricalMatrix s = new SymetricalMatrix(4);
+
+    for (int i = 0; i < s.getRows(); ++i) {
+      for (int j = 0; j < s.getColumns(); ++j) {
+        if (i == j) {
+          s.setElement(i, j, 0.5);
+        } else {
+          boolean gotIt = false;
+          try {
+            s.setElement
+              (i, j, -1.3);
+          } catch(ArrayIndexOutOfBoundsException e) {
+            gotIt = true;
+          }
+          assertTrue(gotIt);
+        }
+      }
+    }
+
+    checkMatrix(s, new ElementPattern() {
+        public double value(int i, int j) {
+          return (i == j) ? 0.5 : 0.0;
+        }
+      });
+
+  }
+
+  public void testSetElementAndSymetricalElement() {
+    SymetricalMatrix s = new SymetricalMatrix(5);
+    s.setElementAndSymetricalElement(1, 2, 3.4);
+    assertTrue(Math.abs(s.getElement(1, 2) - 3.4) < 1.0e-10);
+    assertTrue(Math.abs(s.getElement(2, 1) - 3.4) < 1.0e-10);
+  }
+
+  public void testCopy() {
+    SymetricalMatrix m1 = buildMatrix(5, new ElementPattern() {
+        public double value(int i, int j) {
+          return i * i + j * j;
+        }
+      });
+
+    SymetricalMatrix m2 = new SymetricalMatrix(m1);
+
+    for (int i = 0; i < m1.getRows(); ++i) {
+      for (int j = i; j < m1.getColumns(); ++j) {
+        m1.setElementAndSymetricalElement(i, j, -1.0);
+      }
+    }
+
+    assertTrue(m2.getRows() == m1.getRows());
+    assertTrue(m2.getColumns() == m1.getColumns());
+
+    checkMatrix(m2, new ElementPattern() {
+        public double value(int i, int j) {
+          return i * i + j * j;
+        }
+      });
+
+  }
+
+  public void testDuplicate() {
+    SymetricalMatrix m1 = buildMatrix(5, new ElementPattern() {
+        public double value(int i, int j) {
+          return i * j;
+        }
+      });
+
+    Matrix m2 = m1.duplicate();
+    assertTrue(m2 instanceof SymetricalMatrix);
+
+    for (int i = 0; i < m1.getRows(); ++i) {
+      for (int j = i; j < m1.getColumns(); ++j) {
+        m1.setElementAndSymetricalElement(i, j, -1.0);
+      }
+    }
+
+    assertTrue(m2.getRows() == m1.getRows());
+    assertTrue(m2.getColumns() == m1.getColumns());
+
+    checkMatrix(m2, new ElementPattern() {
+        public double value(int i, int j) {
+          return i * j;
+        }
+      });
+
+  }
+
+  public void testSelfAdd() {
+    double[] a1 = { 2.0, 4.0, 8.0, 16.0 };
+    SymetricalMatrix s1 = new SymetricalMatrix(0.5, a1);
+
+    double[] a2 = { 3.0, 9.0, 27.0, 81.0 };
+    SymetricalMatrix s2 = new SymetricalMatrix(1.0, a2);
+
+    s1.selfAdd(s2);
+
+    checkMatrix(s1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 0.5 * Math.pow(2.0, i + 1) * Math.pow(2.0, j + 1)
+            + Math.pow(3.0, i + 1) * Math.pow(3.0, j + 1);
+        }
+      });
+  }
+
+  public void testSelfSub() {
+    double[] a1 = { 2.0, 4.0, 8.0, 16.0 };
+    SymetricalMatrix s1 = new SymetricalMatrix(0.5, a1);
+
+    double[] a2 = { 3.0, 9.0, 27.0, 81.0 };
+    SymetricalMatrix s2 = new SymetricalMatrix(1.0, a2);
+
+    s1.selfSub(s2);
+
+    checkMatrix(s1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 0.5 * Math.pow(2.0, i + 1) * Math.pow(2.0, j + 1)
+            - Math.pow(3.0, i + 1) * Math.pow(3.0, j + 1);
+        }
+      });
+  }
+
+  public void testSelfAddWAAt() {
+
+    SymetricalMatrix s = new SymetricalMatrix(3);
+
+    double[] a1 = { 1.0, 2.0, 3.0 };
+    s.selfAddWAAt(1.0, a1);
+
+    double[] a2 = { 0.1, 0.2, 0.3 };
+    s.selfAddWAAt(2.0, a2);
+
+    checkMatrix(s, new ElementPattern() {
+        public double value(int i, int j) {
+          return 1.02 * (i + 1) * (j + 1);
+        }
+      });
+
+  }
+
+  public void testSingular()
+    throws SingularMatrixException {
+    SymetricalMatrix s = new SymetricalMatrix(3);
+
+    double[] a1 = { 1.0, 2.0, 3.0 };
+    s.selfAddWAAt(1.0, a1);
+
+    double[] a2 = { 0.1, 0.2, 0.3 };
+    s.selfAddWAAt(2.0, a2);
+
+    Matrix b = new GeneralMatrix(3, 1);
+    b.setElement(0, 0,  6.12);
+    b.setElement(1, 0, 12.24);
+    b.setElement(2, 0, 18.36);
+
+    boolean gotIt = false;
+    try {
+      s.solve(b, 1.0e-10);
+    } catch(SingularMatrixException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public void testSolve()
+    throws SingularMatrixException {
+    SymetricalMatrix s = new SymetricalMatrix(3);
+
+    double[] a1 = { 1.0, 2.0, 3.0 };
+    s.selfAddWAAt(1.0, a1);
+
+    double[] a2 = { 0.1, 0.2, 0.3 };
+    s.selfAddWAAt(2.0, a2);
+
+    double[] a3 = { 1.2, -3.0, 2.1 };
+    s.selfAddWAAt(3.0, a3);
+
+    double[] a4 = { 0.4, 0.1, 3.1 };
+    s.selfAddWAAt(2.0, a4);
+
+    Matrix b = new GeneralMatrix(3, 1);
+    b.setElement(0, 0, 10.08);
+    b.setElement(1, 0, 10.26);
+    b.setElement(2, 0, 42.57);
+
+    Matrix x = s.solve(b, 1.0e-10);
+
+    checkMatrix (x, new ElementPattern() {
+        public double value(int i, int j) {
+          return 1.0;
+        }
+      });
+
+    assertTrue(Math.abs(s.getDeterminant(1.0e-10) - 782.846532) < 1.0e-10);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(SymetricalMatrixTest.class);
+  }
+
+  public interface ElementPattern {
+    public double value(int i, int j);
+  }
+
+  public SymetricalMatrix buildMatrix(int order,
+                                      ElementPattern pattern) {
+    SymetricalMatrix m = new SymetricalMatrix(order);
+
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = i; j < m.getColumns(); ++j) {
+        m.setElementAndSymetricalElement(i, j, pattern.value(i, j));
+      }
+    }
+
+    return m;
+
+  }
+
+  public void checkMatrix(Matrix m, ElementPattern pattern) {
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j) {
+        assertTrue(Math.abs(m.getElement(i, j) - pattern.value(i, j))
+                   < 1.0e-10);
+      }
+    }
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/SymetricalMatrixTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,261 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.linalg;
+
+import junit.framework.*;
+
+public class UpperTriangularMatrixTest
+  extends TestCase {
+
+  public UpperTriangularMatrixTest(String name) {
+    super(name);
+  }
+
+  public void testNoSetOutsideOfUpperTriangle() {
+
+    UpperTriangularMatrix u = new UpperTriangularMatrix(4);
+
+    for (int i = 0; i < u.getRows(); ++i) {
+      for (int j = 0; j < u.getColumns(); ++j) {
+        if (i <= j) {
+          u.setElement(i, j, i + 0.1 * j);
+        } else {
+          boolean gotIt = false;
+          try {
+            u.setElement(i, j, -1.3);
+          } catch(ArrayIndexOutOfBoundsException e) {
+            gotIt = true;
+          }
+          assertTrue(gotIt);
+        }
+      }
+    }
+
+    checkMatrix(u, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+  }
+
+  public void testCopy() {
+
+    UpperTriangularMatrix u1 = buildMatrix(4, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+    UpperTriangularMatrix u2 = new UpperTriangularMatrix(u1);
+
+    checkMatrix(u2, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+  }
+
+  public void testDuplicate() {
+
+    UpperTriangularMatrix u1 = buildMatrix(4, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+    Matrix u2 = u1.duplicate();
+    assertTrue(u2 instanceof UpperTriangularMatrix);
+
+    checkMatrix(u2, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+  }
+
+  public void testTranspose() {
+
+    UpperTriangularMatrix u = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.1 * j;
+        }
+      });
+
+    Matrix transposed = u.getTranspose();
+    assertTrue(transposed instanceof LowerTriangularMatrix);
+
+    for (int i = 0; i < transposed.getRows(); ++i){
+      for (int j = 0; j < transposed.getColumns(); ++j) {
+        double expected = (i < j) ? 0.0 : (j + 0.1 * i);
+        assertTrue(Math.abs(transposed.getElement(i, j) - expected) < 1.0e-10);
+      }
+    }
+
+  }
+
+  public void testSelfAdd() {
+    UpperTriangularMatrix u1 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 3 * i - 0.2 * j;
+        }
+      });
+
+    UpperTriangularMatrix u2 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 2 * i - 0.4 * j;
+        }
+      });
+
+    u1.selfAdd(u2);
+
+    checkMatrix(u1, new ElementPattern() {
+        public double value(int i, int j) {
+          return 5 * i - 0.6 * j;
+        }
+      });
+  }
+
+  public void testSelfSub() {
+    UpperTriangularMatrix u1 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 3 * i - 0.2 * j;
+        }
+      });
+
+    UpperTriangularMatrix u2 = buildMatrix(7, new ElementPattern() {
+        public double value(int i, int j) {
+          return 2 * i - 0.4 * j;
+        }
+      });
+
+    u1.selfSub(u2);
+
+    checkMatrix(u1, new ElementPattern() {
+        public double value(int i, int j) {
+          return i + 0.2 * j;
+        }
+      });
+  }
+
+  public void testDeterminant() {
+
+    UpperTriangularMatrix u = buildMatrix(4, new ElementPattern() {
+        public double value(int i, int j) {
+          return (i == j) ? 2.0 : 1.0;
+        }
+      });
+
+    assertTrue(Math.abs(u.getDeterminant(1.0e-10) - Math.pow(2.0, u.getRows()))
+               < 1.0e-10);
+
+  }
+
+  public void testSolve()
+    throws SingularMatrixException {
+
+    int rows = 7;
+    UpperTriangularMatrix u = buildMatrix(rows, new ElementPattern() {
+        public double value(int i, int j) {
+          return 1.0;
+        }
+      });
+
+    GeneralMatrix b = new GeneralMatrix(rows, 3);
+    for (int i = 0; i < rows; ++i) {
+      b.setElement(i, 0, rows - i);
+      b.setElement(i, 1, (rows - i) * (rows + 1 - i) / 2.0);
+      b.setElement(i, 2, 0.0);
+    }
+
+    Matrix result = u.solve(b, 1.0e-10);
+
+    assertTrue(result.getRows() == b.getRows());
+    assertTrue(result.getColumns() == b.getColumns());
+
+    for (int i = 0; i < result.getRows(); ++i) {
+      assertTrue(Math.abs(result.getElement(i, 0) - 1.0)        < 1.0e-10);
+      assertTrue(Math.abs(result.getElement(i, 1) - (rows - i)) < 1.0e-10);
+      assertTrue(Math.abs(result.getElement(i, 2) - 0.0)        < 1.0e-10);
+    }
+
+    boolean gotIt = false;
+    try {
+      u.setElement(3, 3, 0.0);
+      result = u.solve(b, 1.0e-10);
+    } catch(SingularMatrixException e) {
+      gotIt = true;
+    }
+    assertTrue(gotIt);
+
+  }
+
+  public void testInverse()
+    throws SingularMatrixException {
+
+    UpperTriangularMatrix u = buildMatrix(5, new ElementPattern() {
+        public double value(int i, int j) {
+          return 1.0;
+        }
+      });
+
+    Matrix inverse = u.getInverse(1.0e-10);
+    assertTrue(inverse instanceof UpperTriangularMatrix);
+
+    checkMatrix(inverse, new ElementPattern() {
+        public double value(int i, int j) {
+          return (i == j) ? 1.0 : ((i == j - 1) ? -1.0 : 0.0);
+        }
+      });
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(UpperTriangularMatrixTest.class);
+  }
+
+  public interface ElementPattern {
+    public double value(int i, int j);
+  }
+
+  public UpperTriangularMatrix buildMatrix(int order,
+                                           ElementPattern pattern) {
+    UpperTriangularMatrix m = new UpperTriangularMatrix (order);
+
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = i; j < m.getColumns(); ++j) {
+        m.setElement(i, j, pattern.value(i, j));
+      }
+    }
+
+    return m;
+
+  }
+
+  public void checkMatrix(Matrix m, ElementPattern pattern) {
+    for (int i = 0; i < m.getRows(); ++i) {
+      for (int j = 0; j < m.getColumns(); ++j) {
+        double expected = (i <= j) ? pattern.value(i, j) : 0.0;
+        assertTrue(Math.abs(m.getElement(i, j) - expected) < 1.0e-10);
+      }
+    }
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/linalg/UpperTriangularMatrixTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+  public static Test suite() { 
+
+    TestSuite suite = new TestSuite("org.spaceroots.mantissa.ode"); 
+
+    suite.addTest(EulerStepInterpolatorTest.suite());
+    suite.addTest(EulerIntegratorTest.suite());
+    suite.addTest(MidpointIntegratorTest.suite());
+    suite.addTest(ClassicalRungeKuttaIntegratorTest.suite());
+    suite.addTest(GillIntegratorTest.suite());
+    suite.addTest(ThreeEighthesIntegratorTest.suite());
+    suite.addTest(HighamHall54IntegratorTest.suite());
+    suite.addTest(DormandPrince54IntegratorTest.suite());
+    suite.addTest(DormandPrince853IntegratorTest.suite());
+    suite.addTest(GraggBulirschStoerIntegratorTest.suite());
+    suite.addTest(FirstOrderConverterTest.suite());
+    suite.addTest(StepNormalizerTest.suite());
+    suite.addTest(ContinuousOutputModelTest.suite());
+    suite.addTest(ClassicalRungeKuttaStepInterpolatorTest.suite());
+    suite.addTest(GillStepInterpolatorTest.suite());
+    suite.addTest(ThreeEighthesStepInterpolatorTest.suite());
+    suite.addTest(DormandPrince853StepInterpolatorTest.suite());
+    suite.addTest(DormandPrince54StepInterpolatorTest.suite());
+    suite.addTest(HighamHall54StepInterpolatorTest.suite());
+    suite.addTest(MidpointStepInterpolatorTest.suite());
+    suite.addTest(GraggBulirschStoerStepInterpolatorTest.suite());
+
+    return suite; 
+
+  }
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/AllTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,216 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.fitting.PolynomialFitter;
+
+public class ClassicalRungeKuttaIntegratorTest
+  extends TestCase {
+
+  public ClassicalRungeKuttaIntegratorTest(String name) {
+    super(name);
+  }
+
+  public void testDimensionCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      new ClassicalRungeKuttaIntegrator(0.01).integrate(pb,
+                                                        0.0, new double[pb.getDimension()+10],
+                                                        1.0, new double[pb.getDimension()+10]);
+        fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+  
+  public void testNullIntervalCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      new ClassicalRungeKuttaIntegrator(0.01).integrate(pb,
+                                                        0.0, new double[pb.getDimension()],
+                                                        0.0, new double[pb.getDimension()]);
+        fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+  
+  public void testDecreasingSteps()
+    throws DerivativeException, IntegratorException  {
+      
+    TestProblemAbstract[] problems = TestProblemFactory.getProblems();
+    for (int k = 0; k < problems.length; ++k) {
+
+      double previousError = Double.NaN;
+      for (int i = 4; i < 10; ++i) {
+
+        TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
+        double step = (pb.getFinalTime() - pb.getInitialTime())
+          * Math.pow(2.0, -i);
+
+        FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
+        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);
+          }
+        }
+        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
+
+        double error = handler.getMaximalError();
+        if (i > 4) {
+          assertTrue(error < Math.abs(previousError));
+        }
+        previousError = error;
+      }
+
+    }
+
+  }
+
+  public void testOrder()
+  throws EstimationException, DerivativeException,
+         IntegratorException {
+    PolynomialFitter fitter = new PolynomialFitter(1,
+                                                   10, 1.0e-7, 1.0e-10,
+                                                   1.0e-10);
+
+    TestProblemAbstract[] problems = TestProblemFactory.getProblems();
+    for (int k = 0; k < problems.length; ++k) {
+
+      for (int i = 0; i < 10; ++i) {
+
+        TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
+        double step = (pb.getFinalTime() - pb.getInitialTime())
+          * Math.pow(2.0, -(i + 1));
+
+        FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
+        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);
+          }
+        }
+        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
+
+        fitter.addWeightedPair(1.0,
+                               Math.log(Math.abs(step)),
+                               Math.log(handler.getLastError()));
+
+      }
+
+      // this is an order 4 method
+      double[] coeffs = fitter.fit();
+      assertTrue(coeffs[1] > 3.2);
+      assertTrue(coeffs[1] < 4.8);
+
+    }
+
+  }
+
+  public void testSmallStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem1 pb = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
+
+    FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    integ.setStepHandler(handler);
+    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(handler.getLastError() < 2.0e-13);
+    assertTrue(handler.getMaximalError() < 4.0e-12);
+
+  }
+
+  public void testBigStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem1 pb = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
+
+    FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    integ.setStepHandler(handler);
+    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(handler.getLastError() > 0.0004);
+    assertTrue(handler.getMaximalError() > 0.005);
+
+  }
+
+  public void testKepler()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb  = new TestProblem3(0.9);
+    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.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  public static Test suite() {
+    return new TestSuite(ClassicalRungeKuttaIntegratorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolatorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolatorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolatorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+
+public class ClassicalRungeKuttaStepInterpolatorTest
+  extends TestCase {
+
+  public ClassicalRungeKuttaStepInterpolatorTest(String name) {
+    super(name);
+  }
+
+  public void testSerialization()
+    throws DerivativeException, IntegratorException,
+           IOException, ClassNotFoundException {
+
+    TestProblem3 pb = new TestProblem3(0.9);
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003;
+    ClassicalRungeKuttaIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream    oos = new ObjectOutputStream(bos);
+    oos.writeObject(integ.getStepHandler());
+
+    assertTrue(bos.size () > 700000);
+    assertTrue(bos.size () < 701000);
+
+    ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
+    ObjectInputStream     ois = new ObjectInputStream(bis);
+    ContinuousOutputModel cm  = (ContinuousOutputModel) ois.readObject();
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError > 0.005);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(ClassicalRungeKuttaStepInterpolatorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,94 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+
+public class ContinuousOutputModelTest
+  extends TestCase {
+
+  public ContinuousOutputModelTest(String name) {
+    super(name);
+  }
+
+  public void testBoundaries()
+    throws DerivativeException, IntegratorException {
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+    ContinuousOutputModel cm = (ContinuousOutputModel) integ.getStepHandler();
+    cm.setInterpolatedTime(2.0 * pb.getInitialTime() - pb.getFinalTime());
+    cm.setInterpolatedTime(2.0 * pb.getFinalTime() - pb.getInitialTime());
+    cm.setInterpolatedTime(0.5 * (pb.getFinalTime() + pb.getInitialTime()));
+  }
+
+  public void testRandomAccess()
+    throws DerivativeException, IntegratorException {
+
+    ContinuousOutputModel cm = new ContinuousOutputModel();
+    integ.setStepHandler(cm);
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError < 1.0e-9);
+
+  }
+
+  public void checkValue(double value, double reference) {
+    assertTrue(Math.abs(value - reference) < 1.0e-10);
+  }
+
+  public static Test suite() {
+    return new TestSuite(ContinuousOutputModelTest.class);
+  }
+
+  public void setUp() {
+    pb = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    integ = new DormandPrince54Integrator(minStep, maxStep, 1.0e-8, 1.0e-8);
+  }
+
+  public void tearDown() {
+    pb    = null;
+    integ = null;
+  }
+
+  TestProblem3 pb;
+  FirstOrderIntegrator integ;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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