Removed remnants of junit 3.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1209247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-12-01 21:20:47 +00:00
parent fa73f3c50f
commit b241c3962f
5 changed files with 76 additions and 81 deletions

View File

@ -23,12 +23,11 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import junit.framework.Assert;
import org.apache.commons.math.analysis.UnivariateFunction;
import org.apache.commons.math.analysis.function.Sin;
import org.apache.commons.math.exception.MathUnsupportedOperationException;
import org.apache.commons.math.linear.RealVector.Entry;
import org.junit.Assert;
import org.junit.Test;
/**

View File

@ -16,7 +16,6 @@
package org.apache.commons.math.optimization;
import java.util.Arrays;
import junit.framework.Assert;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.analysis.DifferentiableMultivariateFunction;
@ -29,6 +28,7 @@ import org.apache.commons.math.optimization.general.AbstractScalarDifferentiable
import org.apache.commons.math.optimization.general.ConjugateGradientFormula;
import org.apache.commons.math.optimization.general.NonLinearConjugateGradientOptimizer;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
/**

View File

@ -16,11 +16,11 @@
*/
package org.apache.commons.math.random;
import junit.framework.TestCase;
import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.stat.StatUtils;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import org.junit.Assert;
import org.junit.Test;
/**
* The class <code>StableRandomGeneratorTest</code> contains tests for the class
@ -28,26 +28,18 @@ import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
*
* @version $Revision$
*/
public class StableRandomGeneratorTest extends TestCase {
public class StableRandomGeneratorTest {
private RandomGenerator rg = new Well19937c(100);
private final static int sampleSize = 10000;
/**
* Construct new test instance
*
* @param name the test name
*/
public StableRandomGeneratorTest(String name) {
super(name);
}
/**
* Run the double nextDouble() method test Due to leptokurtic property the
* acceptance range is widened.
*
* TODO: verify that tolerance this wide is really OK
*/
@Test
public void testNextDouble() {
StableRandomGenerator generator = new StableRandomGenerator(rg, 1.3,
0.1);
@ -55,12 +47,13 @@ public class StableRandomGeneratorTest extends TestCase {
for (int i = 0; i < sample.length; ++i) {
sample[i] = generator.nextNormalizedDouble();
}
assertEquals(0.0, StatUtils.mean(sample), 0.3);
Assert.assertEquals(0.0, StatUtils.mean(sample), 0.3);
}
/**
* If alpha = 2, than it must be Gaussian distribution
*/
@Test
public void testGaussianCase() {
StableRandomGenerator generator = new StableRandomGenerator(rg, 2d, 0.0);
@ -68,13 +61,14 @@ public class StableRandomGeneratorTest extends TestCase {
for (int i = 0; i < sample.length; ++i) {
sample[i] = generator.nextNormalizedDouble();
}
assertEquals(0.0, StatUtils.mean(sample), 0.02);
assertEquals(1.0, StatUtils.variance(sample), 0.02);
Assert.assertEquals(0.0, StatUtils.mean(sample), 0.02);
Assert.assertEquals(1.0, StatUtils.variance(sample), 0.02);
}
/**
* If alpha = 1, than it must be Cauchy distribution
*/
@Test
public void testCauchyCase() {
StableRandomGenerator generator = new StableRandomGenerator(rg, 1d, 0.0);
DescriptiveStatistics summary = new DescriptiveStatistics();
@ -86,49 +80,53 @@ public class StableRandomGeneratorTest extends TestCase {
// Standard Cauchy distribution should have zero median and mode
double median = summary.getPercentile(50);
assertEquals(0.0, median, 0.2);
Assert.assertEquals(0.0, median, 0.2);
}
/**
* Input parameter range tests
*/
@Test
public void testAlphaRangeBelowZero() {
try {
new StableRandomGenerator(rg,
-1.0, 0.0);
fail("Expected OutOfRangeException");
Assert.fail("Expected OutOfRangeException");
} catch (OutOfRangeException e) {
assertEquals(-1.0, e.getArgument());
Assert.assertEquals(-1.0, e.getArgument());
}
}
@Test
public void testAlphaRangeAboveTwo() {
try {
new StableRandomGenerator(rg,
3.0, 0.0);
fail("Expected OutOfRangeException");
Assert.fail("Expected OutOfRangeException");
} catch (OutOfRangeException e) {
assertEquals(3.0, e.getArgument());
Assert.assertEquals(3.0, e.getArgument());
}
}
@Test
public void testBetaRangeBelowMinusOne() {
try {
new StableRandomGenerator(rg,
1.0, -2.0);
fail("Expected OutOfRangeException");
Assert.fail("Expected OutOfRangeException");
} catch (OutOfRangeException e) {
assertEquals(-2.0, e.getArgument());
Assert.assertEquals(-2.0, e.getArgument());
}
}
@Test
public void testBetaRangeAboveOne() {
try {
new StableRandomGenerator(rg,
1.0, 2.0);
fail("Expected OutOfRangeException");
Assert.fail("Expected OutOfRangeException");
} catch (OutOfRangeException e) {
assertEquals(2.0, e.getArgument());
Assert.assertEquals(2.0, e.getArgument());
}
}
}

View File

@ -16,14 +16,12 @@
*/
package org.apache.commons.math.stat.regression;
import junit.framework.Assert;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.stat.correlation.PearsonsCorrelation;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* MillerUpdatingRegression tests.
@ -51,11 +49,11 @@ public class MillerUpdatingRegressionTest {
public void testHasIntercept() {
MillerUpdatingRegression instance = new MillerUpdatingRegression(10, false);
if (instance.hasIntercept()) {
fail("Should not have intercept");
Assert.fail("Should not have intercept");
}
instance = new MillerUpdatingRegression(10, true);
if (!instance.hasIntercept()) {
fail("Should have intercept");
Assert.fail("Should have intercept");
}
}
@ -76,14 +74,14 @@ public class MillerUpdatingRegressionTest {
}
instance.addObservations(xAll, y);
if (instance.getN() != xAll.length) {
fail("Number of observations not correct in bulk addition");
Assert.fail("Number of observations not correct in bulk addition");
}
instance.clear();
for (int i = 0; i < xAll.length; i++) {
instance.addObservation(xAll[i], y[i]);
}
if (instance.getN() != xAll.length) {
fail("Number of observations not correct in drip addition");
Assert.fail("Number of observations not correct in drip addition");
}
return;
}
@ -93,44 +91,44 @@ public class MillerUpdatingRegressionTest {
MillerUpdatingRegression instance = new MillerUpdatingRegression(3, true);
try {
instance.addObservation(new double[]{1.0}, 0.0);
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
}
try {
instance.addObservation(new double[]{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, 0.0);
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
}
try {
instance.addObservation(new double[]{1.0, 1.0, 1.0}, 0.0);
} catch (Exception e) {
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
}
//now we try it without an intercept
instance = new MillerUpdatingRegression(3, false);
try {
instance.addObservation(new double[]{1.0}, 0.0);
fail("Should throw IllegalArgumentException [NOINTERCEPT]");
Assert.fail("Should throw IllegalArgumentException [NOINTERCEPT]");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException [NOINTERCEPT]");
Assert.fail("Should throw IllegalArgumentException [NOINTERCEPT]");
}
try {
instance.addObservation(new double[]{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, 0.0);
fail("Should throw IllegalArgumentException [NOINTERCEPT]");
Assert.fail("Should throw IllegalArgumentException [NOINTERCEPT]");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException [NOINTERCEPT]");
Assert.fail("Should throw IllegalArgumentException [NOINTERCEPT]");
}
try {
instance.addObservation(new double[]{1.0, 1.0, 1.0}, 0.0);
} catch (Exception e) {
fail("Should throw IllegalArgumentException [NOINTERCEPT]");
Assert.fail("Should throw IllegalArgumentException [NOINTERCEPT]");
}
}
@ -142,10 +140,10 @@ public class MillerUpdatingRegressionTest {
double[] y = {1.0};
instance.addObservations(tst, y);
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
}
try {
@ -153,10 +151,10 @@ public class MillerUpdatingRegressionTest {
double[] y = {1.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
instance.addObservations(tst, y);
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {
fail("Should throw IllegalArgumentException");
Assert.fail("Should throw IllegalArgumentException");
}
}
@ -192,7 +190,7 @@ public class MillerUpdatingRegressionTest {
TestUtils.assertEquals(0.01552839, result.getMeanSquareError(), 1.0e-8);
} catch (Exception e) {
fail("Should not throw exception but does");
Assert.fail("Should not throw exception but does");
}
}
@ -225,7 +223,7 @@ public class MillerUpdatingRegressionTest {
TestUtils.assertEquals(0.9883, result.getRSquared(), 1.0e-4);
TestUtils.assertEquals(0.01552839, result.getMeanSquareError(), 1.0e-8);
} catch (Exception e) {
fail("Should not throw exception but does");
Assert.fail("Should not throw exception but does");
}
}
@ -733,7 +731,7 @@ public class MillerUpdatingRegressionTest {
// instance.addObservations(x, y);
// RegressionResults result = instance.regress();
// if (result == null) {
// fail("Null result....");
// Assert.fail("Null result....");
// }
//
// instance.reorderRegressors(new int[]{3, 2}, 0);
@ -742,16 +740,16 @@ public class MillerUpdatingRegressionTest {
// double[] beta = result.getParameterEstimates();
// double[] betar = resultInverse.getParameterEstimates();
// if (Math.abs(beta[0] - betar[0]) > 1.0e-14) {
// fail("Parameters not correct after reorder (0,3)");
// Assert.fail("Parameters not correct after reorder (0,3)");
// }
// if (Math.abs(beta[1] - betar[1]) > 1.0e-14) {
// fail("Parameters not correct after reorder (1,2)");
// Assert.fail("Parameters not correct after reorder (1,2)");
// }
// if (Math.abs(beta[2] - betar[2]) > 1.0e-14) {
// fail("Parameters not correct after reorder (2,1)");
// Assert.fail("Parameters not correct after reorder (2,1)");
// }
// if (Math.abs(beta[3] - betar[3]) > 1.0e-14) {
// fail("Parameters not correct after reorder (3,0)");
// Assert.fail("Parameters not correct after reorder (3,0)");
// }
// }
@ -793,15 +791,15 @@ public class MillerUpdatingRegressionTest {
for (int i = 0; i < beta.length; i++) {
if (Math.abs(beta[i] - betar[i]) > 1.0e-8) {
fail("Parameters not correctly estimated");
Assert.fail("Parameters not correctly estimated");
}
if (Math.abs(se[i] - ser[i]) > 1.0e-8) {
fail("Standard errors not correctly estimated");
Assert.fail("Standard errors not correctly estimated");
}
for (int j = 0; j < i; j++) {
if (Math.abs(result.getCovarianceOfParameters(i, j)
- resultRedundant.getCovarianceOfParameters(i, j)) > 1.0e-8) {
fail("Variance Covariance not correct");
Assert.fail("Variance Covariance not correct");
}
}
}
@ -854,72 +852,72 @@ public class MillerUpdatingRegressionTest {
double[] ser = resultRedundant.getStdErrorOfEstimates();
if (Math.abs(beta[0] - betar[0]) > 1.0e-8) {
fail("Parameters not correct after reorder (0,3)");
Assert.fail("Parameters not correct after reorder (0,3)");
}
if (Math.abs(beta[1] - betar[2]) > 1.0e-8) {
fail("Parameters not correct after reorder (1,2)");
Assert.fail("Parameters not correct after reorder (1,2)");
}
if (Math.abs(beta[2] - betar[3]) > 1.0e-8) {
fail("Parameters not correct after reorder (2,1)");
Assert.fail("Parameters not correct after reorder (2,1)");
}
if (Math.abs(beta[3] - betar[5]) > 1.0e-8) {
fail("Parameters not correct after reorder (3,0)");
Assert.fail("Parameters not correct after reorder (3,0)");
}
if (Math.abs(se[0] - ser[0]) > 1.0e-8) {
fail("Se not correct after reorder (0,3)");
Assert.fail("Se not correct after reorder (0,3)");
}
if (Math.abs(se[1] - ser[2]) > 1.0e-8) {
fail("Se not correct after reorder (1,2)");
Assert.fail("Se not correct after reorder (1,2)");
}
if (Math.abs(se[2] - ser[3]) > 1.0e-8) {
fail("Se not correct after reorder (2,1)");
Assert.fail("Se not correct after reorder (2,1)");
}
if (Math.abs(se[3] - ser[5]) > 1.0e-8) {
fail("Se not correct after reorder (3,0)");
Assert.fail("Se not correct after reorder (3,0)");
}
if (Math.abs(result.getCovarianceOfParameters(0, 0)
- resultRedundant.getCovarianceOfParameters(0, 0)) > 1.0e-8) {
fail("VCV not correct after reorder (0,0)");
Assert.fail("VCV not correct after reorder (0,0)");
}
if (Math.abs(result.getCovarianceOfParameters(0, 1)
- resultRedundant.getCovarianceOfParameters(0, 2)) > 1.0e-8) {
fail("VCV not correct after reorder (0,1)<->(0,2)");
Assert.fail("VCV not correct after reorder (0,1)<->(0,2)");
}
if (Math.abs(result.getCovarianceOfParameters(0, 2)
- resultRedundant.getCovarianceOfParameters(0, 3)) > 1.0e-8) {
fail("VCV not correct after reorder (0,2)<->(0,1)");
Assert.fail("VCV not correct after reorder (0,2)<->(0,1)");
}
if (Math.abs(result.getCovarianceOfParameters(0, 3)
- resultRedundant.getCovarianceOfParameters(0, 5)) > 1.0e-8) {
fail("VCV not correct after reorder (0,3)<->(0,3)");
Assert.fail("VCV not correct after reorder (0,3)<->(0,3)");
}
if (Math.abs(result.getCovarianceOfParameters(1, 0)
- resultRedundant.getCovarianceOfParameters(2, 0)) > 1.0e-8) {
fail("VCV not correct after reorder (1,0)<->(2,0)");
Assert.fail("VCV not correct after reorder (1,0)<->(2,0)");
}
if (Math.abs(result.getCovarianceOfParameters(1, 1)
- resultRedundant.getCovarianceOfParameters(2, 2)) > 1.0e-8) {
fail("VCV not correct (1,1)<->(2,1)");
Assert.fail("VCV not correct (1,1)<->(2,1)");
}
if (Math.abs(result.getCovarianceOfParameters(1, 2)
- resultRedundant.getCovarianceOfParameters(2, 3)) > 1.0e-8) {
fail("VCV not correct (1,2)<->(2,2)");
Assert.fail("VCV not correct (1,2)<->(2,2)");
}
if (Math.abs(result.getCovarianceOfParameters(2, 0)
- resultRedundant.getCovarianceOfParameters(3, 0)) > 1.0e-8) {
fail("VCV not correct (2,0)<->(1,0)");
Assert.fail("VCV not correct (2,0)<->(1,0)");
}
if (Math.abs(result.getCovarianceOfParameters(2, 1)
- resultRedundant.getCovarianceOfParameters(3, 2)) > 1.0e-8) {
fail("VCV not correct (2,1)<->(1,2)");
Assert.fail("VCV not correct (2,1)<->(1,2)");
}
if (Math.abs(result.getCovarianceOfParameters(3, 3)
- resultRedundant.getCovarianceOfParameters(5, 5)) > 1.0e-8) {
fail("VCV not correct (3,3)<->(3,2)");
Assert.fail("VCV not correct (3,3)<->(3,2)");
}
TestUtils.assertEquals(result.getAdjustedRSquared(), resultRedundant.getAdjustedRSquared(), 1.0e-8);
@ -971,14 +969,14 @@ public class MillerUpdatingRegressionTest {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < i; j++) {
if (Math.abs(pc[idx] - cp[off] / (diag[i] * diag[j])) > 1.0e-8) {
fail("Failed cross products... i = " + i + " j = " + j);
Assert.fail("Failed cross products... i = " + i + " j = " + j);
}
++idx;
++off;
}
++off;
if (Math.abs(pc[i+off2] - yxcorr[ i] / (FastMath.sqrt(sumysq) * diag[i])) > 1.0e-8) {
fail("failed cross product i = " + i + " y");
Assert.fail("Assert.failed cross product i = " + i + " y");
}
}
double[] pc2 = instance.getPartialCorrelations(1);
@ -988,14 +986,14 @@ public class MillerUpdatingRegressionTest {
for (int i = 1; i < 4; i++) {
for (int j = 1; j < i; j++) {
if (Math.abs(pc2[idx] - corr.getEntry(j, i)) > 1.0e-8) {
fail("Failed cross products... i = " + i + " j = " + j);
Assert.fail("Failed cross products... i = " + i + " j = " + j);
}
++idx;
}
}
double[] pc3 = instance.getPartialCorrelations(2);
if (pc3 == null) {
fail("Should not be null");
Assert.fail("Should not be null");
}
return;
}

View File

@ -64,7 +64,7 @@
</equals>
</condition>
<!--Test if JUNIT is present in ANT classpath-->
<available property="Junit.present" classname="junit.framework.Test">
<available property="Junit.present" classname="org.junit.Test">
</available>
</target>
<target name="test" description="o Run the test cases" if="test.failure" depends="internal-test">