commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1083323 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/special/ test/java/org/apache/commons/math/special/
Date Sat, 19 Mar 2011 22:49:59 GMT
Author: erans
Date: Sat Mar 19 22:49:59 2011
New Revision: 1083323

URL: http://svn.apache.org/viewvc?rev=1083323&view=rev
Log:
MATH-446
Removed checked exceptions.
Some Javadoc cleanup.
Tests upgraded to Junit 4 (MATH-423).

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Erf.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/BetaTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java?rev=1083323&r1=1083322&r2=1083323&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java Sat
Mar 19 22:49:59 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.math.special;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.util.ContinuedFraction;
 import org.apache.commons.math.util.FastMath;
 
@@ -27,31 +26,28 @@ import org.apache.commons.math.util.Fast
  * @version $Revision$ $Date$
  */
 public class Beta {
-
     /** Maximum allowed numerical error. */
     private static final double DEFAULT_EPSILON = 10e-15;
 
     /**
      * Default constructor.  Prohibit instantiation.
      */
-    private Beta() {
-        super();
-    }
+    private Beta() {}
 
     /**
      * Returns the
      * <a href="http://mathworld.wolfram.com/RegularizedBetaFunction.html">
      * regularized beta function</a> I(x, a, b).
      *
-     * @param x the value.
-     * @param a the a parameter.
-     * @param b the b parameter.
-     * @return the regularized beta function I(x, a, b)
+     * @param x Value.
+     * @param a Parameter {@code a}.
+     * @param b Parameter {@code b}.
+     * @return the regularized beta function I(x, a, b).
+     * @throws org.apache.commons.math.exception.MaxCountExceededException
+     * if the algorithm fails to converge.
      * @throws MathException if the algorithm fails to converge.
      */
-    public static double regularizedBeta(double x, double a, double b)
-        throws MathException
-    {
+    public static double regularizedBeta(double x, double a, double b) {
         return regularizedBeta(x, a, b, DEFAULT_EPSILON, Integer.MAX_VALUE);
     }
 
@@ -60,18 +56,19 @@ public class Beta {
      * <a href="http://mathworld.wolfram.com/RegularizedBetaFunction.html">
      * regularized beta function</a> I(x, a, b).
      *
-     * @param x the value.
-     * @param a the a parameter.
-     * @param b the b parameter.
+     * @param x Value.
+     * @param a Parameter {@code a}.
+     * @param b Parameter {@code b}.
      * @param epsilon When the absolute value of the nth item in the
-     *                series is less than epsilon the approximation ceases
-     *                to calculate further elements in the series.
+     * series is less than epsilon the approximation ceases to calculate
+     * further elements in the series.
      * @return the regularized beta function I(x, a, b)
-     * @throws MathException if the algorithm fails to converge.
+     * @throws org.apache.commons.math.exception.MaxCountExceededException
+     * if the algorithm fails to converge.
      */
-    public static double regularizedBeta(double x, double a, double b,
-        double epsilon) throws MathException
-    {
+    public static double regularizedBeta(double x,
+                                         double a, double b,
+                                         double epsilon) {
         return regularizedBeta(x, a, b, epsilon, Integer.MAX_VALUE);
     }
 
@@ -79,15 +76,16 @@ public class Beta {
      * Returns the regularized beta function I(x, a, b).
      *
      * @param x the value.
-     * @param a the a parameter.
-     * @param b the b parameter.
+     * @param a Parameter {@code a}.
+     * @param b Parameter {@code b}.
      * @param maxIterations Maximum number of "iterations" to complete.
      * @return the regularized beta function I(x, a, b)
-     * @throws MathException if the algorithm fails to converge.
+     * @throws org.apache.commons.math.exception.MaxCountExceededException
+     * if the algorithm fails to converge.
      */
-    public static double regularizedBeta(double x, double a, double b,
-        int maxIterations) throws MathException
-    {
+    public static double regularizedBeta(double x,
+                                         double a, double b,
+                                         int maxIterations) {
         return regularizedBeta(x, a, b, DEFAULT_EPSILON, maxIterations);
     }
 
@@ -105,23 +103,28 @@ public class Beta {
      * </ul>
      *
      * @param x the value.
-     * @param a the a parameter.
-     * @param b the b parameter.
+     * @param a Parameter {@code a}.
+     * @param b Parameter {@code b}.
      * @param epsilon When the absolute value of the nth item in the
-     *                series is less than epsilon the approximation ceases
-     *                to calculate further elements in the series.
+     * series is less than epsilon the approximation ceases to calculate
+     * further elements in the series.
      * @param maxIterations Maximum number of "iterations" to complete.
      * @return the regularized beta function I(x, a, b)
-     * @throws MathException if the algorithm fails to converge.
+     * @throws org.apache.commons.math.exception.MaxCountExceededException
+     * if the algorithm fails to converge.
      */
-    public static double regularizedBeta(double x, final double a,
-        final double b, double epsilon, int maxIterations) throws MathException
-    {
+    public static double regularizedBeta(double x,
+                                         final double a, final double b,
+                                         double epsilon, int maxIterations) {
         double ret;
 
-        if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b) || (x < 0) ||
-            (x > 1) || (a <= 0.0) || (b <= 0.0))
-        {
+        if (Double.isNaN(x) ||
+            Double.isNaN(a) ||
+            Double.isNaN(b) ||
+            x < 0 ||
+            x > 1 ||
+            a <= 0.0 ||
+            b <= 0.0) {
             ret = Double.NaN;
         } else if (x > (a + 1.0) / (a + b + 2.0)) {
             ret = 1.0 - regularizedBeta(1.0 - x, b, a, epsilon, maxIterations);
@@ -160,9 +163,9 @@ public class Beta {
     /**
      * Returns the natural logarithm of the beta function B(a, b).
      *
-     * @param a the a parameter.
-     * @param b the b parameter.
-     * @return log(B(a, b))
+     * @param a Parameter {@code a}.
+     * @param b Parameter {@code b}.
+     * @return log(B(a, b)).
      */
     public static double logBeta(double a, double b) {
         return logBeta(a, b, DEFAULT_EPSILON, Integer.MAX_VALUE);
@@ -177,20 +180,23 @@ public class Beta {
      * Beta Function</a>, equation (1).</li>
      * </ul>
      *
-     * @param a the a parameter.
-     * @param b the b parameter.
+     * @param a Parameter {@code a}.
+     * @param b Parameter {@code b}.
      * @param epsilon When the absolute value of the nth item in the
-     *                series is less than epsilon the approximation ceases
-     *                to calculate further elements in the series.
+     * series is less than epsilon the approximation ceases to calculate
+     * further elements in the series.
      * @param maxIterations Maximum number of "iterations" to complete.
-     * @return log(B(a, b))
+     * @return log(B(a, b)).
      */
-    public static double logBeta(double a, double b, double epsilon,
-        int maxIterations) {
-
+    public static double logBeta(double a, double b,
+                                 double epsilon,
+                                 int maxIterations) {
         double ret;
 
-        if (Double.isNaN(a) || Double.isNaN(b) || (a <= 0.0) || (b <= 0.0)) {
+        if (Double.isNaN(a) ||
+            Double.isNaN(b) ||
+            a <= 0.0 ||
+            b <= 0.0) {
             ret = Double.NaN;
         } else {
             ret = Gamma.logGamma(a) + Gamma.logGamma(b) -

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Erf.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Erf.java?rev=1083323&r1=1083322&r2=1083323&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Erf.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Erf.java Sat Mar
19 22:49:59 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.math.special;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.util.FastMath;
 
 /**
@@ -26,32 +25,32 @@ import org.apache.commons.math.util.Fast
  * @version $Revision$ $Date$
  */
 public class Erf {
-
     /**
      * Default constructor.  Prohibit instantiation.
      */
-    private Erf() {
-        super();
-    }
+    private Erf() {}
 
     /**
-     * <p>Returns the error function</p>
+     * Returns the error function.
+     *
      * <p>erf(x) = 2/&radic;&pi; <sub>0</sub>&int;<sup>x</sup>
e<sup>-t<sup>2</sup></sup>dt </p>
      *
      * <p>This implementation computes erf(x) using the
      * {@link Gamma#regularizedGammaP(double, double, double, int) regularized gamma function},
      * following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation
(3)</p>
      *
-     * <p>The value returned is always between -1 and 1 (inclusive).  If {@code abs(x)
> 40}, then
-     * {@code erf(x)} is indistinguishable from either 1 or -1 as a double, so the appropriate
extreme
-     * value is returned.</p>
+     * <p>The value returned is always between -1 and 1 (inclusive).
+     * If {@code abs(x) > 40}, then {@code erf(x)} is indistinguishable from
+     * either 1 or -1 as a double, so the appropriate extreme value is returned.
+     * </p>
      *
      * @param x the value.
      * @return the error function erf(x)
-     * @throws MathException if the algorithm fails to converge.
+     * @throws org.apache.commons.math.exception.MaxCountExceededException
+     * if the algorithm fails to converge.
      * @see Gamma#regularizedGammaP(double, double, double, int)
      */
-    public static double erf(double x) throws MathException {
+    public static double erf(double x) {
         if (FastMath.abs(x) > 40) {
             return x > 0 ? 1 : -1;
         }
@@ -63,25 +62,29 @@ public class Erf {
     }
 
     /**
-     * <p>Returns the complementary error function</p>
-     * <p>erfc(x) = 2/&radic;&pi; <sub>x</sub>&int;<sup>&infin;</sup>
e<sup>-t<sup>2</sup></sup>dt <br/>
+     * Returns the complementary error function.
+     *
+     * <p>erfc(x) = 2/&radic;&pi; <sub>x</sub>&int;<sup>&infin;</sup>
e<sup>-t<sup>2</sup></sup>dt
+     * <br/>
      *    = 1 - {@link #erf(double) erf(x)} </p>
      *
      * <p>This implementation computes erfc(x) using the
      * {@link Gamma#regularizedGammaQ(double, double, double, int) regularized gamma function},
      * following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation
(3).</p>
      *
-     * <p>The value returned is always between 0 and 2 (inclusive).  If {@code abs(x)
> 40}, then
-     * {@code erf(x)} is indistinguishable from either 0 or 2 as a double, so the appropriate
extreme
-     * value is returned.</p>
+     * <p>The value returned is always between 0 and 2 (inclusive).
+     * If {@code abs(x) > 40}, then {@code erf(x)} is indistinguishable from
+     * either 0 or 2 as a double, so the appropriate extreme value is returned.
+     * </p>
      *
      * @param x the value
      * @return the complementary error function erfc(x)
-     * @throws MathException if the algorithm fails to converge
+     * @throws org.apache.commons.math.exception.MaxCountExceededException
+     * if the algorithm fails to converge.
      * @see Gamma#regularizedGammaQ(double, double, double, int)
      * @since 2.2
      */
-    public static double erfc(double x) throws MathException {
+    public static double erfc(double x) {
         if (FastMath.abs(x) > 40) {
             return x > 0 ? 0 : 2;
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java?rev=1083323&r1=1083322&r2=1083323&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java Sat
Mar 19 22:49:59 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.math.special;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.util.ContinuedFraction;
 import org.apache.commons.math.util.FastMath;
@@ -28,19 +27,15 @@ import org.apache.commons.math.util.Fast
  * @version $Revision$ $Date$
  */
 public class Gamma {
-
     /**
      * <a href="http://en.wikipedia.org/wiki/Euler-Mascheroni_constant">Euler-Mascheroni
constant</a>
      * @since 2.0
      */
     public static final double GAMMA = 0.577215664901532860606512090082;
-
     /** Maximum allowed numerical error. */
     private static final double DEFAULT_EPSILON = 10e-15;
-
     /** Lanczos coefficients */
-    private static final double[] LANCZOS =
-    {
+    private static final double[] LANCZOS = {
         0.99999999999999709182,
         57.156235665862923517,
         -59.597960355475491248,
@@ -57,23 +52,18 @@ public class Gamma {
         -.26190838401581408670e-4,
         .36899182659531622704e-5,
     };
-
     /** Avoid repeated computation of log of 2 PI in logGamma */
     private static final double HALF_LOG_2_PI = 0.5 * FastMath.log(2.0 * FastMath.PI);
-
     // limits for switching algorithm in digamma
     /** C limit. */
     private static final double C_LIMIT = 49;
-
     /** S limit. */
     private static final double S_LIMIT = 1e-5;
 
     /**
      * Default constructor.  Prohibit instantiation.
      */
-    private Gamma() {
-        super();
-    }
+    private Gamma() {}
 
     /**
      * Returns the natural logarithm of the gamma function &#915;(x).
@@ -89,7 +79,7 @@ public class Gamma {
      * </a></li>
      * </ul>
      *
-     * @param x the value.
+     * @param x Value.
      * @return log(&#915;(x))
      */
     public static double logGamma(double x) {
@@ -117,50 +107,47 @@ public class Gamma {
     /**
      * Returns the regularized gamma function P(a, x).
      *
-     * @param a the a parameter.
-     * @param x the value.
-     * @return the regularized gamma function P(a, x)
-     * @throws MathException if the algorithm fails to converge.
+     * @param a Parameter.
+     * @param x Value.
+     * @return the regularized gamma function P(a, x).
+     * @throws MaxCountExceededException if the algorithm fails to converge.
      */
-    public static double regularizedGammaP(double a, double x)
-        throws MathException
-    {
+    public static double regularizedGammaP(double a, double x) {
         return regularizedGammaP(a, x, DEFAULT_EPSILON, Integer.MAX_VALUE);
     }
 
-
     /**
      * Returns the regularized gamma function P(a, x).
      *
      * The implementation of this method is based on:
      * <ul>
-     * <li>
-     * <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html">
-     * Regularized Gamma Function</a>, equation (1).</li>
-     * <li>
-     * <a href="http://mathworld.wolfram.com/IncompleteGammaFunction.html">
-     * Incomplete Gamma Function</a>, equation (4).</li>
-     * <li>
-     * <a href="http://mathworld.wolfram.com/ConfluentHypergeometricFunctionoftheFirstKind.html">
-     * Confluent Hypergeometric Function of the First Kind</a>, equation (1).
-     * </li>
+     *  <li>
+     *   <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html">
+     *   Regularized Gamma Function</a>, equation (1)
+     *  </li>
+     *  <li>
+     *   <a href="http://mathworld.wolfram.com/IncompleteGammaFunction.html">
+     *   Incomplete Gamma Function</a>, equation (4).
+     *  </li>
+     *  <li>
+     *   <a href="http://mathworld.wolfram.com/ConfluentHypergeometricFunctionoftheFirstKind.html">
+     *   Confluent Hypergeometric Function of the First Kind</a>, equation (1).
+     *  </li>
      * </ul>
      *
      * @param a the a parameter.
      * @param x the value.
      * @param epsilon When the absolute value of the nth item in the
-     *                series is less than epsilon the approximation ceases
-     *                to calculate further elements in the series.
+     * series is less than epsilon the approximation ceases to calculate
+     * further elements in the series.
      * @param maxIterations Maximum number of "iterations" to complete.
      * @return the regularized gamma function P(a, x)
-     * @throws MathException if the algorithm fails to converge.
+     * @throws MaxCountExceededException if the algorithm fails to converge.
      */
     public static double regularizedGammaP(double a,
                                            double x,
                                            double epsilon,
-                                           int maxIterations)
-        throws MathException
-    {
+                                           int maxIterations) {
         double ret;
 
         if (Double.isNaN(a) || Double.isNaN(x) || (a <= 0.0) || (x < 0.0)) {
@@ -176,7 +163,9 @@ public class Gamma {
             double n = 0.0; // current element index
             double an = 1.0 / a; // n-th element in the series
             double sum = an; // partial sum
-            while (FastMath.abs(an/sum) > epsilon && n < maxIterations &&
sum < Double.POSITIVE_INFINITY) {
+            while (FastMath.abs(an/sum) > epsilon &&
+                   n < maxIterations &&
+                   sum < Double.POSITIVE_INFINITY) {
                 // compute next element in the series
                 n = n + 1.0;
                 an = an * (x / (a + n));
@@ -204,9 +193,7 @@ public class Gamma {
      * @return the regularized gamma function Q(a, x)
      * @throws MathException if the algorithm fails to converge.
      */
-    public static double regularizedGammaQ(double a, double x)
-        throws MathException
-    {
+    public static double regularizedGammaQ(double a, double x) {
         return regularizedGammaQ(a, x, DEFAULT_EPSILON, Integer.MAX_VALUE);
     }
 
@@ -215,29 +202,30 @@ public class Gamma {
      *
      * The implementation of this method is based on:
      * <ul>
-     * <li>
-     * <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html">
-     * Regularized Gamma Function</a>, equation (1).</li>
-     * <li>
-     * <a href="http://functions.wolfram.com/GammaBetaErf/GammaRegularized/10/0003/">
-     * Regularized incomplete gamma function: Continued fraction representations  (formula
06.08.10.0003)</a></li>
+     *  <li>
+     *   <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html">
+     *   Regularized Gamma Function</a>, equation (1).
+     *  </li>
+     *  <li>
+     *   <a href="http://functions.wolfram.com/GammaBetaErf/GammaRegularized/10/0003/">
+     *   Regularized incomplete gamma function: Continued fraction representations
+     *   (formula 06.08.10.0003)</a>
+     *  </li>
      * </ul>
      *
      * @param a the a parameter.
      * @param x the value.
      * @param epsilon When the absolute value of the nth item in the
-     *                series is less than epsilon the approximation ceases
-     *                to calculate further elements in the series.
+     * series is less than epsilon the approximation ceases to calculate
+     * further elements in the series.
      * @param maxIterations Maximum number of "iterations" to complete.
      * @return the regularized gamma function P(a, x)
-     * @throws MathException if the algorithm fails to converge.
+     * @throws MaxCountExceededException if the algorithm fails to converge.
      */
     public static double regularizedGammaQ(final double a,
                                            double x,
                                            double epsilon,
-                                           int maxIterations)
-        throws MathException
-    {
+                                           int maxIterations) {
         double ret;
 
         if (Double.isNaN(a) || Double.isNaN(x) || (a <= 0.0) || (x < 0.0)) {
@@ -285,10 +273,10 @@ public class Gamma {
      * |x|).  Accuracy for negative values of x should be about 10^-8 absolute for results
      * less than 10^5 and 10^-8 relative for results larger than that.</p>
      *
-     * @param x  the argument
-     * @return   digamma(x) to within 10-8 relative or absolute error whichever is smaller
-     * @see <a href="http://en.wikipedia.org/wiki/Digamma_function"> Digamma at wikipedia
</a>
-     * @see <a href="http://www.uv.es/~bernardo/1976AppStatist.pdf"> Bernardo&apos;s
original article </a>
+     * @param x Argument.
+     * @return digamma(x) to within 10-8 relative or absolute error whichever is smaller.
+     * @see <a href="http://en.wikipedia.org/wiki/Digamma_function">Digamma</a>
+     * @see <a href="http://www.uv.es/~bernardo/1976AppStatist.pdf">Bernardo&apos;s
original article </a>
      * @since 2.0
      */
     public static double digamma(double x) {
@@ -311,12 +299,13 @@ public class Gamma {
     }
 
     /**
-     * <p>Computes the trigamma function of x.  This function is derived by taking
the derivative of
-     * the implementation of digamma.</p>
-     *
-     * @param x  the argument
-     * @return   trigamma(x) to within 10-8 relative or absolute error whichever is smaller
-     * @see <a href="http://en.wikipedia.org/wiki/Trigamma_function"> Trigamma at wikipedia
</a>
+     * Computes the trigamma function of x.
+     * This function is derived by taking the derivative of the implementation
+     * of digamma.
+     *
+     * @param x Argument.
+     * @return trigamma(x) to within 10-8 relative or absolute error whichever is smaller
+     * @see <a href="http://en.wikipedia.org/wiki/Trigamma_function">Trigamma</a>
      * @see Gamma#digamma(double)
      * @since 2.0
      */

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/BetaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/BetaTest.java?rev=1083323&r1=1083322&r2=1083323&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/BetaTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/BetaTest.java
Sat Mar 19 22:49:59 2011
@@ -16,32 +16,19 @@
  */
 package org.apache.commons.math.special;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.TestUtils;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
 
 /**
  * @version $Revision$ $Date$
  */
-public class BetaTest extends TestCase {
-    /**
-     * Constructor for BetaTest.
-     * @param name
-     */
-    public BetaTest(String name) {
-        super(name);
-    }
-
-    private void testRegularizedBeta(double expected, double x, double a,
-        double b)
-    {
-        try {
-            double actual = Beta.regularizedBeta(x, a, b);
-            TestUtils.assertEquals(expected, actual, 10e-15);
-        } catch(MathException ex){
-            fail(ex.getMessage());
-        }
+public class BetaTest {
+    private void testRegularizedBeta(double expected, double x,
+                                     double a, double b) {
+        double actual = Beta.regularizedBeta(x, a, b);
+        TestUtils.assertEquals(expected, actual, 10e-15);
     }
 
     private void testLogBeta(double expected, double a, double b) {
@@ -49,70 +36,87 @@ public class BetaTest extends TestCase {
         TestUtils.assertEquals(expected, actual, 10e-15);
     }
 
+    @Test
     public void testRegularizedBetaNanPositivePositive() {
         testRegularizedBeta(Double.NaN, Double.NaN, 1.0, 1.0);
     }
 
+    @Test
     public void testRegularizedBetaPositiveNanPositive() {
         testRegularizedBeta(Double.NaN, 0.5, Double.NaN, 1.0);
     }
 
+    @Test
     public void testRegularizedBetaPositivePositiveNan() {
         testRegularizedBeta(Double.NaN, 0.5, 1.0, Double.NaN);
     }
 
+    @Test
     public void testRegularizedBetaNegativePositivePositive() {
         testRegularizedBeta(Double.NaN, -0.5, 1.0, 2.0);
     }
 
+    @Test
     public void testRegularizedBetaPositiveNegativePositive() {
         testRegularizedBeta(Double.NaN, 0.5, -1.0, 2.0);
     }
 
+    @Test
     public void testRegularizedBetaPositivePositiveNegative() {
         testRegularizedBeta(Double.NaN, 0.5, 1.0, -2.0);
     }
 
+    @Test
     public void testRegularizedBetaZeroPositivePositive() {
         testRegularizedBeta(0.0, 0.0, 1.0, 2.0);
     }
 
+    @Test
     public void testRegularizedBetaPositiveZeroPositive() {
         testRegularizedBeta(Double.NaN, 0.5, 0.0, 2.0);
     }
 
+    @Test
     public void testRegularizedBetaPositivePositiveZero() {
         testRegularizedBeta(Double.NaN, 0.5, 1.0, 0.0);
     }
 
+    @Test
     public void testRegularizedBetaPositivePositivePositive() {
         testRegularizedBeta(0.75, 0.5, 1.0, 2.0);
     }
 
+    @Test
     public void testLogBetaNanPositive() {
         testLogBeta(Double.NaN, Double.NaN, 2.0);
     }
 
+    @Test
     public void testLogBetaPositiveNan() {
         testLogBeta(Double.NaN, 1.0, Double.NaN);
     }
 
+    @Test
     public void testLogBetaNegativePositive() {
         testLogBeta(Double.NaN, -1.0, 2.0);
     }
 
+    @Test
     public void testLogBetaPositiveNegative() {
         testLogBeta(Double.NaN, 1.0, -2.0);
     }
 
+    @Test
     public void testLogBetaZeroPositive() {
         testLogBeta(Double.NaN, 0.0, 2.0);
     }
 
+    @Test
     public void testLogBetaPositiveZero() {
         testLogBeta(Double.NaN, 1.0, 0.0);
     }
 
+    @Test
     public void testLogBetaPositivePositive() {
         testLogBeta(-0.693147180559945, 1.0, 2.0);
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java?rev=1083323&r1=1083322&r2=1083323&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java Sat
Mar 19 22:49:59 2011
@@ -17,104 +17,110 @@
 
 package org.apache.commons.math.special;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.util.FastMath;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
 
 /**
  * @version $Revision$ $Date$
  */
-public class ErfTest extends TestCase {
-
-    public void testErf0() throws MathException {
+public class ErfTest {
+    @Test
+    public void testErf0() {
         double actual = Erf.erf(0.0);
         double expected = 0.0;
-        assertEquals(expected, actual, 1.0e-15);
-        assertEquals(1 - expected, Erf.erfc(0.0), 1.0e-15);
+        Assert.assertEquals(expected, actual, 1.0e-15);
+        Assert.assertEquals(1 - expected, Erf.erfc(0.0), 1.0e-15);
     }
 
-    public void testErf1960() throws MathException {
+    @Test
+    public void testErf1960() {
         double x = 1.960 / FastMath.sqrt(2.0);
         double actual = Erf.erf(x);
         double expected = 0.95;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - actual, Erf.erfc(x), 1.0e-15);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - actual, Erf.erfc(x), 1.0e-15);
 
         actual = Erf.erf(-x);
         expected = -expected;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - actual, Erf.erfc(-x), 1.0e-15);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - actual, Erf.erfc(-x), 1.0e-15);
     }
 
-    public void testErf2576() throws MathException {
+    @Test
+    public void testErf2576() {
         double x = 2.576 / FastMath.sqrt(2.0);
         double actual = Erf.erf(x);
         double expected = 0.99;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - actual, Erf.erfc(x), 1e-15);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - actual, Erf.erfc(x), 1e-15);
 
         actual = Erf.erf(-x);
         expected = -expected;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - actual, Erf.erfc(-x), 1.0e-15);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - actual, Erf.erfc(-x), 1.0e-15);
     }
 
-    public void testErf2807() throws MathException {
+    @Test
+    public void testErf2807() {
         double x = 2.807 / FastMath.sqrt(2.0);
         double actual = Erf.erf(x);
         double expected = 0.995;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - actual, Erf.erfc(x), 1.0e-15);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - actual, Erf.erfc(x), 1.0e-15);
 
         actual = Erf.erf(-x);
         expected = -expected;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - actual, Erf.erfc(-x), 1.0e-15);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - actual, Erf.erfc(-x), 1.0e-15);
     }
 
-    public void testErf3291() throws MathException {
+    @Test
+    public void testErf3291() {
         double x = 3.291 / FastMath.sqrt(2.0);
         double actual = Erf.erf(x);
         double expected = 0.999;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - expected, Erf.erfc(x), 1.0e-5);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - expected, Erf.erfc(x), 1.0e-5);
 
         actual = Erf.erf(-x);
         expected = -expected;
-        assertEquals(expected, actual, 1.0e-5);
-        assertEquals(1 - expected, Erf.erfc(-x), 1.0e-5);
+        Assert.assertEquals(expected, actual, 1.0e-5);
+        Assert.assertEquals(1 - expected, Erf.erfc(-x), 1.0e-5);
     }
     
     /**
      * MATH-301, MATH-456
      */
+    @Test
     public void testLargeValues() throws Exception {
         for (int i = 1; i < 200; i*=10) {
             double result = Erf.erf(i);
-            assertFalse(Double.isNaN(result));
-            assertTrue(result > 0 && result <= 1);
+            Assert.assertFalse(Double.isNaN(result));
+            Assert.assertTrue(result > 0 && result <= 1);
             result = Erf.erf(-i);
-            assertFalse(Double.isNaN(result));
-            assertTrue(result >= -1 && result < 0);
+            Assert.assertFalse(Double.isNaN(result));
+            Assert.assertTrue(result >= -1 && result < 0);
             result = Erf.erfc(i);
-            assertFalse(Double.isNaN(result));
-            assertTrue(result >= 0 && result < 1);
+            Assert.assertFalse(Double.isNaN(result));
+            Assert.assertTrue(result >= 0 && result < 1);
             result = Erf.erfc(-i);
-            assertFalse(Double.isNaN(result));
-            assertTrue(result >= 1 && result <= 2);    
+            Assert.assertFalse(Double.isNaN(result));
+            Assert.assertTrue(result >= 1 && result <= 2);    
         }
-        assertEquals(-1, Erf.erf(Double.NEGATIVE_INFINITY), 0);
-        assertEquals(1, Erf.erf(Double.POSITIVE_INFINITY), 0);
-        assertEquals(2, Erf.erfc(Double.NEGATIVE_INFINITY), 0);
-        assertEquals(0, Erf.erfc(Double.POSITIVE_INFINITY), 0);
+        Assert.assertEquals(-1, Erf.erf(Double.NEGATIVE_INFINITY), 0);
+        Assert.assertEquals(1, Erf.erf(Double.POSITIVE_INFINITY), 0);
+        Assert.assertEquals(2, Erf.erfc(Double.NEGATIVE_INFINITY), 0);
+        Assert.assertEquals(0, Erf.erfc(Double.POSITIVE_INFINITY), 0);
     }
     
     /**
      * Compare Erf.erf against reference values computed using GCC 4.2.1 (Apple OSX packaged
version)
      * erfl (extended precision erf).
      */
+    @Test
     public void testErfGnu() throws Exception {
         final double tol = 1E-15;
         final double[] gnuValues = new double[] {-1, -1, -1, -1, -1, 
@@ -129,7 +135,7 @@ public class ErfTest extends TestCase {
          1,  1,  1,  1};
         double x = -10d;
         for (int i = 0; i < 41; i++) {
-            assertEquals(gnuValues[i], Erf.erf(x), tol);
+            Assert.assertEquals(gnuValues[i], Erf.erf(x), tol);
             x += 0.5d;
         }
     }
@@ -138,6 +144,7 @@ public class ErfTest extends TestCase {
      * Compare Erf.erfc against reference values computed using GCC 4.2.1 (Apple OSX packaged
version)
      * erfcl (extended precision erfc).
      */
+    @Test
     public void testErfcGnu() throws Exception {
         final double tol = 1E-15;
         final double[] gnuValues = new double[] { 2,  2,  2,  2,  2, 
@@ -152,7 +159,7 @@ public class ErfTest extends TestCase {
         2.7623240713337714448E-33, 4.1370317465138102353E-37, 3.7692144856548799402E-41,
2.0884875837625447567E-45};
         double x = -10d;
         for (int i = 0; i < 41; i++) {
-            assertEquals(gnuValues[i], Erf.erfc(x), tol);
+            Assert.assertEquals(gnuValues[i], Erf.erfc(x), tol);
             x += 0.5d;
         }
     }
@@ -162,6 +169,7 @@ public class ErfTest extends TestCase {
      * "Evaluating the Normal Distribution," Journal of Statistical Software, July, 2004.
      * http//www.jstatsoft.org/v11/a05/paper
      */
+    @Test
     public void testErfcMaple() throws Exception {
         double[][] ref = new double[][]
                         {{0.1, 4.60172162722971e-01},
@@ -183,7 +191,7 @@ public class ErfTest extends TestCase {
         };
         for (int i = 0; i < 15; i++) {
             final double result = 0.5*Erf.erfc(ref[i][0]/Math.sqrt(2));
-            assertEquals(ref[i][1], result, 1E-15);
+            Assert.assertEquals(ref[i][1], result, 1E-15);
             TestUtils.assertRelativelyEquals(ref[i][1], result, 1E-13);
         }
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java?rev=1083323&r1=1083322&r2=1083323&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java
Sat Mar 19 22:49:59 2011
@@ -16,30 +16,21 @@
  */
 package org.apache.commons.math.special;
 
-import org.apache.commons.math.MathException;
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.util.FastMath;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
 
 /**
  * @version $Revision$ $Date$
  */
-public class GammaTest extends TestCase {
-
-    public GammaTest(String name) {
-        super(name);
-    }
-
+public class GammaTest {
     private void testRegularizedGamma(double expected, double a, double x) {
-        try {
-            double actualP = Gamma.regularizedGammaP(a, x);
-            double actualQ = Gamma.regularizedGammaQ(a, x);
-            TestUtils.assertEquals(expected, actualP, 10e-15);
-            TestUtils.assertEquals(actualP, 1.0 - actualQ, 10e-15);
-        } catch(MathException ex){
-            fail(ex.getMessage());
-        }
+        double actualP = Gamma.regularizedGammaP(a, x);
+        double actualQ = Gamma.regularizedGammaQ(a, x);
+        TestUtils.assertEquals(expected, actualP, 10e-15);
+        TestUtils.assertEquals(actualP, 1.0 - actualQ, 10e-15);
     }
 
     private void testLogGamma(double expected, double x) {
@@ -47,65 +38,78 @@ public class GammaTest extends TestCase 
         TestUtils.assertEquals(expected, actual, 10e-15);
     }
 
+    @Test
     public void testRegularizedGammaNanPositive() {
         testRegularizedGamma(Double.NaN, Double.NaN, 1.0);
     }
 
+    @Test
     public void testRegularizedGammaPositiveNan() {
         testRegularizedGamma(Double.NaN, 1.0, Double.NaN);
     }
 
+    @Test
     public void testRegularizedGammaNegativePositive() {
         testRegularizedGamma(Double.NaN, -1.5, 1.0);
     }
 
+    @Test
     public void testRegularizedGammaPositiveNegative() {
         testRegularizedGamma(Double.NaN, 1.0, -1.0);
     }
 
+    @Test
     public void testRegularizedGammaZeroPositive() {
         testRegularizedGamma(Double.NaN, 0.0, 1.0);
     }
 
+    @Test
     public void testRegularizedGammaPositiveZero() {
         testRegularizedGamma(0.0, 1.0, 0.0);
     }
 
+    @Test
     public void testRegularizedGammaPositivePositive() {
         testRegularizedGamma(0.632120558828558, 1.0, 1.0);
     }
 
+    @Test
     public void testLogGammaNan() {
         testLogGamma(Double.NaN, Double.NaN);
     }
 
+    @Test
     public void testLogGammaNegative() {
         testLogGamma(Double.NaN, -1.0);
     }
 
+    @Test
     public void testLogGammaZero() {
         testLogGamma(Double.NaN, 0.0);
     }
 
+    @Test
     public void testLogGammaPositive() {
         testLogGamma(0.6931471805599457, 3.0);
     }
 
+    @Test
     public void testDigammaLargeArgs() {
         double eps = 1e-8;
-        assertEquals(4.6001618527380874002, Gamma.digamma(100), eps);
-        assertEquals(3.9019896734278921970, Gamma.digamma(50), eps);
-        assertEquals(2.9705239922421490509, Gamma.digamma(20), eps);
-        assertEquals(2.9958363947076465821, Gamma.digamma(20.5), eps);
-        assertEquals(2.2622143570941481605, Gamma.digamma(10.1), eps);
-        assertEquals(2.1168588189004379233, Gamma.digamma(8.8), eps);
-        assertEquals(1.8727843350984671394, Gamma.digamma(7), eps);
-        assertEquals(0.42278433509846713939, Gamma.digamma(2), eps);
-        assertEquals(-100.56088545786867450, Gamma.digamma(0.01), eps);
-        assertEquals(-4.0390398965921882955, Gamma.digamma(-0.8), eps);
-        assertEquals(4.2003210041401844726, Gamma.digamma(-6.3), eps);
+        Assert.assertEquals(4.6001618527380874002, Gamma.digamma(100), eps);
+        Assert.assertEquals(3.9019896734278921970, Gamma.digamma(50), eps);
+        Assert.assertEquals(2.9705239922421490509, Gamma.digamma(20), eps);
+        Assert.assertEquals(2.9958363947076465821, Gamma.digamma(20.5), eps);
+        Assert.assertEquals(2.2622143570941481605, Gamma.digamma(10.1), eps);
+        Assert.assertEquals(2.1168588189004379233, Gamma.digamma(8.8), eps);
+        Assert.assertEquals(1.8727843350984671394, Gamma.digamma(7), eps);
+        Assert.assertEquals(0.42278433509846713939, Gamma.digamma(2), eps);
+        Assert.assertEquals(-100.56088545786867450, Gamma.digamma(0.01), eps);
+        Assert.assertEquals(-4.0390398965921882955, Gamma.digamma(-0.8), eps);
+        Assert.assertEquals(4.2003210041401844726, Gamma.digamma(-6.3), eps);
     }
 
+    @Test
     public void testDigammaSmallArgs() {
         // values for negative powers of 10 from 1 to 30 as computed by webMathematica with
20 digits
         // see functions.wolfram.com
@@ -120,6 +124,7 @@ public class GammaTest extends TestCase 
         }
     }
 
+    @Test
     public void testTrigamma() {
         double eps = 1e-8;
         // computed using webMathematica.  For example, to compute trigamma($i) = Polygamma(1,
$i), use
@@ -141,11 +146,11 @@ public class GammaTest extends TestCase 
                 100, 0.010050166663333571395
         };
         for (int i = data.length - 2; i >= 0; i -= 2) {
-            assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], Gamma.trigamma(data[i]),
eps);
+            Assert.assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], Gamma.trigamma(data[i]),
eps);
         }
     }
 
     private void checkRelativeError(String msg, double expected, double actual, double tolerance)
{
-        assertEquals(msg, expected, actual, FastMath.abs(tolerance * actual));
+        Assert.assertEquals(msg, expected, actual, FastMath.abs(tolerance * actual));
     }
 }



Mime
View raw message