Remove unnecessary casts, unnecessary throws and unnecessary semi-colons

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@762118 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2009-04-05 16:55:59 +00:00
parent a2b1aa1695
commit e1abece416
20 changed files with 106 additions and 109 deletions

View File

@ -196,14 +196,14 @@ public abstract class IntegerDistributionAbstractTest extends TestCase {
*/
public void testFloatingPointArguments() throws Exception {
for (int i = 0; i < cumulativeTestPoints.length; i++) {
double arg = (double) cumulativeTestPoints[i];
double arg = cumulativeTestPoints[i];
assertEquals(
"Incorrect cumulative probability value returned for " +
cumulativeTestPoints[i],
cumulativeTestValues[i],
distribution.cumulativeProbability(arg), tolerance);
if (i < cumulativeTestPoints.length - 1) {
double arg2 = (double) cumulativeTestPoints[i + 1];
double arg2 = cumulativeTestPoints[i + 1];
assertEquals("Inconsistent probability for discrete range " +
"[ " + arg + "," + arg2 + " ]",
distribution.cumulativeProbability(
@ -223,9 +223,9 @@ public abstract class IntegerDistributionAbstractTest extends TestCase {
int one = 1;
int ten = 10;
int two = 2;
double oned = (double) one;
double twod = (double) two;
double tend = (double) ten;
double oned = one;
double twod = two;
double tend = ten;
assertEquals(distribution.cumulativeProbability(one, two),
distribution.cumulativeProbability(oned, twod), tolerance);
assertEquals(distribution.cumulativeProbability(one, two),

View File

@ -149,8 +149,8 @@ public class NormalDistributionTest extends ContinuousDistributionAbstractTest
distribution.setMean(0);
distribution.setStandardDeviation(1);
for (int i = 0; i < 100; i+=5) { // make sure no convergence exception
double lowerTail = distribution.cumulativeProbability((double)-i);
double upperTail = distribution.cumulativeProbability((double) i);
double lowerTail = distribution.cumulativeProbability(-i);
double upperTail = distribution.cumulativeProbability(i);
if (i < 10) { // make sure not top-coded
assertTrue(lowerTail > 0.0d);
assertTrue(upperTail < 1.0d);

View File

@ -237,7 +237,7 @@ public class GaussNewtonEstimatorTest
}
public void testNonInversible() throws EstimationException {
public void testNonInversible() {
EstimatedParameter[] p = {
new EstimatedParameter("p0", 0),
@ -322,7 +322,7 @@ public class GaussNewtonEstimatorTest
}
public void testMoreEstimatedParametersSimple() throws EstimationException {
public void testMoreEstimatedParametersSimple() {
EstimatedParameter[] p = {
new EstimatedParameter("p0", 7),
@ -354,7 +354,7 @@ public class GaussNewtonEstimatorTest
}
public void testMoreEstimatedParametersUnsorted() throws EstimationException {
public void testMoreEstimatedParametersUnsorted() {
EstimatedParameter[] p = {
new EstimatedParameter("p0", 2),
new EstimatedParameter("p1", 2),
@ -516,7 +516,7 @@ public class GaussNewtonEstimatorTest
assertEquals(48.13516790438953, circle.getY(), 1.0e-10);
}
public void testCircleFittingBadInit() throws EstimationException {
public void testCircleFittingBadInit() {
Circle circle = new Circle(-12, -12);
double[][] points = new double[][] {
{-0.312967, 0.072366}, {-0.339248, 0.132965}, {-0.379780, 0.202724},
@ -637,7 +637,7 @@ public class GaussNewtonEstimatorTest
}
public WeightedMeasurement[] getMeasurements() {
return (WeightedMeasurement[]) points.toArray(new PointModel[points.size()]);
return points.toArray(new PointModel[points.size()]);
}
public EstimatedParameter[] getAllParameters() {

View File

@ -457,7 +457,7 @@ public class LevenbergMarquardtEstimatorTest
}
public void testControlParameters() throws EstimationException {
public void testControlParameters() {
Circle circle = new Circle(98.680, 47.345);
circle.addPoint( 30.0, 68.0);
circle.addPoint( 50.0, -6.0);
@ -620,7 +620,7 @@ public class LevenbergMarquardtEstimatorTest
set.add(parameters[j]);
}
}
return (EstimatedParameter[]) set.toArray(new EstimatedParameter[set.size()]);
return set.toArray(new EstimatedParameter[set.size()]);
}
private LinearMeasurement[] measurements;
@ -682,7 +682,7 @@ public class LevenbergMarquardtEstimatorTest
}
public WeightedMeasurement[] getMeasurements() {
return (WeightedMeasurement[]) points.toArray(new PointModel[points.size()]);
return points.toArray(new PointModel[points.size()]);
}
public EstimatedParameter[] getAllParameters() {

View File

@ -236,7 +236,7 @@ public final class BigMatrixImplTest extends TestCase {
m.add(m2);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -258,7 +258,7 @@ public final class BigMatrixImplTest extends TestCase {
m.subtract(new BigMatrixImpl(testData2));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -282,7 +282,7 @@ public final class BigMatrixImplTest extends TestCase {
m.multiply(new BigMatrixImpl(bigSingular));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -350,32 +350,32 @@ public final class BigMatrixImplTest extends TestCase {
asDouble(m.solve(asBigDecimal(testVector2)));
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
BigMatrix bs = new BigMatrixImpl(bigSingular);
try {
bs.solve(bs);
fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) {
;
// ignored
}
try {
m.solve(bs);
fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
new BigMatrixImpl(testData2).solve(bs);
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
(new BigMatrixImpl(testData2)).luDecompose();
fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) {
;
// ignored
}
}
@ -396,7 +396,7 @@ public final class BigMatrixImplTest extends TestCase {
new BigMatrixImpl(testData2).getDeterminant().doubleValue();
fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) {
;
// ignored
}
}
@ -409,7 +409,7 @@ public final class BigMatrixImplTest extends TestCase {
m.getTrace().doubleValue();
fail("Expecting NonSquareMatrixException");
} catch (NonSquareMatrixException ex) {
;
// ignored
}
}
@ -430,7 +430,7 @@ public final class BigMatrixImplTest extends TestCase {
asDouble(m.operate(asBigDecimal(testVector)));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -467,7 +467,7 @@ public final class BigMatrixImplTest extends TestCase {
m.preMultiply(asBigDecimal(testVector));
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -493,7 +493,7 @@ public final class BigMatrixImplTest extends TestCase {
m.preMultiply(new BigMatrixImpl(bigSingular));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -505,24 +505,24 @@ public final class BigMatrixImplTest extends TestCase {
m.getRowAsDoubleArray(10);
fail("expecting MatrixIndexException");
} catch (MatrixIndexException ex) {
;
// ignored
}
try {
m.getColumnAsDoubleArray(-1);
fail("expecting MatrixIndexException");
} catch (MatrixIndexException ex) {
;
// ignored
}
}
public void testLUDecomposition() throws Exception {
BigMatrixImpl m = new BigMatrixImpl(testData);
BigMatrix lu = m.getLUMatrix();
assertClose("LU decomposition", lu, (BigMatrix) new BigMatrixImpl(testDataLU), normTolerance);
assertClose("LU decomposition", lu, new BigMatrixImpl(testDataLU), normTolerance);
verifyDecomposition(m, lu);
m = new BigMatrixImpl(luData);
lu = m.getLUMatrix();
assertClose("LU decomposition", lu, (BigMatrix) new BigMatrixImpl(luDataLUDecomposition), normTolerance);
assertClose("LU decomposition", lu, new BigMatrixImpl(luDataLUDecomposition), normTolerance);
verifyDecomposition(m, lu);
m = new BigMatrixImpl(testDataMinus);
lu = m.getLUMatrix();

View File

@ -132,11 +132,11 @@ public final class MatrixUtilsTest extends TestCase {
}
public void testCreateRowBigMatrix() {
assertEquals((BigMatrixImpl) MatrixUtils.createRowBigMatrix(row),
assertEquals(MatrixUtils.createRowBigMatrix(row),
new BigMatrixImpl(rowMatrix));
assertEquals((BigMatrixImpl) MatrixUtils.createRowBigMatrix(bigRow),
assertEquals(MatrixUtils.createRowBigMatrix(bigRow),
new BigMatrixImpl(bigRowMatrix));
assertEquals((BigMatrixImpl) MatrixUtils.createRowBigMatrix(stringRow),
assertEquals(MatrixUtils.createRowBigMatrix(stringRow),
new BigMatrixImpl(stringRowMatrix));
try {
MatrixUtils.createRowBigMatrix(new double[] {}); // empty
@ -170,11 +170,11 @@ public final class MatrixUtilsTest extends TestCase {
}
public void testCreateColumnBigMatrix() {
assertEquals((BigMatrixImpl) MatrixUtils.createColumnBigMatrix(col),
assertEquals(MatrixUtils.createColumnBigMatrix(col),
new BigMatrixImpl(colMatrix));
assertEquals((BigMatrixImpl) MatrixUtils.createColumnBigMatrix(bigCol),
assertEquals(MatrixUtils.createColumnBigMatrix(bigCol),
new BigMatrixImpl(bigColMatrix));
assertEquals((BigMatrixImpl) MatrixUtils.createColumnBigMatrix(stringCol),
assertEquals(MatrixUtils.createColumnBigMatrix(stringCol),
new BigMatrixImpl(stringColMatrix));
try {

View File

@ -63,7 +63,7 @@ public class EulerStepInterpolatorTest
double t0 = 0;
double[] y0 = {0.0, 1.0, -2.0};
double[] y = (double[]) y0.clone();
double[] y = y0.clone();
double[][] yDot = { new double[y0.length] };
EulerStepInterpolator interpolator = new EulerStepInterpolator();
interpolator.reinitialize(new DummyEquations(), y, yDot, true);

View File

@ -59,7 +59,7 @@ public class TestProblem1
*/
public TestProblem1(TestProblem1 problem) {
super(problem);
y = (double[]) problem.y.clone();
y = problem.y.clone();
}
/**

View File

@ -60,7 +60,7 @@ public class TestProblem2
*/
public TestProblem2(TestProblem2 problem) {
super(problem);
y = (double[]) problem.y.clone();
y = problem.y.clone();
}
/**

View File

@ -75,7 +75,7 @@ public class TestProblem3
public TestProblem3(TestProblem3 problem) {
super(problem);
e = problem.e;
y = (double[]) problem.y.clone();
y = problem.y.clone();
}
/**

View File

@ -65,7 +65,7 @@ public class TestProblem4
public TestProblem4(TestProblem4 problem) {
super(problem);
a = problem.a;
y = (double[]) problem.y.clone();
y = problem.y.clone();
}
/**

View File

@ -71,12 +71,12 @@ public abstract class TestProblemAbstract
if (problem.y0 == null) {
y0 = null;
} else {
y0 = (double[]) problem.y0.clone();
y0 = problem.y0.clone();
}
if (problem.errorScale == null) {
errorScale = null;
} else {
errorScale = (double[]) problem.errorScale.clone();
errorScale = problem.errorScale.clone();
}
t1 = problem.t1;
}
@ -97,7 +97,7 @@ public abstract class TestProblemAbstract
calls = 0;
n = y0.length;
this.t0 = t0;
this.y0 = (double[]) y0.clone();
this.y0 = y0.clone();
}
/**
@ -113,7 +113,7 @@ public abstract class TestProblemAbstract
* @param errorScale error scale
*/
protected void setErrorScale(double[] errorScale) {
this.errorScale = (double[]) errorScale.clone();
this.errorScale = errorScale.clone();
}
public int getDimension() {

View File

@ -18,8 +18,6 @@ package org.apache.commons.math.random;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.security.NoSuchProviderException;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import org.apache.commons.math.RetryTestCase;
@ -72,7 +70,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextInt(4,3);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
Frequency freq = new Frequency();
int value = 0;
@ -99,7 +97,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextLong(4,3);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
Frequency freq = new Frequency();
long value = 0;
@ -126,7 +124,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextSecureLong(4,3);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
Frequency freq = new Frequency();
long value = 0;
@ -153,7 +151,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextSecureInt(4,3);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
Frequency freq = new Frequency();
int value = 0;
@ -185,7 +183,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextPoisson(0);
fail("zero mean -- expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
Frequency f = new Frequency();
for (int i = 0; i<largeSampleSize; i++) {
@ -205,13 +203,13 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextPoisson(-1);
fail("negative mean supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
randomData.nextPoisson(0);
fail("0 mean supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -222,13 +220,13 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextHexString(-1);
fail("negative length supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
randomData.nextHexString(0);
fail("zero length supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
String hexString = randomData.nextHexString(3);
if (hexString.length() != 3) {
@ -242,7 +240,7 @@ public class RandomDataTest extends RetryTestCase {
hexString = randomData.nextHexString(0);
fail("zero length requested -- expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
if (hexString.length() != 1) {
fail("incorrect length for generated string");
@ -260,7 +258,7 @@ public class RandomDataTest extends RetryTestCase {
double[] expected = new double[16];
long[] observed = new long[16];
for (int i = 0; i < 16; i++) {
expected[i] = (double)smallSampleSize*100/(double)16;
expected[i] = (double)smallSampleSize*100/16;
observed[i] = f.getCount(hex[i]);
}
/* Use ChiSquare dist with df = 16-1 = 15, alpha = .001
@ -276,13 +274,13 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextSecureHexString(-1);
fail("negative length -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
randomData.nextSecureHexString(0);
fail("zero length -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
String hexString = randomData.nextSecureHexString(3);
if (hexString.length() != 3) {
@ -296,7 +294,7 @@ public class RandomDataTest extends RetryTestCase {
hexString = randomData.nextSecureHexString(0);
fail("zero length requested -- expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
if (hexString.length() != 1) {
fail("incorrect length for generated string");
@ -314,7 +312,7 @@ public class RandomDataTest extends RetryTestCase {
double[] expected = new double[16];
long[] observed = new long[16];
for (int i = 0; i < 16; i++) {
expected[i] = (double)smallSampleSize*100/(double)16;
expected[i] = (double)smallSampleSize*100/16;
observed[i] = f.getCount(hex[i]);
}
/* Use ChiSquare dist with df = 16-1 = 15, alpha = .001
@ -330,13 +328,13 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextUniform(4,3);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
randomData.nextUniform(3,3);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
double[] expected = {500,500};
long[] observed = {0,0};
@ -376,7 +374,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextGaussian(0,0);
fail("zero sigma -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) {
;
// ignored
}
SummaryStatistics u = new SummaryStatistics();
for (int i = 0; i<largeSampleSize; i++) {
@ -384,7 +382,7 @@ public class RandomDataTest extends RetryTestCase {
}
double xbar = u.getMean();
double s = u.getStandardDeviation();
double n = (double) u.getN();
double n = u.getN();
/* t-test at .001-level TODO: replace with externalized t-test, with
* test statistic defined in TestStatistic
*/
@ -397,7 +395,7 @@ public class RandomDataTest extends RetryTestCase {
randomData.nextExponential(-1);
fail("negative mean -- expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
assertEquals("0 mean", 0,randomData.nextExponential(0),10E-8);
long cumFreq = 0;
@ -416,8 +414,7 @@ public class RandomDataTest extends RetryTestCase {
}
/** test reseeding, algorithm/provider games */
public void testConfig() throws NoSuchProviderException,
NoSuchAlgorithmException {
public void testConfig() {
randomData.reSeed(1000);
double v = randomData.nextUniform(0,1);
randomData.reSeed();
@ -521,7 +518,7 @@ public class RandomDataTest extends RetryTestCase {
one = randomData.nextSample(hs,2);
fail("sample size > set size, expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
// Make sure we fail for empty collection
@ -530,7 +527,7 @@ public class RandomDataTest extends RetryTestCase {
one = randomData.nextSample(hs,0);
fail("n = k = 0, expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}
@ -577,7 +574,7 @@ public class RandomDataTest extends RetryTestCase {
perm = randomData.nextPermutation(2,3);
fail("permutation k > n, expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
// Make sure we fail for n = 0
@ -585,7 +582,7 @@ public class RandomDataTest extends RetryTestCase {
perm = randomData.nextPermutation(0,0);
fail("permutation k = n = 0, expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
// Make sure we fail for k < n < 0
@ -593,7 +590,7 @@ public class RandomDataTest extends RetryTestCase {
perm = randomData.nextPermutation(-1,-3);
fail("permutation k < n < 0, expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
}

View File

@ -112,7 +112,7 @@ public abstract class CertifiedDataAbstractTest extends TestCase {
public void testCertifiedValues() {
for (String name : certifiedValues.keySet()) {
Double expectedValue = (Double)certifiedValues.get(name);
Double expectedValue = certifiedValues.get(name);
Double summariesValue = getProperty(summaries, name);
if (summariesValue != null) {

View File

@ -183,11 +183,11 @@ public abstract class StorelessUnivariateStatisticAbstractTest
StorelessUnivariateStatistic replica = null;
// Randomly select a portion of testArray to load first
long index = Math.round((Math.random()) * (double) testArray.length);
long index = Math.round((Math.random()) * testArray.length);
// Put first half in master and copy master to replica
master.incrementAll(testArray, 0, (int) index);
replica = (StorelessUnivariateStatistic) master.copy();
replica = master.copy();
// Check same
assertTrue(replica.equals(master));

View File

@ -101,7 +101,7 @@ public class StandardDeviationTest extends StorelessUnivariateStatisticAbstractT
for (int i = 0; i < v.length; i++) {
sum += (v[i] - mean) * (v[i] - mean);
}
return Math.sqrt(sum / (double) v.length);
return Math.sqrt(sum / v.length);
}
}

View File

@ -100,7 +100,7 @@ public class VarianceTest extends StorelessUnivariateStatisticAbstractTest{
for (int i = 0; i < v.length; i++) {
sum += (v[i] - mean) * (v[i] - mean);
}
return sum / (double) v.length;
return sum / v.length;
}
}

View File

@ -34,7 +34,7 @@ public final class FastFourierTransformerTest extends TestCase {
/**
* Test of transformer for the ad hoc data taken from Mathematica.
*/
public void testAdHocData() throws MathException {
public void testAdHocData() {
FastFourierTransformer transformer = new FastFourierTransformer();
Complex result[]; double tolerance = 1E-12;
@ -78,7 +78,7 @@ public final class FastFourierTransformerTest extends TestCase {
}
}
public void test2DData() throws MathException {
public void test2DData() {
FastFourierTransformer transformer = new FastFourierTransformer();
double tolerance = 1E-12;
Complex[][] input = new Complex[][] {new Complex[] {new Complex(1, 0),

View File

@ -77,7 +77,7 @@ public final class FastHadamardTransformerTest extends TestCase {
// check double transform
double[] dX = new double[x.length];
for (int i = 0; i < dX.length; ++i) {
dX[i] = (double) x[i];
dX[i] = x[i];
}
double dResult[] = transformer.transform(dX);
for (int i = 0; i < dResult.length; i++) {
@ -106,7 +106,7 @@ public final class FastHadamardTransformerTest extends TestCase {
// check double transform
double[] dY = new double[y.length];
for (int i = 0; i < dY.length; ++i) {
dY[i] = (double) y[i];
dY[i] = y[i];
}
double dResult[] = transformer.inversetransform(dY);
for (int i = 0; i < dResult.length; i++) {

View File

@ -170,8 +170,8 @@ public final class MathUtilsTest extends TestCase {
for (int n = 1; n < 10; n++) {
for (int k = 0; k <= n; k++) {
assertEquals(n + " choose " + k, binomialCoefficient(n, k), MathUtils.binomialCoefficient(n, k));
assertEquals(n + " choose " + k, (double)binomialCoefficient(n, k), MathUtils.binomialCoefficientDouble(n, k), Double.MIN_VALUE);
assertEquals(n + " choose " + k, Math.log((double)binomialCoefficient(n, k)), MathUtils.binomialCoefficientLog(n, k), 10E-12);
assertEquals(n + " choose " + k, binomialCoefficient(n, k), MathUtils.binomialCoefficientDouble(n, k), Double.MIN_VALUE);
assertEquals(n + " choose " + k, Math.log(binomialCoefficient(n, k)), MathUtils.binomialCoefficientLog(n, k), 10E-12);
}
}
@ -181,7 +181,7 @@ public final class MathUtilsTest extends TestCase {
long expected = binomialCoefficient(n[i], k[i]);
assertEquals(n[i] + " choose " + k[i], expected,
MathUtils.binomialCoefficient(n[i], k[i]));
assertEquals(n[i] + " choose " + k[i], (double) expected,
assertEquals(n[i] + " choose " + k[i], expected,
MathUtils.binomialCoefficientDouble(n[i], k[i]), 0.0);
assertEquals("log(" + n[i] + " choose " + k[i] + ")", Math.log(expected),
MathUtils.binomialCoefficientLog(n[i], k[i]), 0.0);
@ -253,53 +253,53 @@ public final class MathUtilsTest extends TestCase {
MathUtils.binomialCoefficient(4, 5);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficientDouble(4, 5);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficientLog(4, 5);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficient(-1, -2);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficientDouble(-1, -2);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficientLog(-1, -2);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficient(67, 30);
fail("expecting ArithmeticException");
} catch (ArithmeticException ex) {
;
// ignored
}
try {
MathUtils.binomialCoefficient(67, 34);
fail("expecting ArithmeticException");
} catch (ArithmeticException ex) {
;
// ignored
}
double x = MathUtils.binomialCoefficientDouble(1030, 515);
assertTrue("expecting infinite binomial coefficient", Double
@ -378,8 +378,8 @@ public final class MathUtilsTest extends TestCase {
public void testFactorial() {
for (int i = 1; i < 21; i++) {
assertEquals(i + "! ", factorial(i), MathUtils.factorial(i));
assertEquals(i + "! ", (double)factorial(i), MathUtils.factorialDouble(i), Double.MIN_VALUE);
assertEquals(i + "! ", Math.log((double)factorial(i)), MathUtils.factorialLog(i), 10E-12);
assertEquals(i + "! ", factorial(i), MathUtils.factorialDouble(i), Double.MIN_VALUE);
assertEquals(i + "! ", Math.log(factorial(i)), MathUtils.factorialLog(i), 10E-12);
}
assertEquals("0", 1, MathUtils.factorial(0));
@ -392,25 +392,25 @@ public final class MathUtilsTest extends TestCase {
MathUtils.factorial(-1);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.factorialDouble(-1);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.factorialLog(-1);
fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) {
;
// ignored
}
try {
MathUtils.factorial(21);
fail("expecting ArithmeticException");
} catch (ArithmeticException ex) {
;
// ignored
}
assertTrue("expecting infinite factorial value", Double.isInfinite(MathUtils.factorialDouble(171)));
}
@ -515,7 +515,7 @@ public final class MathUtilsTest extends TestCase {
// Generate 10 distinct random values
for (int i = 0; i < 10; i++) {
original[i] = random.nextUniform((double)i + 0.5, (double)i + 0.75);
original[i] = random.nextUniform(i + 0.5, i + 0.75);
}
// Generate a random permutation, making sure it is not the identity
@ -556,9 +556,9 @@ public final class MathUtilsTest extends TestCase {
}
public void testIndicatorInt() {
assertEquals((int)1, MathUtils.indicator((int)(2)));
assertEquals((int)1, MathUtils.indicator((int)(0)));
assertEquals((int)(-1), MathUtils.indicator((int)(-2)));
assertEquals(1, MathUtils.indicator((2)));
assertEquals(1, MathUtils.indicator((0)));
assertEquals((-1), MathUtils.indicator((-2)));
}
public void testIndicatorLong() {
@ -999,9 +999,9 @@ public final class MathUtilsTest extends TestCase {
}
public void testSignInt() {
assertEquals((int) 1, MathUtils.sign((int) 2));
assertEquals((int) 0, MathUtils.sign((int) 0));
assertEquals((int) (-1), MathUtils.sign((int) (-2)));
assertEquals(1, MathUtils.sign(2));
assertEquals(0, MathUtils.sign(0));
assertEquals((-1), MathUtils.sign((-2)));
}
public void testSignLong() {