You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by lu...@apache.org on 2007/02/12 23:35:10 UTC
svn commit: r506713 [3/4] - in /jakarta/commons/proper/math/trunk: ./
src/java/org/apache/commons/math/analysis/
src/java/org/apache/commons/math/distribution/
src/java/org/apache/commons/math/fraction/
src/test/org/apache/commons/math/analysis/ src/te...
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java Mon Feb 12 14:35:08 2007
@@ -1,150 +1,150 @@
-/*
- * 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.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Lagrange form of polynomial function.
- * <p>
- * We use n+1 points to interpolate a polynomial of degree n. This should
- * give us the exact same polynomial as result. Thus we can use a very
- * small tolerance to account only for round-off errors.
- *
- * @version $Revision$ $Date$
- */
-public final class PolynomialFunctionLagrangeFormTest extends TestCase {
-
- /**
- * Test of polynomial for the linear function.
- */
- public void testLinearFunction() throws MathException {
- PolynomialFunctionLagrangeForm p;
- double c[], z, expected, result, tolerance = 1E-12;
-
- // p(x) = 1.5x - 4
- double x[] = { 0.0, 3.0 };
- double y[] = { -4.0, 0.5 };
- p = new PolynomialFunctionLagrangeForm(x, y);
-
- z = 2.0; expected = -1.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 4.5; expected = 2.75; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 6.0; expected = 5.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- assertEquals(1, p.degree());
-
- c = p.getCoefficients();
- assertEquals(2, c.length);
- assertEquals(-4.0, c[0], tolerance);
- assertEquals(1.5, c[1], tolerance);
- }
-
- /**
- * Test of polynomial for the quadratic function.
- */
- public void testQuadraticFunction() throws MathException {
- PolynomialFunctionLagrangeForm p;
- double c[], z, expected, result, tolerance = 1E-12;
-
- // p(x) = 2x^2 + 5x - 3 = (2x - 1)(x + 3)
- double x[] = { 0.0, -1.0, 0.5 };
- double y[] = { -3.0, -6.0, 0.0 };
- p = new PolynomialFunctionLagrangeForm(x, y);
-
- z = 1.0; expected = 4.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 2.5; expected = 22.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = -2.0; expected = -5.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- assertEquals(2, p.degree());
-
- c = p.getCoefficients();
- assertEquals(3, c.length);
- assertEquals(-3.0, c[0], tolerance);
- assertEquals(5.0, c[1], tolerance);
- assertEquals(2.0, c[2], tolerance);
- }
-
- /**
- * Test of polynomial for the quintic function.
- */
- public void testQuinticFunction() throws MathException {
- PolynomialFunctionLagrangeForm p;
- double c[], z, expected, result, tolerance = 1E-12;
-
- // p(x) = x^5 - x^4 - 7x^3 + x^2 + 6x = x(x^2 - 1)(x + 2)(x - 3)
- double x[] = { 1.0, -1.0, 2.0, 3.0, -3.0, 0.5 };
- double y[] = { 0.0, 0.0, -24.0, 0.0, -144.0, 2.34375 };
- p = new PolynomialFunctionLagrangeForm(x, y);
-
- z = 0.0; expected = 0.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = -2.0; expected = 0.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 4.0; expected = 360.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- assertEquals(5, p.degree());
-
- c = p.getCoefficients();
- assertEquals(6, c.length);
- assertEquals(0.0, c[0], tolerance);
- assertEquals(6.0, c[1], tolerance);
- assertEquals(1.0, c[2], tolerance);
- assertEquals(-7.0, c[3], tolerance);
- assertEquals(-1.0, c[4], tolerance);
- assertEquals(1.0, c[5], tolerance);
- }
-
- /**
- * Test of parameters for the polynomial.
- */
- public void testParameters() throws Exception {
- PolynomialFunctionLagrangeForm p;
-
- try {
- // bad input array length
- double x[] = { 1.0 };
- double y[] = { 2.0 };
- p = new PolynomialFunctionLagrangeForm(x, y);
- fail("Expecting IllegalArgumentException - bad input array length");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- try {
- // mismatch input arrays
- double x[] = { 1.0, 2.0, 3.0, 4.0 };
- double y[] = { 0.0, -4.0, -24.0 };
- p = new PolynomialFunctionLagrangeForm(x, y);
- fail("Expecting IllegalArgumentException - mismatch input arrays");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-}
+/*
+ * 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.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Lagrange form of polynomial function.
+ * <p>
+ * We use n+1 points to interpolate a polynomial of degree n. This should
+ * give us the exact same polynomial as result. Thus we can use a very
+ * small tolerance to account only for round-off errors.
+ *
+ * @version $Revision$ $Date$
+ */
+public final class PolynomialFunctionLagrangeFormTest extends TestCase {
+
+ /**
+ * Test of polynomial for the linear function.
+ */
+ public void testLinearFunction() throws MathException {
+ PolynomialFunctionLagrangeForm p;
+ double c[], z, expected, result, tolerance = 1E-12;
+
+ // p(x) = 1.5x - 4
+ double x[] = { 0.0, 3.0 };
+ double y[] = { -4.0, 0.5 };
+ p = new PolynomialFunctionLagrangeForm(x, y);
+
+ z = 2.0; expected = -1.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 4.5; expected = 2.75; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 6.0; expected = 5.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ assertEquals(1, p.degree());
+
+ c = p.getCoefficients();
+ assertEquals(2, c.length);
+ assertEquals(-4.0, c[0], tolerance);
+ assertEquals(1.5, c[1], tolerance);
+ }
+
+ /**
+ * Test of polynomial for the quadratic function.
+ */
+ public void testQuadraticFunction() throws MathException {
+ PolynomialFunctionLagrangeForm p;
+ double c[], z, expected, result, tolerance = 1E-12;
+
+ // p(x) = 2x^2 + 5x - 3 = (2x - 1)(x + 3)
+ double x[] = { 0.0, -1.0, 0.5 };
+ double y[] = { -3.0, -6.0, 0.0 };
+ p = new PolynomialFunctionLagrangeForm(x, y);
+
+ z = 1.0; expected = 4.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 2.5; expected = 22.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = -2.0; expected = -5.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ assertEquals(2, p.degree());
+
+ c = p.getCoefficients();
+ assertEquals(3, c.length);
+ assertEquals(-3.0, c[0], tolerance);
+ assertEquals(5.0, c[1], tolerance);
+ assertEquals(2.0, c[2], tolerance);
+ }
+
+ /**
+ * Test of polynomial for the quintic function.
+ */
+ public void testQuinticFunction() throws MathException {
+ PolynomialFunctionLagrangeForm p;
+ double c[], z, expected, result, tolerance = 1E-12;
+
+ // p(x) = x^5 - x^4 - 7x^3 + x^2 + 6x = x(x^2 - 1)(x + 2)(x - 3)
+ double x[] = { 1.0, -1.0, 2.0, 3.0, -3.0, 0.5 };
+ double y[] = { 0.0, 0.0, -24.0, 0.0, -144.0, 2.34375 };
+ p = new PolynomialFunctionLagrangeForm(x, y);
+
+ z = 0.0; expected = 0.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = -2.0; expected = 0.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 4.0; expected = 360.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ assertEquals(5, p.degree());
+
+ c = p.getCoefficients();
+ assertEquals(6, c.length);
+ assertEquals(0.0, c[0], tolerance);
+ assertEquals(6.0, c[1], tolerance);
+ assertEquals(1.0, c[2], tolerance);
+ assertEquals(-7.0, c[3], tolerance);
+ assertEquals(-1.0, c[4], tolerance);
+ assertEquals(1.0, c[5], tolerance);
+ }
+
+ /**
+ * Test of parameters for the polynomial.
+ */
+ public void testParameters() throws Exception {
+ PolynomialFunctionLagrangeForm p;
+
+ try {
+ // bad input array length
+ double x[] = { 1.0 };
+ double y[] = { 2.0 };
+ p = new PolynomialFunctionLagrangeForm(x, y);
+ fail("Expecting IllegalArgumentException - bad input array length");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ try {
+ // mismatch input arrays
+ double x[] = { 1.0, 2.0, 3.0, 4.0 };
+ double y[] = { 0.0, -4.0, -24.0 };
+ p = new PolynomialFunctionLagrangeForm(x, y);
+ fail("Expecting IllegalArgumentException - mismatch input arrays");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java
('svn:executable' removed)
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java Mon Feb 12 14:35:08 2007
@@ -1,149 +1,149 @@
-/*
- * 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.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Newton form of polynomial function.
- * <p>
- * The small tolerance number is used only to account for round-off errors.
- *
- * @version $Revision$ $Date$
- */
-public final class PolynomialFunctionNewtonFormTest extends TestCase {
-
- /**
- * Test of polynomial for the linear function.
- */
- public void testLinearFunction() throws MathException {
- PolynomialFunctionNewtonForm p;
- double coefficients[], z, expected, result, tolerance = 1E-12;
-
- // p(x) = 1.5x - 4 = 2 + 1.5(x-4)
- double a[] = { 2.0, 1.5 };
- double c[] = { 4.0 };
- p = new PolynomialFunctionNewtonForm(a, c);
-
- z = 2.0; expected = -1.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 4.5; expected = 2.75; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 6.0; expected = 5.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- assertEquals(1, p.degree());
-
- coefficients = p.getCoefficients();
- assertEquals(2, coefficients.length);
- assertEquals(-4.0, coefficients[0], tolerance);
- assertEquals(1.5, coefficients[1], tolerance);
- }
-
- /**
- * Test of polynomial for the quadratic function.
- */
- public void testQuadraticFunction() throws MathException {
- PolynomialFunctionNewtonForm p;
- double coefficients[], z, expected, result, tolerance = 1E-12;
-
- // p(x) = 2x^2 + 5x - 3 = 4 + 3(x-1) + 2(x-1)(x+2)
- double a[] = { 4.0, 3.0, 2.0 };
- double c[] = { 1.0, -2.0 };
- p = new PolynomialFunctionNewtonForm(a, c);
-
- z = 1.0; expected = 4.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 2.5; expected = 22.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = -2.0; expected = -5.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- assertEquals(2, p.degree());
-
- coefficients = p.getCoefficients();
- assertEquals(3, coefficients.length);
- assertEquals(-3.0, coefficients[0], tolerance);
- assertEquals(5.0, coefficients[1], tolerance);
- assertEquals(2.0, coefficients[2], tolerance);
- }
-
- /**
- * Test of polynomial for the quintic function.
- */
- public void testQuinticFunction() throws MathException {
- PolynomialFunctionNewtonForm p;
- double coefficients[], z, expected, result, tolerance = 1E-12;
-
- // p(x) = x^5 - x^4 - 7x^3 + x^2 + 6x
- // = 6x - 6x^2 -6x^2(x-1) + x^2(x-1)(x+1) + x^2(x-1)(x+1)(x-2)
- double a[] = { 0.0, 6.0, -6.0, -6.0, 1.0, 1.0 };
- double c[] = { 0.0, 0.0, 1.0, -1.0, 2.0 };
- p = new PolynomialFunctionNewtonForm(a, c);
-
- z = 0.0; expected = 0.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = -2.0; expected = 0.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- z = 4.0; expected = 360.0; result = p.value(z);
- assertEquals(expected, result, tolerance);
-
- assertEquals(5, p.degree());
-
- coefficients = p.getCoefficients();
- assertEquals(6, coefficients.length);
- assertEquals(0.0, coefficients[0], tolerance);
- assertEquals(6.0, coefficients[1], tolerance);
- assertEquals(1.0, coefficients[2], tolerance);
- assertEquals(-7.0, coefficients[3], tolerance);
- assertEquals(-1.0, coefficients[4], tolerance);
- assertEquals(1.0, coefficients[5], tolerance);
- }
-
- /**
- * Test of parameters for the polynomial.
- */
- public void testParameters() throws Exception {
- PolynomialFunctionNewtonForm p;
-
- try {
- // bad input array length
- double a[] = { 1.0 };
- double c[] = { 2.0 };
- p = new PolynomialFunctionNewtonForm(a, c);
- fail("Expecting IllegalArgumentException - bad input array length");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- try {
- // mismatch input arrays
- double a[] = { 1.0, 2.0, 3.0, 4.0 };
- double c[] = { 4.0, 3.0, 2.0, 1.0 };
- p = new PolynomialFunctionNewtonForm(a, c);
- fail("Expecting IllegalArgumentException - mismatch input arrays");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-}
+/*
+ * 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.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Newton form of polynomial function.
+ * <p>
+ * The small tolerance number is used only to account for round-off errors.
+ *
+ * @version $Revision$ $Date$
+ */
+public final class PolynomialFunctionNewtonFormTest extends TestCase {
+
+ /**
+ * Test of polynomial for the linear function.
+ */
+ public void testLinearFunction() throws MathException {
+ PolynomialFunctionNewtonForm p;
+ double coefficients[], z, expected, result, tolerance = 1E-12;
+
+ // p(x) = 1.5x - 4 = 2 + 1.5(x-4)
+ double a[] = { 2.0, 1.5 };
+ double c[] = { 4.0 };
+ p = new PolynomialFunctionNewtonForm(a, c);
+
+ z = 2.0; expected = -1.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 4.5; expected = 2.75; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 6.0; expected = 5.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ assertEquals(1, p.degree());
+
+ coefficients = p.getCoefficients();
+ assertEquals(2, coefficients.length);
+ assertEquals(-4.0, coefficients[0], tolerance);
+ assertEquals(1.5, coefficients[1], tolerance);
+ }
+
+ /**
+ * Test of polynomial for the quadratic function.
+ */
+ public void testQuadraticFunction() throws MathException {
+ PolynomialFunctionNewtonForm p;
+ double coefficients[], z, expected, result, tolerance = 1E-12;
+
+ // p(x) = 2x^2 + 5x - 3 = 4 + 3(x-1) + 2(x-1)(x+2)
+ double a[] = { 4.0, 3.0, 2.0 };
+ double c[] = { 1.0, -2.0 };
+ p = new PolynomialFunctionNewtonForm(a, c);
+
+ z = 1.0; expected = 4.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 2.5; expected = 22.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = -2.0; expected = -5.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ assertEquals(2, p.degree());
+
+ coefficients = p.getCoefficients();
+ assertEquals(3, coefficients.length);
+ assertEquals(-3.0, coefficients[0], tolerance);
+ assertEquals(5.0, coefficients[1], tolerance);
+ assertEquals(2.0, coefficients[2], tolerance);
+ }
+
+ /**
+ * Test of polynomial for the quintic function.
+ */
+ public void testQuinticFunction() throws MathException {
+ PolynomialFunctionNewtonForm p;
+ double coefficients[], z, expected, result, tolerance = 1E-12;
+
+ // p(x) = x^5 - x^4 - 7x^3 + x^2 + 6x
+ // = 6x - 6x^2 -6x^2(x-1) + x^2(x-1)(x+1) + x^2(x-1)(x+1)(x-2)
+ double a[] = { 0.0, 6.0, -6.0, -6.0, 1.0, 1.0 };
+ double c[] = { 0.0, 0.0, 1.0, -1.0, 2.0 };
+ p = new PolynomialFunctionNewtonForm(a, c);
+
+ z = 0.0; expected = 0.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = -2.0; expected = 0.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ z = 4.0; expected = 360.0; result = p.value(z);
+ assertEquals(expected, result, tolerance);
+
+ assertEquals(5, p.degree());
+
+ coefficients = p.getCoefficients();
+ assertEquals(6, coefficients.length);
+ assertEquals(0.0, coefficients[0], tolerance);
+ assertEquals(6.0, coefficients[1], tolerance);
+ assertEquals(1.0, coefficients[2], tolerance);
+ assertEquals(-7.0, coefficients[3], tolerance);
+ assertEquals(-1.0, coefficients[4], tolerance);
+ assertEquals(1.0, coefficients[5], tolerance);
+ }
+
+ /**
+ * Test of parameters for the polynomial.
+ */
+ public void testParameters() throws Exception {
+ PolynomialFunctionNewtonForm p;
+
+ try {
+ // bad input array length
+ double a[] = { 1.0 };
+ double c[] = { 2.0 };
+ p = new PolynomialFunctionNewtonForm(a, c);
+ fail("Expecting IllegalArgumentException - bad input array length");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ try {
+ // mismatch input arrays
+ double a[] = { 1.0, 2.0, 3.0, 4.0 };
+ double c[] = { 4.0, 3.0, 2.0, 1.0 };
+ p = new PolynomialFunctionNewtonForm(a, c);
+ fail("Expecting IllegalArgumentException - mismatch input arrays");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java
('svn:executable' removed)
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java Mon Feb 12 14:35:08 2007
@@ -1,132 +1,132 @@
-/*
- * 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.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Ridders solver.
- * <p>
- * Ridders' method converges superlinearly, more specific, its rate of
- * convergence is sqrt(2). Test runs show that for a default absolute
- * accuracy of 1E-6, it generally takes less than 5 iterations for close
- * initial bracket and 5 to 10 iterations for distant initial bracket
- * to converge.
- *
- * @version $Revision$ $Date$
- */
-public final class RiddersSolverTest extends TestCase {
-
- /**
- * Test of solver for the sine function.
- */
- public void testSinFunction() throws MathException {
- UnivariateRealFunction f = new SinFunction();
- UnivariateRealSolver solver = new RiddersSolver(f);
- double min, max, expected, result, tolerance;
-
- min = 3.0; max = 4.0; expected = Math.PI;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
-
- min = -1.0; max = 1.5; expected = 0.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
- }
-
- /**
- * Test of solver for the quintic function.
- */
- public void testQuinticFunction() throws MathException {
- UnivariateRealFunction f = new QuinticFunction();
- UnivariateRealSolver solver = new RiddersSolver(f);
- double min, max, expected, result, tolerance;
-
- min = -0.4; max = 0.2; expected = 0.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
-
- min = 0.75; max = 1.5; expected = 1.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
-
- min = -0.9; max = -0.2; expected = -0.5;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
- }
-
- /**
- * Test of solver for the exponential function.
- */
- public void testExpm1Function() throws MathException {
- UnivariateRealFunction f = new Expm1Function();
- UnivariateRealSolver solver = new RiddersSolver(f);
- double min, max, expected, result, tolerance;
-
- min = -1.0; max = 2.0; expected = 0.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
-
- min = -20.0; max = 10.0; expected = 0.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
-
- min = -50.0; max = 100.0; expected = 0.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
- result = solver.solve(min, max);
- assertEquals(expected, result, tolerance);
- }
-
- /**
- * Test of parameters for the solver.
- */
- public void testParameters() throws Exception {
- UnivariateRealFunction f = new SinFunction();
- UnivariateRealSolver solver = new RiddersSolver(f);
-
- try {
- // bad interval
- solver.solve(1, -1);
- fail("Expecting IllegalArgumentException - bad interval");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- try {
- // no bracketing
- solver.solve(2, 3);
- fail("Expecting IllegalArgumentException - no bracketing");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-}
+/*
+ * 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.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Ridders solver.
+ * <p>
+ * Ridders' method converges superlinearly, more specific, its rate of
+ * convergence is sqrt(2). Test runs show that for a default absolute
+ * accuracy of 1E-6, it generally takes less than 5 iterations for close
+ * initial bracket and 5 to 10 iterations for distant initial bracket
+ * to converge.
+ *
+ * @version $Revision$ $Date$
+ */
+public final class RiddersSolverTest extends TestCase {
+
+ /**
+ * Test of solver for the sine function.
+ */
+ public void testSinFunction() throws MathException {
+ UnivariateRealFunction f = new SinFunction();
+ UnivariateRealSolver solver = new RiddersSolver(f);
+ double min, max, expected, result, tolerance;
+
+ min = 3.0; max = 4.0; expected = Math.PI;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+
+ min = -1.0; max = 1.5; expected = 0.0;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+ }
+
+ /**
+ * Test of solver for the quintic function.
+ */
+ public void testQuinticFunction() throws MathException {
+ UnivariateRealFunction f = new QuinticFunction();
+ UnivariateRealSolver solver = new RiddersSolver(f);
+ double min, max, expected, result, tolerance;
+
+ min = -0.4; max = 0.2; expected = 0.0;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+
+ min = 0.75; max = 1.5; expected = 1.0;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+
+ min = -0.9; max = -0.2; expected = -0.5;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+ }
+
+ /**
+ * Test of solver for the exponential function.
+ */
+ public void testExpm1Function() throws MathException {
+ UnivariateRealFunction f = new Expm1Function();
+ UnivariateRealSolver solver = new RiddersSolver(f);
+ double min, max, expected, result, tolerance;
+
+ min = -1.0; max = 2.0; expected = 0.0;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+
+ min = -20.0; max = 10.0; expected = 0.0;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+
+ min = -50.0; max = 100.0; expected = 0.0;
+ tolerance = Math.max(solver.getAbsoluteAccuracy(),
+ Math.abs(expected * solver.getRelativeAccuracy()));
+ result = solver.solve(min, max);
+ assertEquals(expected, result, tolerance);
+ }
+
+ /**
+ * Test of parameters for the solver.
+ */
+ public void testParameters() throws Exception {
+ UnivariateRealFunction f = new SinFunction();
+ UnivariateRealSolver solver = new RiddersSolver(f);
+
+ try {
+ // bad interval
+ solver.solve(1, -1);
+ fail("Expecting IllegalArgumentException - bad interval");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ try {
+ // no bracketing
+ solver.solve(2, 3);
+ fail("Expecting IllegalArgumentException - no bracketing");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java
('svn:executable' removed)
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/CauchyDistributionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/CauchyDistributionTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/CauchyDistributionTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/CauchyDistributionTest.java Mon Feb 12 14:35:08 2007
@@ -1,97 +1,97 @@
-/*
- * 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.apache.commons.math.distribution;
-
-/**
- * Test cases for CauchyDistribution.
- * Extends ContinuousDistributionAbstractTest. See class javadoc for
- * ContinuousDistributionAbstractTest for details.
- *
- * @version $Revision$ $Date$
- */
-public class CauchyDistributionTest extends ContinuousDistributionAbstractTest {
-
- /**
- * Constructor for CauchyDistributionTest.
- * @param arg0
- */
- public CauchyDistributionTest(String arg0) {
- super(arg0);
- }
-
- //-------------- Implementations for abstract methods -----------------------
-
- /** Creates the default continuous distribution instance to use in tests. */
- public ContinuousDistribution makeDistribution() {
- return DistributionFactory.newInstance().createCauchyDistribution(1.2, 2.1);
- }
-
- /** Creates the default cumulative probability distribution test input values */
- public double[] makeCumulativeTestPoints() {
- // quantiles computed using Mathematica
- return new double[] {-667.2485619d, -65.6230835d, -25.48302995d,
- -12.05887818d, -5.263135428d, 7.663135428d, 14.45887818d,
- 27.88302995d, 68.0230835d, 669.6485619d};
- }
-
- /** Creates the default cumulative probability density test expected values */
- public double[] makeCumulativeTestValues() {
- return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
- 0.975d, 0.990d, 0.999d};
- }
-
- //---------------------------- Additional test cases -------------------------
-
- public void testInverseCumulativeProbabilityExtremes() throws Exception {
- setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
- setInverseCumulativeTestValues(
- new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY});
- verifyInverseCumulativeProbabilities();
- }
-
- public void testMedian() {
- CauchyDistribution distribution = (CauchyDistribution) getDistribution();
- double expected = Math.random();
- distribution.setMedian(expected);
- assertEquals(expected, distribution.getMedian(), 0.0);
- }
-
- public void testScale() {
- CauchyDistribution distribution = (CauchyDistribution) getDistribution();
- double expected = Math.random();
- distribution.setScale(expected);
- assertEquals(expected, distribution.getScale(), 0.0);
- }
-
- public void testSetScale() {
- CauchyDistribution distribution = (CauchyDistribution) getDistribution();
- try {
- distribution.setScale(0.0);
- fail("Can not have 0.0 scale.");
- } catch (IllegalArgumentException ex) {
- // success
- }
-
- try {
- distribution.setScale(-1.0);
- fail("Can not have negative scale.");
- } catch (IllegalArgumentException ex) {
- // success
- }
- }
-}
+/*
+ * 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.apache.commons.math.distribution;
+
+/**
+ * Test cases for CauchyDistribution.
+ * Extends ContinuousDistributionAbstractTest. See class javadoc for
+ * ContinuousDistributionAbstractTest for details.
+ *
+ * @version $Revision$ $Date$
+ */
+public class CauchyDistributionTest extends ContinuousDistributionAbstractTest {
+
+ /**
+ * Constructor for CauchyDistributionTest.
+ * @param arg0
+ */
+ public CauchyDistributionTest(String arg0) {
+ super(arg0);
+ }
+
+ //-------------- Implementations for abstract methods -----------------------
+
+ /** Creates the default continuous distribution instance to use in tests. */
+ public ContinuousDistribution makeDistribution() {
+ return DistributionFactory.newInstance().createCauchyDistribution(1.2, 2.1);
+ }
+
+ /** Creates the default cumulative probability distribution test input values */
+ public double[] makeCumulativeTestPoints() {
+ // quantiles computed using Mathematica
+ return new double[] {-667.2485619d, -65.6230835d, -25.48302995d,
+ -12.05887818d, -5.263135428d, 7.663135428d, 14.45887818d,
+ 27.88302995d, 68.0230835d, 669.6485619d};
+ }
+
+ /** Creates the default cumulative probability density test expected values */
+ public double[] makeCumulativeTestValues() {
+ return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
+ 0.975d, 0.990d, 0.999d};
+ }
+
+ //---------------------------- Additional test cases -------------------------
+
+ public void testInverseCumulativeProbabilityExtremes() throws Exception {
+ setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
+ setInverseCumulativeTestValues(
+ new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY});
+ verifyInverseCumulativeProbabilities();
+ }
+
+ public void testMedian() {
+ CauchyDistribution distribution = (CauchyDistribution) getDistribution();
+ double expected = Math.random();
+ distribution.setMedian(expected);
+ assertEquals(expected, distribution.getMedian(), 0.0);
+ }
+
+ public void testScale() {
+ CauchyDistribution distribution = (CauchyDistribution) getDistribution();
+ double expected = Math.random();
+ distribution.setScale(expected);
+ assertEquals(expected, distribution.getScale(), 0.0);
+ }
+
+ public void testSetScale() {
+ CauchyDistribution distribution = (CauchyDistribution) getDistribution();
+ try {
+ distribution.setScale(0.0);
+ fail("Can not have 0.0 scale.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ distribution.setScale(-1.0);
+ fail("Can not have negative scale.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/CauchyDistributionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/WeibullDistributionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/WeibullDistributionTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/WeibullDistributionTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/WeibullDistributionTest.java Mon Feb 12 14:35:08 2007
@@ -1,114 +1,114 @@
-/*
- * 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.apache.commons.math.distribution;
-
-/**
- * Test cases for WeibullDistribution.
- * Extends ContinuousDistributionAbstractTest. See class javadoc for
- * ContinuousDistributionAbstractTest for details.
- *
- * @version $Revision: 1.8 $ $Date: 2004-07-24 16:41:37 -0500 (Sat, 24 Jul 2004) $
- */
-public class WeibullDistributionTest extends ContinuousDistributionAbstractTest {
-
- /**
- * Constructor for CauchyDistributionTest.
- * @param arg0
- */
- public WeibullDistributionTest(String arg0) {
- super(arg0);
- }
-
- //-------------- Implementations for abstract methods -----------------------
-
- /** Creates the default continuous distribution instance to use in tests. */
- public ContinuousDistribution makeDistribution() {
- return DistributionFactory.newInstance().createWeibullDistribution(1.2, 2.1);
- }
-
- /** Creates the default cumulative probability distribution test input values */
- public double[] makeCumulativeTestPoints() {
- // quantiles computed using Mathematica
- return new double[] {0.00664355181d, 0.04543282833d, 0.09811627374d,
- 0.1767135246d, 0.3219468654d, 4.207902826d, 5.23968437d,
- 6.232056007d, 7.497630467d, 10.51154969d};
- }
-
- /** Creates the default cumulative probability density test expected values */
- public double[] makeCumulativeTestValues() {
- return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
- 0.975d, 0.990d, 0.999d};
- }
-
- //---------------------------- Additional test cases -------------------------
-
- public void testInverseCumulativeProbabilityExtremes() throws Exception {
- setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
- setInverseCumulativeTestValues(
- new double[] {0.0, Double.POSITIVE_INFINITY});
- verifyInverseCumulativeProbabilities();
- }
-
- public void testAlpha() {
- WeibullDistribution distribution = (WeibullDistribution) getDistribution();
- double expected = Math.random();
- distribution.setShape(expected);
- assertEquals(expected, distribution.getShape(), 0.0);
- }
-
- public void testBeta() {
- WeibullDistribution distribution = (WeibullDistribution) getDistribution();
- double expected = Math.random();
- distribution.setScale(expected);
- assertEquals(expected, distribution.getScale(), 0.0);
- }
-
- public void testSetAlpha() {
- WeibullDistribution distribution = (WeibullDistribution) getDistribution();
- try {
- distribution.setShape(0.0);
- fail("Can not have 0.0 alpha.");
- } catch (IllegalArgumentException ex) {
- // success
- }
-
- try {
- distribution.setShape(-1.0);
- fail("Can not have negative alpha.");
- } catch (IllegalArgumentException ex) {
- // success
- }
- }
-
- public void testSetBeta() {
- WeibullDistribution distribution = (WeibullDistribution) getDistribution();
- try {
- distribution.setScale(0.0);
- fail("Can not have 0.0 beta.");
- } catch (IllegalArgumentException ex) {
- // success
- }
-
- try {
- distribution.setScale(-1.0);
- fail("Can not have negative beta.");
- } catch (IllegalArgumentException ex) {
- // success
- }
- }
-}
+/*
+ * 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.apache.commons.math.distribution;
+
+/**
+ * Test cases for WeibullDistribution.
+ * Extends ContinuousDistributionAbstractTest. See class javadoc for
+ * ContinuousDistributionAbstractTest for details.
+ *
+ * @version $Revision: 1.8 $ $Date: 2004-07-24 16:41:37 -0500 (Sat, 24 Jul 2004) $
+ */
+public class WeibullDistributionTest extends ContinuousDistributionAbstractTest {
+
+ /**
+ * Constructor for CauchyDistributionTest.
+ * @param arg0
+ */
+ public WeibullDistributionTest(String arg0) {
+ super(arg0);
+ }
+
+ //-------------- Implementations for abstract methods -----------------------
+
+ /** Creates the default continuous distribution instance to use in tests. */
+ public ContinuousDistribution makeDistribution() {
+ return DistributionFactory.newInstance().createWeibullDistribution(1.2, 2.1);
+ }
+
+ /** Creates the default cumulative probability distribution test input values */
+ public double[] makeCumulativeTestPoints() {
+ // quantiles computed using Mathematica
+ return new double[] {0.00664355181d, 0.04543282833d, 0.09811627374d,
+ 0.1767135246d, 0.3219468654d, 4.207902826d, 5.23968437d,
+ 6.232056007d, 7.497630467d, 10.51154969d};
+ }
+
+ /** Creates the default cumulative probability density test expected values */
+ public double[] makeCumulativeTestValues() {
+ return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
+ 0.975d, 0.990d, 0.999d};
+ }
+
+ //---------------------------- Additional test cases -------------------------
+
+ public void testInverseCumulativeProbabilityExtremes() throws Exception {
+ setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
+ setInverseCumulativeTestValues(
+ new double[] {0.0, Double.POSITIVE_INFINITY});
+ verifyInverseCumulativeProbabilities();
+ }
+
+ public void testAlpha() {
+ WeibullDistribution distribution = (WeibullDistribution) getDistribution();
+ double expected = Math.random();
+ distribution.setShape(expected);
+ assertEquals(expected, distribution.getShape(), 0.0);
+ }
+
+ public void testBeta() {
+ WeibullDistribution distribution = (WeibullDistribution) getDistribution();
+ double expected = Math.random();
+ distribution.setScale(expected);
+ assertEquals(expected, distribution.getScale(), 0.0);
+ }
+
+ public void testSetAlpha() {
+ WeibullDistribution distribution = (WeibullDistribution) getDistribution();
+ try {
+ distribution.setShape(0.0);
+ fail("Can not have 0.0 alpha.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ distribution.setShape(-1.0);
+ fail("Can not have negative alpha.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+ }
+
+ public void testSetBeta() {
+ WeibullDistribution distribution = (WeibullDistribution) getDistribution();
+ try {
+ distribution.setScale(0.0);
+ fail("Can not have 0.0 beta.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ distribution.setScale(-1.0);
+ fail("Can not have negative beta.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/WeibullDistributionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java Mon Feb 12 14:35:08 2007
@@ -1,292 +1,292 @@
-/*
- * 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.apache.commons.math.fraction;
-
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Locale;
-
-import junit.framework.TestCase;
-
-public class FractionFormatTest extends TestCase {
-
- FractionFormat properFormat = null;
- FractionFormat improperFormat = null;
-
- protected Locale getLocale() {
- return Locale.getDefault();
- }
-
- protected void setUp() throws Exception {
- properFormat = FractionFormat.getProperInstance(getLocale());
- improperFormat = FractionFormat.getImproperInstance(getLocale());
- }
-
- public void testFormat() {
- Fraction c = new Fraction(1, 2);
- String expected = "1 / 2";
-
- String actual = properFormat.format(c);
- assertEquals(expected, actual);
-
- actual = improperFormat.format(c);
- assertEquals(expected, actual);
- }
-
- public void testFormatNegative() {
- Fraction c = new Fraction(-1, 2);
- String expected = "-1 / 2";
-
- String actual = properFormat.format(c);
- assertEquals(expected, actual);
-
- actual = improperFormat.format(c);
- assertEquals(expected, actual);
- }
-
- public void testFormatZero() {
- Fraction c = new Fraction(0, 1);
- String expected = "0 / 1";
-
- String actual = properFormat.format(c);
- assertEquals(expected, actual);
-
- actual = improperFormat.format(c);
- assertEquals(expected, actual);
- }
-
- public void testFormatImproper() {
- Fraction c = new Fraction(5, 3);
-
- String actual = properFormat.format(c);
- assertEquals("1 2 / 3", actual);
-
- actual = improperFormat.format(c);
- assertEquals("5 / 3", actual);
- }
-
- public void testFormatImproperNegative() {
- Fraction c = new Fraction(-5, 3);
-
- String actual = properFormat.format(c);
- assertEquals("-1 2 / 3", actual);
-
- actual = improperFormat.format(c);
- assertEquals("-5 / 3", actual);
- }
-
- public void testParse() {
- String source = "1 / 2";
-
- try {
- Fraction c = properFormat.parse(source);
- assertNotNull(c);
- assertEquals(1, c.getNumerator());
- assertEquals(2, c.getDenominator());
-
- c = improperFormat.parse(source);
- assertNotNull(c);
- assertEquals(1, c.getNumerator());
- assertEquals(2, c.getDenominator());
- } catch (ParseException ex) {
- fail(ex.getMessage());
- }
- }
-
- public void testParseInteger() {
- String source = "10";
- try {
- Fraction c = properFormat.parse(source);
- assertNotNull(c);
- assertEquals(10, c.getNumerator());
- assertEquals(1, c.getDenominator());
- } catch (ParseException ex) {
- fail(ex.getMessage());
- }
- try {
- Fraction c = improperFormat.parse(source);
- assertNotNull(c);
- assertEquals(10, c.getNumerator());
- assertEquals(1, c.getDenominator());
- } catch (ParseException ex) {
- fail(ex.getMessage());
- }
- }
-
- public void testParseInvalid() {
- String source = "a";
- String msg = "should not be able to parse '10 / a'.";
- try {
- properFormat.parse(source);
- fail(msg);
- } catch (ParseException ex) {
- // success
- }
- try {
- improperFormat.parse(source);
- fail(msg);
- } catch (ParseException ex) {
- // success
- }
- }
-
- public void testParseInvalidDenominator() {
- String source = "10 / a";
- String msg = "should not be able to parse '10 / a'.";
- try {
- properFormat.parse(source);
- fail(msg);
- } catch (ParseException ex) {
- // success
- }
- try {
- improperFormat.parse(source);
- fail(msg);
- } catch (ParseException ex) {
- // success
- }
- }
-
- public void testParseNegative() {
-
- try {
- String source = "-1 / 2";
- Fraction c = properFormat.parse(source);
- assertNotNull(c);
- assertEquals(-1, c.getNumerator());
- assertEquals(2, c.getDenominator());
-
- c = improperFormat.parse(source);
- assertNotNull(c);
- assertEquals(-1, c.getNumerator());
- assertEquals(2, c.getDenominator());
-
- source = "1 / -2";
- c = properFormat.parse(source);
- assertNotNull(c);
- assertEquals(-1, c.getNumerator());
- assertEquals(2, c.getDenominator());
-
- c = improperFormat.parse(source);
- assertNotNull(c);
- assertEquals(-1, c.getNumerator());
- assertEquals(2, c.getDenominator());
- } catch (ParseException ex) {
- fail(ex.getMessage());
- }
- }
-
- public void testParseProper() {
- String source = "1 2 / 3";
-
- try {
- Fraction c = properFormat.parse(source);
- assertNotNull(c);
- assertEquals(5, c.getNumerator());
- assertEquals(3, c.getDenominator());
- } catch (ParseException ex) {
- fail(ex.getMessage());
- }
-
- try {
- improperFormat.parse(source);
- fail("invalid improper fraction.");
- } catch (ParseException ex) {
- // success
- }
- }
-
- public void testParseProperNegative() {
- String source = "-1 2 / 3";
- try {
- Fraction c = properFormat.parse(source);
- assertNotNull(c);
- assertEquals(-5, c.getNumerator());
- assertEquals(3, c.getDenominator());
- } catch (ParseException ex) {
- fail(ex.getMessage());
- }
-
- try {
- improperFormat.parse(source);
- fail("invalid improper fraction.");
- } catch (ParseException ex) {
- // success
- }
- }
-
- public void testParseProperInvalidMinus() {
- String source = "2 -2 / 3";
- try {
- Fraction c = properFormat.parse(source);
- fail("invalid minus in improper fraction.");
- } catch (ParseException ex) {
- // expected
- }
- source = "2 2 / -3";
- try {
- Fraction c = properFormat.parse(source);
- fail("invalid minus in improper fraction.");
- } catch (ParseException ex) {
- // expected
- }
- }
-
- public void testNumeratorFormat() {
- NumberFormat old = properFormat.getNumeratorFormat();
- NumberFormat nf = NumberFormat.getInstance();
- nf.setParseIntegerOnly(true);
- properFormat.setNumeratorFormat(nf);
- assertEquals(nf, properFormat.getNumeratorFormat());
- properFormat.setNumeratorFormat(old);
-
- old = improperFormat.getNumeratorFormat();
- nf = NumberFormat.getInstance();
- nf.setParseIntegerOnly(true);
- improperFormat.setNumeratorFormat(nf);
- assertEquals(nf, improperFormat.getNumeratorFormat());
- improperFormat.setNumeratorFormat(old);
- }
-
- public void testDenominatorFormat() {
- NumberFormat old = properFormat.getDenominatorFormat();
- NumberFormat nf = NumberFormat.getInstance();
- nf.setParseIntegerOnly(true);
- properFormat.setDenominatorFormat(nf);
- assertEquals(nf, properFormat.getDenominatorFormat());
- properFormat.setDenominatorFormat(old);
-
- old = improperFormat.getDenominatorFormat();
- nf = NumberFormat.getInstance();
- nf.setParseIntegerOnly(true);
- improperFormat.setDenominatorFormat(nf);
- assertEquals(nf, improperFormat.getDenominatorFormat());
- improperFormat.setDenominatorFormat(old);
- }
-
- public void testWholeFormat() {
- ProperFractionFormat format = (ProperFractionFormat)properFormat;
-
- NumberFormat old = format.getWholeFormat();
- NumberFormat nf = NumberFormat.getInstance();
- nf.setParseIntegerOnly(true);
- format.setWholeFormat(nf);
- assertEquals(nf, format.getWholeFormat());
- format.setWholeFormat(old);
- }
-}
+/*
+ * 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.apache.commons.math.fraction;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+public class FractionFormatTest extends TestCase {
+
+ FractionFormat properFormat = null;
+ FractionFormat improperFormat = null;
+
+ protected Locale getLocale() {
+ return Locale.getDefault();
+ }
+
+ protected void setUp() throws Exception {
+ properFormat = FractionFormat.getProperInstance(getLocale());
+ improperFormat = FractionFormat.getImproperInstance(getLocale());
+ }
+
+ public void testFormat() {
+ Fraction c = new Fraction(1, 2);
+ String expected = "1 / 2";
+
+ String actual = properFormat.format(c);
+ assertEquals(expected, actual);
+
+ actual = improperFormat.format(c);
+ assertEquals(expected, actual);
+ }
+
+ public void testFormatNegative() {
+ Fraction c = new Fraction(-1, 2);
+ String expected = "-1 / 2";
+
+ String actual = properFormat.format(c);
+ assertEquals(expected, actual);
+
+ actual = improperFormat.format(c);
+ assertEquals(expected, actual);
+ }
+
+ public void testFormatZero() {
+ Fraction c = new Fraction(0, 1);
+ String expected = "0 / 1";
+
+ String actual = properFormat.format(c);
+ assertEquals(expected, actual);
+
+ actual = improperFormat.format(c);
+ assertEquals(expected, actual);
+ }
+
+ public void testFormatImproper() {
+ Fraction c = new Fraction(5, 3);
+
+ String actual = properFormat.format(c);
+ assertEquals("1 2 / 3", actual);
+
+ actual = improperFormat.format(c);
+ assertEquals("5 / 3", actual);
+ }
+
+ public void testFormatImproperNegative() {
+ Fraction c = new Fraction(-5, 3);
+
+ String actual = properFormat.format(c);
+ assertEquals("-1 2 / 3", actual);
+
+ actual = improperFormat.format(c);
+ assertEquals("-5 / 3", actual);
+ }
+
+ public void testParse() {
+ String source = "1 / 2";
+
+ try {
+ Fraction c = properFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(1, c.getNumerator());
+ assertEquals(2, c.getDenominator());
+
+ c = improperFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(1, c.getNumerator());
+ assertEquals(2, c.getDenominator());
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+ }
+
+ public void testParseInteger() {
+ String source = "10";
+ try {
+ Fraction c = properFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(10, c.getNumerator());
+ assertEquals(1, c.getDenominator());
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+ try {
+ Fraction c = improperFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(10, c.getNumerator());
+ assertEquals(1, c.getDenominator());
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+ }
+
+ public void testParseInvalid() {
+ String source = "a";
+ String msg = "should not be able to parse '10 / a'.";
+ try {
+ properFormat.parse(source);
+ fail(msg);
+ } catch (ParseException ex) {
+ // success
+ }
+ try {
+ improperFormat.parse(source);
+ fail(msg);
+ } catch (ParseException ex) {
+ // success
+ }
+ }
+
+ public void testParseInvalidDenominator() {
+ String source = "10 / a";
+ String msg = "should not be able to parse '10 / a'.";
+ try {
+ properFormat.parse(source);
+ fail(msg);
+ } catch (ParseException ex) {
+ // success
+ }
+ try {
+ improperFormat.parse(source);
+ fail(msg);
+ } catch (ParseException ex) {
+ // success
+ }
+ }
+
+ public void testParseNegative() {
+
+ try {
+ String source = "-1 / 2";
+ Fraction c = properFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(-1, c.getNumerator());
+ assertEquals(2, c.getDenominator());
+
+ c = improperFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(-1, c.getNumerator());
+ assertEquals(2, c.getDenominator());
+
+ source = "1 / -2";
+ c = properFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(-1, c.getNumerator());
+ assertEquals(2, c.getDenominator());
+
+ c = improperFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(-1, c.getNumerator());
+ assertEquals(2, c.getDenominator());
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+ }
+
+ public void testParseProper() {
+ String source = "1 2 / 3";
+
+ try {
+ Fraction c = properFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(5, c.getNumerator());
+ assertEquals(3, c.getDenominator());
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+
+ try {
+ improperFormat.parse(source);
+ fail("invalid improper fraction.");
+ } catch (ParseException ex) {
+ // success
+ }
+ }
+
+ public void testParseProperNegative() {
+ String source = "-1 2 / 3";
+ try {
+ Fraction c = properFormat.parse(source);
+ assertNotNull(c);
+ assertEquals(-5, c.getNumerator());
+ assertEquals(3, c.getDenominator());
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+
+ try {
+ improperFormat.parse(source);
+ fail("invalid improper fraction.");
+ } catch (ParseException ex) {
+ // success
+ }
+ }
+
+ public void testParseProperInvalidMinus() {
+ String source = "2 -2 / 3";
+ try {
+ Fraction c = properFormat.parse(source);
+ fail("invalid minus in improper fraction.");
+ } catch (ParseException ex) {
+ // expected
+ }
+ source = "2 2 / -3";
+ try {
+ Fraction c = properFormat.parse(source);
+ fail("invalid minus in improper fraction.");
+ } catch (ParseException ex) {
+ // expected
+ }
+ }
+
+ public void testNumeratorFormat() {
+ NumberFormat old = properFormat.getNumeratorFormat();
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setParseIntegerOnly(true);
+ properFormat.setNumeratorFormat(nf);
+ assertEquals(nf, properFormat.getNumeratorFormat());
+ properFormat.setNumeratorFormat(old);
+
+ old = improperFormat.getNumeratorFormat();
+ nf = NumberFormat.getInstance();
+ nf.setParseIntegerOnly(true);
+ improperFormat.setNumeratorFormat(nf);
+ assertEquals(nf, improperFormat.getNumeratorFormat());
+ improperFormat.setNumeratorFormat(old);
+ }
+
+ public void testDenominatorFormat() {
+ NumberFormat old = properFormat.getDenominatorFormat();
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setParseIntegerOnly(true);
+ properFormat.setDenominatorFormat(nf);
+ assertEquals(nf, properFormat.getDenominatorFormat());
+ properFormat.setDenominatorFormat(old);
+
+ old = improperFormat.getDenominatorFormat();
+ nf = NumberFormat.getInstance();
+ nf.setParseIntegerOnly(true);
+ improperFormat.setDenominatorFormat(nf);
+ assertEquals(nf, improperFormat.getDenominatorFormat());
+ improperFormat.setDenominatorFormat(old);
+ }
+
+ public void testWholeFormat() {
+ ProperFractionFormat format = (ProperFractionFormat)properFormat;
+
+ NumberFormat old = format.getWholeFormat();
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setParseIntegerOnly(true);
+ format.setWholeFormat(nf);
+ assertEquals(nf, format.getWholeFormat());
+ format.setWholeFormat(old);
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.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