You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2006/11/19 22:36:23 UTC
svn commit: r476930 [22/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...
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,33 @@
+// 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.quadrature.vectorial;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("org.spaceroots.mantissa.quadrature.vectorial");
+
+ suite.addTest(GaussLegendreIntegratorTest.suite());
+
+ return suite;
+
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,122 @@
+// 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.quadrature.vectorial;
+
+import org.spaceroots.mantissa.functions.vectorial.ComputableFunction;
+import org.spaceroots.mantissa.functions.FunctionException;
+
+import java.util.Random;
+
+import junit.framework.*;
+
+public class GaussLegendreIntegratorTest
+ extends TestCase {
+
+ public GaussLegendreIntegratorTest(String name) {
+ super(name);
+ }
+
+ public void testExactIntegration()
+ throws FunctionException {
+ Random random = new Random(86343623467878363l);
+ int order = 0;
+ while (true) {
+ GaussLegendreIntegrator integrator = new GaussLegendreIntegrator(order,
+ 7.0);
+ int availableOrder = integrator.getEvaluationsPerStep();
+ if (availableOrder < order) {
+ // we have tested all available orders
+ return;
+ }
+
+ // an order n Gauss-Legendre integrator integrates
+ // 2n-1 degree polynoms exactly
+ for (int degree = 0; degree <= 2 * availableOrder - 1; ++degree) {
+ for (int i = 0; i < 10; ++i) {
+ Polynom p = new Polynom(degree, random, 100.0);
+ double[] s0 = integrator.integrate(p, -5.0, 15.0);
+ double[] s1 = p.exactIntegration(-5.0, 15.0);
+ for (int j = 0; j < p.getDimension(); ++j) {
+ assertTrue(Math.abs(s0[j] - s1[j]) < 1.0e-12 * (1.0 + Math.abs(s0[j])));
+ }
+ }
+ }
+
+ ++order;
+
+ }
+ }
+
+ public static Test suite() {
+ return new TestSuite(GaussLegendreIntegratorTest.class);
+ }
+
+ private class Polynom implements ComputableFunction {
+ public Polynom (int degree, Random random, double max) {
+ coeffs0 = new double[degree + 1];
+ coeffs1 = new double[degree + 1];
+ for (int i = 0; i <= degree; ++i) {
+ coeffs0[i] = 2.0 * max * (random.nextDouble() - 0.5);
+ coeffs1[i] = 2.0 * max * (random.nextDouble() - 0.5);
+ }
+ }
+
+ public int getDimension() {
+ return 2;
+ }
+
+ public double[] valueAt(double t)
+ throws FunctionException {
+ double[] y = new double[2];
+ y[0] = coeffs0[coeffs0.length - 1];
+ for (int i = coeffs0.length - 2; i >= 0; --i) {
+ y[0] = y[0] * t + coeffs0[i];
+ }
+ y[1] = coeffs1 [coeffs1.length - 1];
+ for (int i = coeffs1.length - 2; i >= 0; --i) {
+ y[1] = y[1] * t + coeffs1[i];
+ }
+ return y;
+ }
+
+ public double[] exactIntegration(double a, double b)
+ throws FunctionException {
+ double[] res = new double[2];
+ double yb = coeffs0[coeffs0.length - 1] / coeffs0.length;
+ double ya = yb;
+ for (int i = coeffs0.length - 2; i >= 0; --i) {
+ yb = yb * b + coeffs0[i] / (i + 1);
+ ya = ya * a + coeffs0[i] / (i + 1);
+ }
+ res[0] = yb * b - ya * a;
+ yb = coeffs1[coeffs1.length - 1] / coeffs1.length;
+ ya = yb;
+ for (int i = coeffs1.length - 2; i >= 0; --i) {
+ yb = yb * b + coeffs1[i] / (i + 1);
+ ya = ya * a + coeffs1[i] / (i + 1);
+ }
+ res[1] = yb * b - ya * a;
+ return res;
+ }
+
+ private double[] coeffs0;
+ private double[] coeffs1;
+
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/quadrature/vectorial/GaussLegendreIntegratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,37 @@
+// 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.random;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("org.spaceroots.mantissa.random");
+
+ suite.addTest(ScalarSampleStatisticsTest.suite());
+ suite.addTest(VectorialSampleStatisticsTest.suite());
+ suite.addTest(UniformRandomGeneratorTest.suite());
+ suite.addTest(GaussianRandomGeneratorTest.suite());
+ suite.addTest(UncorrelatedRandomVectorGeneratorTest.suite());
+ suite.addTest(CorrelatedRandomVectorGeneratorTest.suite());
+ return suite;
+
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGeneratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGeneratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGeneratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGeneratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,111 @@
+// 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.random;
+
+import org.spaceroots.mantissa.linalg.Matrix;
+import org.spaceroots.mantissa.linalg.GeneralMatrix;
+import org.spaceroots.mantissa.linalg.SymetricalMatrix;
+
+import junit.framework.*;
+
+public class CorrelatedRandomVectorGeneratorTest
+ extends TestCase {
+
+ public CorrelatedRandomVectorGeneratorTest(String name) {
+ super(name);
+ }
+
+ public void testRank() {
+ assertEquals(3, generator.getRank());
+ }
+
+ public void testRootMatrix() {
+ Matrix b = generator.getRootMatrix();
+ Matrix bbt = b.mul(b.getTranspose());
+ for (int i = 0; i < covariance.getRows(); ++i) {
+ for (int j = 0; j < covariance.getColumns(); ++j) {
+ assertEquals(covariance.getElement(i, j),
+ bbt.getElement(i, j),
+ 1.0e-12);
+ }
+ }
+ }
+
+ public void testMeanAndCovariance() {
+
+ VectorialSampleStatistics sample = new VectorialSampleStatistics();
+ for (int i = 0; i < 5000; ++i) {
+ sample.add(generator.nextVector());
+ }
+
+ double[] estimatedMean = sample.getMean(null);
+ SymetricalMatrix estimatedCovariance = sample.getCovarianceMatrix(null);
+ for (int i = 0; i < estimatedMean.length; ++i) {
+ assertEquals(mean[i], estimatedMean[i], 0.07);
+ for (int j = 0; j <= i; ++j) {
+ assertEquals(covariance.getElement(i, j),
+ estimatedCovariance.getElement(i, j),
+ 0.1 * (1.0 + Math.abs(mean[i])) * (1.0 + Math.abs(mean[j])));
+ }
+ }
+
+ }
+
+ public void setUp() {
+ try {
+ mean = new double[] { 0.0, 1.0, -3.0, 2.3};
+
+ GeneralMatrix b = new GeneralMatrix(4, 3);
+ int counter = 0;
+ for (int i = 0; i < b.getRows(); ++i) {
+ for (int j = 0; j < b.getColumns(); ++j) {
+ b.setElement(i, j, 1.0 + 0.1 * ++counter);
+ }
+ }
+ Matrix bbt = b.mul(b.getTranspose());
+ covariance = new SymetricalMatrix(mean.length);
+ for (int i = 0; i < covariance.getRows(); ++i) {
+ covariance.setElement(i, i, bbt.getElement(i, i));
+ for (int j = 0; j < covariance.getColumns(); ++j) {
+ covariance.setElementAndSymetricalElement(i, j,
+ bbt.getElement(i, j));
+ }
+ }
+
+ GaussianRandomGenerator rawGenerator = new GaussianRandomGenerator(17399225432l);
+ generator = new CorrelatedRandomVectorGenerator(mean, covariance, rawGenerator);
+ } catch (NotPositiveDefiniteMatrixException e) {
+ fail("not positive definite matrix");
+ }
+ }
+
+ public void tearDown() {
+ mean = null;
+ covariance = null;
+ generator = null;
+ }
+
+ public static Test suite() {
+ return new TestSuite(CorrelatedRandomVectorGeneratorTest.class);
+ }
+
+ private double[] mean;
+ private SymetricalMatrix covariance;
+ private CorrelatedRandomVectorGenerator generator;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,43 @@
+// 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.random;
+
+import junit.framework.*;
+
+public class GaussianRandomGeneratorTest
+ extends TestCase {
+
+ public GaussianRandomGeneratorTest(String name) {
+ super(name);
+ }
+
+ public void testMeanAndStandardDeviation() {
+ GaussianRandomGenerator generator = new GaussianRandomGenerator(17399225432l);
+ ScalarSampleStatistics sample = new ScalarSampleStatistics();
+ for (int i = 0; i < 10000; ++i) {
+ sample.add(generator.nextDouble());
+ }
+ assertEquals(0.0, sample.getMean(), 0.012);
+ assertEquals(1.0, sample.getStandardDeviation(), 0.01);
+ }
+
+ public static Test suite() {
+ return new TestSuite(GaussianRandomGeneratorTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,102 @@
+// 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.random;
+
+import junit.framework.*;
+
+public class ScalarSampleStatisticsTest
+ extends TestCase {
+
+ public ScalarSampleStatisticsTest(String name) {
+ super(name);
+ }
+
+ public void testBasicStats() {
+
+ ScalarSampleStatistics sample = new ScalarSampleStatistics();
+ for (int i = 0; i < points.length; ++i) {
+ sample.add(points[i]);
+ }
+
+ assertEquals(points.length, sample.size());
+ assertEquals(-5.0, sample.getMin(), 1.0e-12);
+ assertEquals(10.4, sample.getMax(), 1.0e-12);
+ assertEquals( 3.0, sample.getMean(), 1.0e-12);
+ assertEquals( 3.920034013457876, sample.getStandardDeviation(),
+ 1.0e-12);
+
+ }
+
+ public void testAddSample() {
+
+ ScalarSampleStatistics all = new ScalarSampleStatistics();
+ ScalarSampleStatistics even = new ScalarSampleStatistics();
+ ScalarSampleStatistics odd = new ScalarSampleStatistics();
+ for (int i = 0; i < points.length; ++i) {
+ all.add(points[i]);
+ if (i % 2 == 0) {
+ even.add(points[i]);
+ } else {
+ odd.add(points[i]);
+ }
+ }
+
+ even.add(odd);
+
+ assertEquals(all.size(), even.size());
+ assertEquals(all.getMin(), even.getMin(), 1.0e-12);
+ assertEquals(all.getMax(), even.getMax(), 1.0e-12);
+ assertEquals(all.getMean(), even.getMean(), 1.0e-12);
+ assertEquals(all.getStandardDeviation(), even.getStandardDeviation(),
+ 1.0e-12);
+
+ }
+
+ public void testAddArray() {
+
+ ScalarSampleStatistics loop = new ScalarSampleStatistics();
+ ScalarSampleStatistics direct = new ScalarSampleStatistics();
+ for (int i = 0; i < points.length; ++i) {
+ loop.add(points[i]);
+ }
+ direct.add(points);
+
+ assertEquals(loop.size(), direct.size());
+ assertEquals(loop.getMin(), direct.getMin(), 1.0e-12);
+ assertEquals(loop.getMax(), direct.getMax(), 1.0e-12);
+ assertEquals(loop.getMean(), direct.getMean(), 1.0e-12);
+ assertEquals(loop.getStandardDeviation(), direct.getStandardDeviation(),
+ 1.0e-12);
+
+ }
+
+ public void setUp() {
+ points = new double[] {1.0, 4.2, -5, 4.0, 2.9, 10.4, 0.0, 4.1, 4.2, 4.2};
+ }
+
+ public void tearDown() {
+ points = null;
+ }
+
+ public static Test suite() {
+ return new TestSuite(ScalarSampleStatisticsTest.class);
+ }
+
+ private double[] points;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/ScalarSampleStatisticsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,75 @@
+// 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.random;
+
+import org.spaceroots.mantissa.linalg.SymetricalMatrix;
+
+import junit.framework.*;
+
+public class UncorrelatedRandomVectorGeneratorTest
+ extends TestCase {
+
+ public UncorrelatedRandomVectorGeneratorTest(String name) {
+ super(name);
+ }
+
+ public void testMeanAndCorrelation() {
+
+ VectorialSampleStatistics sample = new VectorialSampleStatistics();
+ for (int i = 0; i < 10000; ++i) {
+ sample.add(generator.nextVector());
+ }
+
+ double[] estimatedMean = sample.getMean(null);
+ double scale;
+ SymetricalMatrix estimatedCorrelation = sample.getCovarianceMatrix(null);
+ for (int i = 0; i < estimatedMean.length; ++i) {
+ assertEquals(mean[i], estimatedMean[i], 0.07);
+ for (int j = 0; j < i; ++j) {
+ scale = standardDeviation[i] * standardDeviation[j];
+ assertEquals(0, estimatedCorrelation.getElement(i, j) / scale, 0.03);
+ }
+ scale = standardDeviation[i] * standardDeviation[i];
+ assertEquals(1, estimatedCorrelation.getElement(i, i) / scale, 0.025);
+ }
+
+ }
+
+ public void setUp() {
+ mean = new double[] {0.0, 1.0, -3.0, 2.3};
+ standardDeviation = new double[] {1.0, 2.0, 10.0, 0.1};
+ generator =
+ new UncorrelatedRandomVectorGenerator(mean, standardDeviation,
+ new GaussianRandomGenerator(17399225432l));
+ }
+
+ public void tearDown() {
+ mean = null;
+ standardDeviation = null;
+ generator = null;
+ }
+
+ public static Test suite() {
+ return new TestSuite(UncorrelatedRandomVectorGeneratorTest.class);
+ }
+
+ private double[] mean;
+ private double[] standardDeviation;
+ private UncorrelatedRandomVectorGenerator generator;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,43 @@
+// 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.random;
+
+import junit.framework.*;
+
+public class UniformRandomGeneratorTest
+ extends TestCase {
+
+ public UniformRandomGeneratorTest(String name) {
+ super(name);
+ }
+
+ public void testMeanAndStandardDeviation() {
+ UniformRandomGenerator generator = new UniformRandomGenerator(17399225432l);
+ ScalarSampleStatistics sample = new ScalarSampleStatistics();
+ for (int i = 0; i < 1000; ++i) {
+ sample.add(generator.nextDouble());
+ }
+ assertEquals(0.0, sample.getMean(), 0.07);
+ assertEquals(1.0, sample.getStandardDeviation(), 0.02);
+ }
+
+ public static Test suite() {
+ return new TestSuite(UniformRandomGeneratorTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/VectorialSampleStatisticsTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/VectorialSampleStatisticsTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/VectorialSampleStatisticsTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/VectorialSampleStatisticsTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,166 @@
+// 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.random;
+
+import org.spaceroots.mantissa.linalg.SymetricalMatrix;
+
+import junit.framework.*;
+
+public class VectorialSampleStatisticsTest
+ extends TestCase {
+
+ public VectorialSampleStatisticsTest(String name) {
+ super(name);
+ }
+
+ public void testSimplistic() {
+ VectorialSampleStatistics sample = new VectorialSampleStatistics();
+ sample.add(new double[] {-1.0, 1.0});
+ sample.add(new double[] { 1.0, -1.0});
+ SymetricalMatrix c = sample.getCovarianceMatrix(null);
+ assertEquals( 2.0, c.getElement(0, 0), 1.0e-12);
+ assertEquals(-2.0, c.getElement(1, 0), 1.0e-12);
+ assertEquals( 2.0, c.getElement(1, 1), 1.0e-12);
+ }
+
+ public void testBasicStats() {
+
+ VectorialSampleStatistics sample = new VectorialSampleStatistics();
+ for (int i = 0; i < points.length; ++i) {
+ sample.add(points[i]);
+ }
+
+ assertEquals(points.length, sample.size());
+
+ double[] min = sample.getMin();
+ double[] max = sample.getMax();
+ double[] mean = sample.getMean(null);
+ SymetricalMatrix c = sample.getCovarianceMatrix(null);
+
+ double[] refMin = new double[] {-0.70, 0.00, -3.10};
+ double[] refMax = new double[] { 6.00, 2.30, 5.00};
+ double[] refMean = new double[] { 1.78, 1.62, 3.12};
+ double[][] refC = new double[][] {
+ { 8.0470, -1.9195, -3.4445},
+ {-1.9195, 1.0470, 3.2795},
+ {-3.4445, 3.2795, 12.2070}
+ };
+
+ for (int i = 0; i < min.length; ++i) {
+ assertEquals(refMin[i], min[i], 1.0e-12);
+ assertEquals(refMax[i], max[i], 1.0e-12);
+ assertEquals(refMean[i], mean[i], 1.0e-12);
+ for (int j = 0; j <= i; ++j) {
+ assertEquals(refC[i][j], c.getElement(i, j), 1.0e-12);
+ }
+ }
+
+ }
+
+ public void testAddSample() {
+
+ VectorialSampleStatistics all = new VectorialSampleStatistics();
+ VectorialSampleStatistics even = new VectorialSampleStatistics();
+ VectorialSampleStatistics odd = new VectorialSampleStatistics();
+ for (int i = 0; i < points.length; ++i) {
+ all.add(points[i]);
+ if (i % 2 == 0) {
+ even.add(points[i]);
+ } else {
+ odd.add(points[i]);
+ }
+ }
+
+ even.add(odd);
+
+ assertEquals(all.size(), even.size());
+
+ double[] min = even.getMin();
+ double[] max = even.getMax();
+ double[] mean = even.getMean(null);
+ SymetricalMatrix c = even.getCovarianceMatrix(null);
+
+ double[] refMin = all.getMin();
+ double[] refMax = all.getMax();
+ double[] refMean = all.getMean(null);
+ SymetricalMatrix refC = all.getCovarianceMatrix(null);
+
+ for (int i = 0; i < min.length; ++i) {
+ assertEquals(refMin[i], min[i], 1.0e-12);
+ assertEquals(refMax[i], max[i], 1.0e-12);
+ assertEquals(refMean[i], mean[i], 1.0e-12);
+ for (int j = 0; j <= i; ++j) {
+ assertEquals(refC.getElement(i, j), c.getElement(i, j), 1.0e-12);
+ }
+ }
+
+ }
+
+ public void testAddArray() {
+
+ VectorialSampleStatistics loop = new VectorialSampleStatistics();
+ VectorialSampleStatistics direct = new VectorialSampleStatistics();
+ for (int i = 0; i < points.length; ++i) {
+ loop.add(points[i]);
+ }
+ direct.add(points);
+
+ assertEquals(loop.size(), direct.size());
+
+ double[] min = direct.getMin();
+ double[] max = direct.getMax();
+ double[] mean = direct.getMean(null);
+ SymetricalMatrix c = direct.getCovarianceMatrix(null);
+
+ double[] refMin = loop.getMin();
+ double[] refMax = loop.getMax();
+ double[] refMean = loop.getMean(null);
+ SymetricalMatrix refC = loop.getCovarianceMatrix(null);
+
+ for (int i = 0; i < min.length; ++i) {
+ assertEquals(refMin[i], min[i], 1.0e-12);
+ assertEquals(refMax[i], max[i], 1.0e-12);
+ assertEquals(refMean[i], mean[i], 1.0e-12);
+ for (int j = 0; j <= i; ++j) {
+ assertEquals(refC.getElement(i, j), c.getElement(i, j), 1.0e-12);
+ }
+ }
+
+ }
+
+ public void setUp() {
+ points = new double[][] {
+ { 1.2, 2.3, 4.5},
+ {-0.7, 2.3, 5.0},
+ { 3.1, 0.0, -3.1},
+ { 6.0, 1.2, 4.2},
+ {-0.7, 2.3, 5.0}
+ };
+ }
+
+ public void tearDown() {
+ points = null;
+ }
+
+ public static Test suite() {
+ return new TestSuite(VectorialSampleStatisticsTest.class);
+ }
+
+ private double [][] points;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/VectorialSampleStatisticsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,33 @@
+// 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.roots;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("org.spaceroots.mantissa.roots");
+
+ suite.addTest(BrentSolverTest.suite());
+
+ return suite;
+
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.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.roots;
+
+import org.spaceroots.mantissa.functions.FunctionException;
+
+import junit.framework.*;
+
+public class BrentSolverTest
+ extends TestCase {
+
+ public BrentSolverTest(String name) {
+ super(name);
+ }
+
+ public void testAlefeldPotraShi()
+ throws FunctionException {
+
+ TestProblem[] problems = TestProblem.getAPSProblems();
+ BrentSolver solver = new BrentSolver();
+
+ for (int i = 0; i < problems.length; ++i) {
+ TestProblem p = problems[i];
+ double tol = 1.0e-10 * Math.abs(p.getExpectedRoot());
+ assertTrue(solver.findRoot(p, new Checker(tol), 1000,
+ p.getA(), p.valueAt(p.getA()),
+ p.getB(), p.valueAt(p.getB())));
+ assertTrue(p.checkResult(solver.getRoot(), tol));
+ }
+
+ }
+
+ private class Checker implements ConvergenceChecker {
+
+ private double tolerance;
+
+ public Checker (double tolerance) {
+ this.tolerance = tolerance;
+ }
+
+ public int converged (double xLow, double fLow,
+ double xHigh, double fHigh) {
+ return (Math.abs(xHigh - xLow) <= tolerance)
+ ? ((Math.abs(fLow) <= Math.abs(fHigh))
+ ? ConvergenceChecker.LOW
+ : ConvergenceChecker.HIGH)
+ : ConvergenceChecker.NONE;
+ }
+
+ }
+
+ public static Test suite() {
+ return new TestSuite(BrentSolverTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/BrentSolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,418 @@
+// 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.roots;
+
+import org.spaceroots.mantissa.functions.scalar.ComputableFunction;
+
+import java.util.ArrayList;
+
+/** This class implement a reference problem for junit tests. */
+public abstract class TestProblem implements ComputableFunction {
+
+ private double a;
+ private double b;
+ private double expectedRoot;
+
+ protected TestProblem(double a, double b, double expectedRoot) {
+ this.a = a;
+ this.b = b;
+ this.expectedRoot = expectedRoot;
+ }
+
+ public double getA() {
+ return a;
+ }
+
+ public double getB() {
+ return b;
+ }
+
+ public double getExpectedRoot() {
+ return expectedRoot;
+ }
+
+ public boolean checkResult(double foundRoot, double tol) {
+ return Math.abs(foundRoot - expectedRoot) <= tol;
+ }
+
+ /** Get the reference problems from G. E. Alefeld, F. A. Potra and Y. Shi. */
+ public static TestProblem[] getAPSProblems() {
+
+ ArrayList problems = new ArrayList();
+
+ // problem 1
+ problems.add(new APSProblem1(Math.PI / 2, Math.PI, 1.8954942670340));
+
+ // problems 2 to 11
+ double[] roots2To11 = {
+ 3.0229153472731, 6.6837535608081, 11.238701655002, 19.676000080623,
+ 29.828227326505, 41.906116195289, 55.953595800143, 71.985665586588,
+ 90.008868539167, 110.02653274833
+ };
+ for (int k = 0, n = 1; n <= 10; ++n) {
+ problems.add(new APSProblems2To11(1.0e-9 + n * n,
+ (n+1) * (n+1) - 1.0e-9,
+ roots2To11[k++]));
+ }
+
+ // problems 12 to 14
+ problems.add(new APSProblems12To14( -40, -9.0, 31.0, 0.0));
+ problems.add(new APSProblems12To14(-100, -9.0, 31.0, 0.0));
+ problems.add(new APSProblems12To14(-200, -9.0, 31.0, 0.0));
+
+ // problems 15 to 17
+ int[] n15 = { 4, 6, 8, 10, 12 };
+ double[] roots15 = {
+ 0.66874030497642, 0.76472449133173, 0.81776543395794,
+ 0.85133992252078, 0.87448527222117
+ };
+ for (int k = 0; k < n15.length; ++k) {
+ problems.add(new APSProblems15To17(n15[k], 0.2, 0.0, 5.0, roots15[k]));
+ }
+
+ int[] n16 = { 4, 6, 8, 10, 12 };
+ for (int k = 0; k < n16.length; ++k) {
+ problems.add(new APSProblems15To17(n16[k], 1.0, 0.0, 5.0, 1.0));
+ }
+
+ int[] n17 = { 8, 10, 12, 14 };
+ for (int k = 0; k < n17.length; ++k) {
+ problems.add(new APSProblems15To17(n17[k], 1.0, -0.95, 4.05, 1.0));
+ }
+
+ // problem 18
+ problems.add(new APSProblem18(0.0, 1.5, 0.52359877559830));
+
+ // problem 19
+ int[] n19 = { 1, 2, 3, 4, 5, 20, 40, 60, 80, 100 };
+ double[] roots19 = {
+ 0.42247770964124, 0.30669941048320, 0.22370545765466,
+ 0.17171914751951, 0.13825715505682, 3.4657359020854e-2,
+ 1.7328679513999e-2, 1.1552453009332e-2, 8.6643397569993e-3,
+ 6.9314718055995e-3
+ };
+ for (int k = 0; k < n19.length; ++k) {
+ problems.add(new APSProblem19(n19[k], 0.0, 1.0, roots19[k]));
+ }
+
+ // problem 20
+ int[] n20 = { 5, 10, 20 };
+ double[] roots20 = {
+ 3.8402551840622e-2, 9.9000099980005e-3, 2.4937500390620e-3
+ };
+ for (int k = 0; k < n20.length; ++k) {
+ problems.add(new APSProblem20(n20[k], 0.0, 1.0, roots20[k]));
+ }
+
+ // problem 21
+ int[] n21 = { 2, 5, 10, 15, 20 };
+ double[] roots21 = {
+ 0.5, 0.34595481584824, 0.24512233375331,
+ 0.19554762353657, 0.16492095727644
+ };
+ for (int k = 0; k < n21.length; ++k) {
+ problems.add(new APSProblem21(n21[k], 0.0, 1.0, roots21[k]));
+ }
+
+ // problem 22
+ int[] n22 = { 1, 2, 4, 5, 8, 15, 20 };
+ double[] roots22 = {
+ 0.27550804099948, 0.13775402049974, 1.0305283778156e-2,
+ 3.6171081789041e-3, 4.1087291849640e-4, 2.5989575892908e-5,
+ 7.6685951221853e-6
+ };
+ for (int k = 0; k < n22.length; ++k) {
+ problems.add(new APSProblem22(n22[k], 0.0, 1.0, roots22[k]));
+ }
+
+ // problem 23
+ int[] n23 = { 1, 5, 10, 15, 20 };
+ double[] roots23 = {
+ 0.40105813754155, 0.51615351875793, 0.53952222690842,
+ 0.54818229434066, 0.55270466667849
+ };
+ for (int k = 0; k < n23.length; ++k) {
+ problems.add(new APSProblem23(n23[k], 0.0, 1.0, roots23[k]));
+ }
+
+ // problem 24
+ int[] n24 = { 2, 5, 15, 20 };
+ for (int k = 0; k < n24.length; ++k) {
+ problems.add(new APSProblem24(n24[k], 0.01, 1, 1.0 / n24[k]));
+ }
+
+ // problem 25
+ int[] n25 = {
+ 2, 3, 4, 5, 6,
+ 7, 9, 11, 13, 15,
+ 17, 19, 21, 23, 25,
+ 27, 29, 31, 33
+ };
+ for (int k = 0; k < n25.length; ++k) {
+ problems.add(new APSProblem25(n25[k], 1.0, 100.0, n25[k]));
+ }
+
+ // problem 26
+ problems.add(new APSProblem26(-1.0, 4.0, 0.0));
+
+ // problem 27
+ int[] n27 = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
+ };
+ for (int k = 0; k < n27.length; ++k) {
+ problems.add(new APSProblem27(n27[k], -10000.0, Math.PI / 2,
+ 0.62380651896161));
+ }
+
+ // problem 28
+ int[] n28 = {
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
+ double[] roots28 = {
+ 5.9051305594220e-5, 5.6367155339937e-5, 5.3916409455592e-5,
+ 5.1669892394942e-5, 4.9603096699145e-5, 4.7695285287639e-5,
+ 4.5928793239949e-5, 4.4288479195665e-5, 4.2761290257883e-5,
+ 4.1335913915954e-5, 4.0002497338020e-5, 3.8752419296207e-5,
+ 3.7578103559958e-5, 3.6472865219959e-5, 3.5430783356532e-5,
+ 3.4446594929961e-5, 3.3515605877800e-5, 3.2633616249437e-5,
+ 3.1796856858426e-5, 3.1001935436965e-5, 3.0245790670210e-5,
+ 1.2277994232462e-5, 6.1695393904409e-6, 4.1198585298293e-6,
+ 3.0924623877272e-6, 2.4752044261050e-6, 2.0633567678513e-6,
+ 1.7690120078154e-6, 1.5481615698859e-6, 1.3763345366022e-6,
+ 1.2388385788997e-6
+ };
+ for (int k = 0; k < n28.length; ++k) {
+ problems.add(new APSProblem28(n28[k], -10000.0, 10000.0, roots28[k]));
+ }
+
+ return (TestProblem[]) problems.toArray(new TestProblem[0]);
+
+ }
+
+ private static class APSProblem1 extends TestProblem {
+ public APSProblem1(double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ }
+ public double valueAt(double x) {
+ return Math.sin(x) - x / 2;
+ }
+ }
+
+ private static class APSProblems2To11 extends TestProblem {
+ public APSProblems2To11(double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ }
+ public double valueAt(double x) {
+ double f = 0;
+ for (int i = 1; i <= 20; ++i) {
+ double n = 2.0 * i - 5.0;
+ double d = x - i * i;
+ f += n * n / (d * d * d);
+ }
+ return -2 * f;
+ }
+ }
+
+ private static class APSProblems12To14 extends TestProblem {
+ private int n;
+ public APSProblems12To14(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ }
+ public double valueAt(double x) {
+ return n * x * Math.exp(-x);
+ }
+ }
+
+ private static class APSProblems15To17 extends TestProblem {
+ private int n;
+ private double u;
+ public APSProblems15To17(int n, double u,
+ double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ this.u = u;
+ }
+ public double valueAt(double x) {
+ return Math.pow(x, n) - u;
+ }
+ }
+
+ private static class APSProblem18 extends TestProblem {
+ public APSProblem18(double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ }
+ public double valueAt(double x) {
+ return Math.sin(x) - 0.5;
+ }
+ }
+
+ private static class APSProblem19 extends TestProblem {
+ private int n;
+ public APSProblem19(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ }
+ public double valueAt(double x) {
+ return 2.0 * x * Math.exp(-n) - 2.0 *Math.exp(-n * x) + 1.0;
+ }
+ }
+
+ private static class APSProblem20 extends TestProblem {
+ private int n;
+ private int oPoMn2;
+ public APSProblem20(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ int oMn = 1 - n;
+ oPoMn2 = 1 + oMn * oMn;
+ }
+ public double valueAt(double x) {
+ double v = 1.0 - n * x;
+ return oPoMn2 * x - v * v;
+ }
+ }
+
+ private static class APSProblem21 extends TestProblem {
+ private int n;
+ public APSProblem21(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ }
+ public double valueAt(double x) {
+ return x * x - Math.pow(1 - x, n);
+ }
+ }
+
+ private static class APSProblem22 extends TestProblem {
+ private int n;
+ private int oPoMn4;
+ public APSProblem22(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ int oMn = 1 - n;
+ int oMn2 = oMn * oMn;
+ oPoMn4 = 1 + oMn2 * oMn2;
+ }
+ public double valueAt(double x) {
+ double oMnx = 1 - n * x;
+ double oMnx2 = oMnx * oMnx;
+ return oPoMn4 * x - oMnx2 * oMnx2;
+ }
+ }
+
+ private static class APSProblem23 extends TestProblem {
+ private int n;
+ public APSProblem23(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ }
+ public double valueAt(double x) {
+ return (x - 1.0) * Math.exp(-n * x) + Math.pow(x, n);
+ }
+ }
+
+ private static class APSProblem24 extends TestProblem {
+ private int n;
+ public APSProblem24(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ this.n = n;
+ }
+ public double valueAt(double x) {
+ return (n * x - 1.0) / ((n - 1) * x);
+ }
+ }
+
+ private static class APSProblem25 extends TestProblem {
+ private double u;
+ private double v;;
+ public APSProblem25(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ u = 1.0 / n;
+ v = Math.pow(n, u);
+ }
+ public double valueAt(double x) {
+ return Math.pow(x, u) - v;
+ }
+ }
+
+ private static class APSProblem26 extends TestProblem {
+ public APSProblem26(double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ }
+ public double valueAt(double x) {
+ if (x == 0.0) {
+ return 0;
+ }
+ return x / Math.exp(1 / (x * x));
+ }
+
+ // this is a very special case since there is a wide range around
+ // the true root (which is 0) for which |f(x)| is smaller than the
+ // smallest representable positive number (according to IEEE 754):
+ // f(0.03762210865...) = 2^-1024
+ // f(0.03764056462...) = 2^-1023
+ // f(0.03765904777...) = 2^-1022
+ // f(0.03767755816...) = 2^-1021
+ // any root between -0.03768 and +0.03768 should be considered good
+ public boolean checkResult(double foundRoot, double tol) {
+ return Math.abs(foundRoot) <= 0.03768;
+ }
+
+ }
+
+ private static class APSProblem27 extends TestProblem {
+ private double u;
+ public APSProblem27(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ u = n / 20.0;
+ }
+ public double valueAt(double x) {
+ if (x >= 0.0) {
+ return (x / 1.5 + Math.sin(x) - 1.0) * u;
+ }
+ return -u;
+ }
+ }
+
+ private static class APSProblem28 extends TestProblem {
+ private double threshold;
+ private double yHigh;
+ private int u;
+ public APSProblem28(int n, double a, double b, double expectedRoot) {
+ super(a, b, expectedRoot);
+ threshold = 0.002 / (1 + n);
+ yHigh = Math.exp(1.0) - 1.859;
+ u = (n + 1) * 500;
+ }
+ public double valueAt(double x) {
+ if (x >= threshold) {
+ return yHigh;
+ } else if (x >= 0) {
+ return Math.exp(u * x) - 1.859;
+ } else {
+ return -0.859;
+ }
+ }
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/roots/TestProblem.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,37 @@
+// 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.utilities;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("org.spaceroots.mantissa.utilities");
+
+ suite.addTest(ArrayMapperTest.suite());
+ suite.addTest(MappableArrayTest.suite());
+ suite.addTest(MappableScalarTest.suite());
+ suite.addTest(IntervalTest.suite());
+ suite.addTest(IntervalsListTest.suite());
+
+ return suite;
+
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,146 @@
+// 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.utilities;
+
+import junit.framework.*;
+
+public class ArrayMapperTest
+ extends TestCase {
+
+ public ArrayMapperTest(String name) {
+ super(name);
+ mapper = null;
+ }
+
+ public void testDimensionCheck() {
+ int size = b1.getStateDimension();
+ size += b2.getStateDimension();
+ size += b3.getStateDimension();
+ assertTrue(mapper.getInternalDataArray().length == size);
+ }
+
+ public void testUpdateObjects() {
+
+ double[] data = new double [7];
+ for (int i = 0; i < 7; ++i) {
+ data [i] = i * 0.1;
+ }
+
+ mapper.updateObjects(data);
+
+ assertTrue(Math.abs(b1.getElement(0) - 0.0) < 1.0e-10);
+
+ assertTrue(Math.abs(b2.getElement(0) - 0.4) < 1.0e-10);
+ assertTrue(Math.abs(b2.getElement(1) - 0.3) < 1.0e-10);
+ assertTrue(Math.abs(b2.getElement(2) - 0.2) < 1.0e-10);
+ assertTrue(Math.abs(b2.getElement(3) - 0.1) < 1.0e-10);
+
+ assertTrue(Math.abs(b3.getElement(0) - 0.6) < 1.0e-10);
+ assertTrue(Math.abs(b3.getElement(1) - 0.5) < 1.0e-10);
+
+ }
+
+ public void testUpdateArray() {
+
+ b1.setElement(0, 0.0);
+
+ b2.setElement(0, 40.0);
+ b2.setElement(1, 30.0);
+ b2.setElement(2, 20.0);
+ b2.setElement(3, 10.0);
+
+ b3.setElement(0, 60.0);
+ b3.setElement(1, 50.0);
+
+ mapper.updateArray();
+
+ double[] data = mapper.getInternalDataArray();
+ for (int i = 0; i < 7; ++i) {
+ assertTrue(Math.abs(data [i] - i * 10.0) < 1.0e-10);
+ }
+
+ }
+
+ public void setUp() {
+
+ b1 = new DomainObject(1);
+ b2 = new DomainObject(4);
+ b3 = new DomainObject(2);
+
+ mapper = new ArrayMapper();
+ mapper.manageMappable(b1);
+ mapper.manageMappable(b2);
+ mapper.manageMappable(b3);
+
+ }
+
+ public void tearOff() {
+
+ b1 = null;
+ b2 = null;
+ b3 = null;
+
+ mapper = null;
+
+ }
+
+ public static Test suite() {
+ return new TestSuite(ArrayMapperTest.class);
+ }
+
+ private class DomainObject implements ArraySliceMappable {
+
+ private double[] data;
+
+ public DomainObject(int size) {
+ data = new double [size];
+ }
+
+ public int getStateDimension() {
+ return data.length;
+ }
+
+ public void mapStateFromArray(int start, double[] array) {
+ for (int i = 0; i < data.length; ++i) {
+ data [data.length - 1 - i] = array [start + i];
+ }
+ }
+
+ public void mapStateToArray(int start, double[] array) {
+ for (int i = 0; i < data.length; ++i) {
+ array [start + i] = data [data.length - 1 - i];
+ }
+ }
+
+ public double getElement(int i) {
+ return data [i];
+ }
+
+ public void setElement(int i, double value) {
+ data [i] = value;
+ }
+
+ }
+
+ private DomainObject b1;
+ private DomainObject b2;
+ private DomainObject b3;
+
+ private ArrayMapper mapper;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/ArrayMapperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,88 @@
+// 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.utilities;
+
+import junit.framework.*;
+
+public class IntervalTest
+ extends TestCase {
+
+ public IntervalTest(String name) {
+ super(name);
+ }
+
+ public void test1() {
+ check(new Interval(-10.0, 10.0), new Interval(11.0, 12.0), 2.5,
+ true, false, false,
+ new Interval(-10.0, 12.0), new Interval(11.0, 11.0));
+ }
+
+ public void test2() {
+ check(new Interval(-10.0, 10.0), new Interval(9.0, 12.0), 50.0,
+ false, false, true,
+ new Interval(-10.0, 12.0), new Interval(9.0, 10.0));
+ }
+
+ public void test3() {
+ check(new Interval(-10.0, 10.0), new Interval(-12.0, -11.0), 0.0,
+ true, false, false,
+ new Interval(-12.0, 10.0), new Interval(-10.0, -10.0));
+ }
+
+ public void test4() {
+ check(new Interval(-10.0, 10.0), new Interval(-4.0, 5.0), 0.0,
+ true, true, true,
+ new Interval(-10.0, 10.0), new Interval(-4.0, 5.0));
+ }
+
+ public void test5() {
+ check(new Interval(-10.0, 10.0), new Interval(-10.0, 10.0), 0.0,
+ true, true, true,
+ new Interval(-10.0, 10.0), new Interval(-10.0, 10.0));
+ }
+
+ private void check(Interval i1, Interval i2, double x,
+ boolean b1, boolean b2, boolean b3,
+ Interval add, Interval inter) {
+
+ assertTrue(i1.contains(x) ^ (!b1));
+ assertTrue(i1.contains(i2) ^ (!b2));
+ assertTrue(i1.intersects(i2) ^ (!b3));
+
+ assertEquals(add.getInf(), Interval.add(i1, i2).getInf(), 1.0e-10);
+ assertEquals(add.getSup(), Interval.add(i1, i2).getSup(), 1.0e-10);
+ assertEquals(inter.getInf(), Interval.intersection(i1, i2).getInf(), 1.0e-10);
+ assertEquals(inter.getSup(), Interval.intersection(i1, i2).getSup(), 1.0e-10);
+
+ Interval ia = new Interval(i1);
+ ia.addToSelf(i2);
+ assertEquals(add.getInf(), ia.getInf(), 1.0e-10);
+ assertEquals(add.getSup(), ia.getSup(), 1.0e-10);
+
+ Interval ib = new Interval(i1);
+ ib.intersectSelf(i2);
+ assertEquals(inter.getInf(), ib.getInf(), 1.0e-10);
+ assertEquals(inter.getSup(), ib.getSup(), 1.0e-10);
+
+ }
+
+ public static Test suite() {
+ return new TestSuite(IntervalTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,120 @@
+// 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.utilities;
+
+import java.util.Iterator;
+
+import junit.framework.*;
+
+public class IntervalsListTest
+ extends TestCase {
+
+ public IntervalsListTest(String name) {
+ super(name);
+ }
+
+ public void testAddBetween() {
+ IntervalsList il =
+ new IntervalsList (new Interval(10, 20), new Interval(50, 60));
+ il.addToSelf(new Interval(30, 40));
+ checkEquals(new Interval[] {
+ new Interval(10, 20),
+ new Interval(30, 40),
+ new Interval(50, 60)
+ }, il);
+ }
+
+ public void testAddReducingLastHole() {
+ IntervalsList il =
+ new IntervalsList (new Interval(10, 20), new Interval(50, 60));
+ il.addToSelf(new Interval(30, 55));
+ checkEquals(new Interval[] {
+ new Interval(10, 20),
+ new Interval(30, 60)
+ }, il);
+ }
+
+ public void test1() {
+
+ IntervalsList list1 = new IntervalsList(-2.0, -1.0);
+ IntervalsList list2 = new IntervalsList(new Interval(-0.9, -0.8));
+ check(list1, list2, 2.5,
+ true, false, 1, true, false, 1, false,
+ new Interval[] { new Interval(-2.0, -1.0),
+ new Interval(-0.9, -0.8) },
+ new Interval[0]);
+
+ list2.addToSelf(new Interval(1.0, 3.0));
+ check(list1, list2, 2.5,
+ true, false, 1, false, false, 2, false,
+ new Interval[] { new Interval(-2.0, -1.0),
+ new Interval(-0.9, -0.8),
+ new Interval( 1.0, 3.0) },
+ new Interval[0]);
+
+ list1.addToSelf(new Interval(-1.2, 0.0));
+ check(list1, list2, -1.1,
+ true, false, 1, false, false, 2, true,
+ new Interval[] { new Interval(-2.0, 0.0),
+ new Interval( 1.0, 3.0) },
+ new Interval[] { new Interval(-0.9, -0.8) });
+
+ IntervalsList list = new IntervalsList(new Interval(-10.0, -8.0));
+ list.addToSelf(new Interval(-6.0, -4.0));
+ list.addToSelf(new Interval(-0.85, 1.2));
+ list1.addToSelf(list);
+ check(list1, list2, 0,
+ false, false, 3, false, false, 2, true,
+ new Interval[] { new Interval(-10.0, -8.0),
+ new Interval( -6.0, -4.0),
+ new Interval( -2.0, 3.0) },
+ new Interval[] { new Interval( -0.9, -0.8),
+ new Interval( 1.0, 1.2) });
+
+ }
+
+ private void check(IntervalsList l1, IntervalsList l2, double x,
+ boolean b1, boolean b2, int i1,
+ boolean b3, boolean b4, int i2,
+ boolean b5, Interval[] add, Interval[] inter) {
+ assertTrue(l1.isConnex() ^ (!b1));
+ assertTrue(l1.isEmpty() ^ (!b2));
+ assertEquals(i1, l1.getIntervals().size());
+ assertTrue(l2.isConnex() ^ (!b3));
+ assertTrue(l2.isEmpty() ^ (!b4));
+ assertEquals(i2, l2.getIntervals().size());
+ assertTrue(l1.contains(x) ^ (!b5));
+ checkEquals(add, IntervalsList.add(l1, l2));
+ checkEquals(inter, IntervalsList.intersection(l1, l2));
+ }
+
+ private void checkEquals(Interval[] sa, IntervalsList sb) {
+ assertEquals(sa.length, sb.getIntervals().size());
+ Iterator iterB = sb.getIntervals().iterator();
+ for (int i = 0; i < sa.length; ++i) {
+ Interval ib = (Interval) iterB.next();
+ assertEquals(sa[i].getInf(), ib.getInf(), 1.0e-10);
+ assertEquals(sa[i].getSup(), ib.getSup(), 1.0e-10);
+ }
+ }
+
+ public static Test suite() {
+ return new TestSuite(IntervalsListTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/IntervalsListTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,146 @@
+// 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.utilities;
+
+import junit.framework.*;
+
+public class MappableArrayTest
+ extends TestCase {
+
+ public MappableArrayTest(String name) {
+ super(name);
+ }
+
+ public void testDimensionCheck() {
+ assertTrue(mapper.getInternalDataArray().length == 9);
+ }
+
+ public void testRealloc() {
+
+ for (int i = 0; i < reusedArray.length; ++i) {
+ reusedArray[i] = -1.0;
+ }
+
+ for (int i = 0; i < clonedArray.length; ++i) {
+ clonedArray[i] = -1.0;
+ }
+
+ double[] data = new double [mapper.getInternalDataArray().length];
+ for (int i = 0; i < data.length; ++i) {
+ data [i] = i * 0.1;
+ }
+
+ mapper.updateObjects(data);
+
+ assertTrue(Math.abs(reusedArray[0] - 0.4) < 1.0e-10);
+ assertTrue(Math.abs(reusedArray[1] - 0.5) < 1.0e-10);
+
+ assertTrue(Math.abs(clonedArray[0] + 1.0) < 1.0e-10);
+ assertTrue(Math.abs(clonedArray[1] + 1.0) < 1.0e-10);
+ assertTrue(Math.abs(clonedArray[2] + 1.0) < 1.0e-10);
+
+ }
+
+ public void testUpdateObjects() {
+
+ double[] data = new double [mapper.getInternalDataArray().length];
+ for (int i = 0; i < data.length; ++i) {
+ data [i] = i * 0.1;
+ }
+
+ mapper.updateObjects(data);
+
+ assertTrue(Math.abs(array1.getArray()[0] - 0.0) < 1.0e-10);
+ assertTrue(Math.abs(array1.getArray()[1] - 0.1) < 1.0e-10);
+ assertTrue(Math.abs(array1.getArray()[2] - 0.2) < 1.0e-10);
+ assertTrue(Math.abs(array1.getArray()[3] - 0.3) < 1.0e-10);
+
+ assertTrue(Math.abs(array2.getArray()[0] - 0.4) < 1.0e-10);
+ assertTrue(Math.abs(array2.getArray()[1] - 0.5) < 1.0e-10);
+
+ assertTrue(Math.abs(array3.getArray()[0] - 0.6) < 1.0e-10);
+ assertTrue(Math.abs(array3.getArray()[1] - 0.7) < 1.0e-10);
+ assertTrue(Math.abs(array3.getArray()[2] - 0.8) < 1.0e-10);
+
+ }
+
+ public void testUpdateArray() {
+
+ array1.getArray()[0] = 00.0;
+ array1.getArray()[1] = 10.0;
+ array1.getArray()[2] = 20.0;
+ array1.getArray()[3] = 30.0;
+
+ array2.getArray()[0] = 40.0;
+ array2.getArray()[1] = 50.0;
+
+ array3.getArray()[0] = 60.0;
+ array3.getArray()[1] = 70.0;
+ array3.getArray()[2] = 80.0;
+
+ mapper.updateArray();
+
+ double[] data = mapper.getInternalDataArray();
+ for (int i = 0; i < data.length; ++i) {
+ assertTrue(Math.abs(data [i] - i * 10.0) < 1.0e-10);
+ }
+
+ }
+
+ public static Test suite() {
+ return new TestSuite(MappableArrayTest.class);
+ }
+
+ public void setUp() {
+
+ reusedArray = new double[2];
+ clonedArray = new double[3];
+
+ array1 = new MappableArray(4);
+ array2 = new MappableArray(reusedArray, false);
+ array3 = new MappableArray(clonedArray, true);
+
+ mapper = new ArrayMapper();
+ mapper.manageMappable(array1);
+ mapper.manageMappable(array2);
+ mapper.manageMappable(array3);
+
+ }
+
+ public void tearDown() {
+ reusedArray = null;
+ clonedArray = null;
+
+ array1 = null;
+ array2 = null;
+ array3 = null;
+
+ mapper = null;
+
+ }
+
+ private double[] reusedArray;
+ private double[] clonedArray;
+
+ private MappableArray array1;
+ private MappableArray array2;
+ private MappableArray array3;
+
+ private ArrayMapper mapper;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableArrayTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,96 @@
+// 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.utilities;
+
+import junit.framework.*;
+
+public class MappableScalarTest
+ extends TestCase {
+
+ public MappableScalarTest(String name) {
+ super(name);
+ }
+
+ public void testDimensionCheck() {
+ assertTrue(mapper.getInternalDataArray().length == 3);
+ }
+
+ public void testUpdateObjects() {
+
+ double[] data = new double [mapper.getInternalDataArray().length];
+ for (int i = 0; i < data.length; ++i) {
+ data [i] = i * 0.1;
+ }
+
+ mapper.updateObjects(data);
+
+ assertTrue(Math.abs(scalar1.getValue() - 0.0) < 1.0e-10);
+ assertTrue(Math.abs(scalar2.getValue() - 0.1) < 1.0e-10);
+ assertTrue(Math.abs(scalar3.getValue() - 0.2) < 1.0e-10);
+
+ }
+
+ public void testUpdateArray() {
+
+ scalar1.setValue(00.0);
+ scalar2.setValue(10.0);
+ scalar3.setValue(20.0);
+
+ mapper.updateArray();
+
+ double[] data = mapper.getInternalDataArray();
+ for (int i = 0; i < data.length; ++i) {
+ assertTrue(Math.abs(data [i] - i * 10.0) < 1.0e-10);
+ }
+
+ }
+
+ public static Test suite() {
+ return new TestSuite(MappableScalarTest.class);
+ }
+
+ public void setUp() {
+
+ scalar1 = new MappableScalar();
+ scalar2 = new MappableScalar(2);
+ scalar3 = new MappableScalar(-3);
+
+ mapper = new ArrayMapper();
+ mapper.manageMappable(scalar1);
+ mapper.manageMappable(scalar2);
+ mapper.manageMappable(scalar3);
+
+ }
+
+ public void tearDown() {
+
+ scalar1 = null;
+ scalar2 = null;
+ scalar3 = null;
+
+ mapper = null;
+
+ }
+
+ private MappableScalar scalar1;
+ private MappableScalar scalar2;
+ private MappableScalar scalar3;
+
+ private ArrayMapper mapper;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/utilities/MappableScalarTest.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