fixed numerous warnings in test code (unused fields/results, fields only set to null)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@566833 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2007-08-16 20:36:33 +00:00
parent 52b98250c2
commit ea14dd91da
28 changed files with 144 additions and 186 deletions

View File

@ -169,7 +169,7 @@ public final class LaguerreSolverTest extends TestCase {
try { try {
// bad function // bad function
UnivariateRealFunction f2 = new SinFunction(); UnivariateRealFunction f2 = new SinFunction();
UnivariateRealSolver solver2 = new LaguerreSolver(f2); new LaguerreSolver(f2);
fail("Expecting IllegalArgumentException - bad function"); fail("Expecting IllegalArgumentException - bad function");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected

View File

@ -126,13 +126,12 @@ public final class PolynomialFunctionLagrangeFormTest extends TestCase {
* Test of parameters for the polynomial. * Test of parameters for the polynomial.
*/ */
public void testParameters() throws Exception { public void testParameters() throws Exception {
PolynomialFunctionLagrangeForm p;
try { try {
// bad input array length // bad input array length
double x[] = { 1.0 }; double x[] = { 1.0 };
double y[] = { 2.0 }; double y[] = { 2.0 };
p = new PolynomialFunctionLagrangeForm(x, y); new PolynomialFunctionLagrangeForm(x, y);
fail("Expecting IllegalArgumentException - bad input array length"); fail("Expecting IllegalArgumentException - bad input array length");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -141,7 +140,7 @@ public final class PolynomialFunctionLagrangeFormTest extends TestCase {
// mismatch input arrays // mismatch input arrays
double x[] = { 1.0, 2.0, 3.0, 4.0 }; double x[] = { 1.0, 2.0, 3.0, 4.0 };
double y[] = { 0.0, -4.0, -24.0 }; double y[] = { 0.0, -4.0, -24.0 };
p = new PolynomialFunctionLagrangeForm(x, y); new PolynomialFunctionLagrangeForm(x, y);
fail("Expecting IllegalArgumentException - mismatch input arrays"); fail("Expecting IllegalArgumentException - mismatch input arrays");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected

View File

@ -125,13 +125,12 @@ public final class PolynomialFunctionNewtonFormTest extends TestCase {
* Test of parameters for the polynomial. * Test of parameters for the polynomial.
*/ */
public void testParameters() throws Exception { public void testParameters() throws Exception {
PolynomialFunctionNewtonForm p;
try { try {
// bad input array length // bad input array length
double a[] = { 1.0 }; double a[] = { 1.0 };
double c[] = { 2.0 }; double c[] = { 2.0 };
p = new PolynomialFunctionNewtonForm(a, c); new PolynomialFunctionNewtonForm(a, c);
fail("Expecting IllegalArgumentException - bad input array length"); fail("Expecting IllegalArgumentException - bad input array length");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -140,7 +139,7 @@ public final class PolynomialFunctionNewtonFormTest extends TestCase {
// mismatch input arrays // mismatch input arrays
double a[] = { 1.0, 2.0, 3.0, 4.0 }; double a[] = { 1.0, 2.0, 3.0, 4.0 };
double c[] = { 4.0, 3.0, 2.0, 1.0 }; double c[] = { 4.0, 3.0, 2.0, 1.0 };
p = new PolynomialFunctionNewtonForm(a, c); new PolynomialFunctionNewtonForm(a, c);
fail("Expecting IllegalArgumentException - mismatch input arrays"); fail("Expecting IllegalArgumentException - mismatch input arrays");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected

View File

@ -132,13 +132,13 @@ public final class PolynomialFunctionTest extends TestCase {
/** /**
* tests the firstDerivative function by comparision * tests the firstDerivative function by comparison
* *
* <p>This will test the functions * <p>This will test the functions
* <tt>f(x) = x^3 - 2x^2 + 6x + 3, g(x) = 3x^2 - 4x + 6</tt> * <tt>f(x) = x^3 - 2x^2 + 6x + 3, g(x) = 3x^2 - 4x + 6</tt>
* and <tt>h(x) = 6x - 4</tt> * and <tt>h(x) = 6x - 4</tt>
*/ */
public void testfirstDerivativeComparision() throws MathException { public void testfirstDerivativeComparison() throws MathException {
double[] f_coeff = { 3.0, 6.0, -2.0, 1.0 }; double[] f_coeff = { 3.0, 6.0, -2.0, 1.0 };
double[] g_coeff = { 6.0, -4.0, 3.0 }; double[] g_coeff = { 6.0, -4.0, 3.0 };
double[] h_coeff = { -4.0, 6.0 }; double[] h_coeff = { -4.0, 6.0 };
@ -155,9 +155,9 @@ public final class PolynomialFunctionTest extends TestCase {
assertEquals( f.derivative().value(-3.25), g.value(-3.25), tolerance ); assertEquals( f.derivative().value(-3.25), g.value(-3.25), tolerance );
// compare g' = h // compare g' = h
assertEquals( g.derivative().value(Math.PI), h.value(Math.PI), tolerance );
assertEquals( g.derivative().value(Math.E), h.value(Math.E), tolerance );
// compare f'' = h
} }
} }

View File

@ -63,24 +63,21 @@ public class PolynomialSplineFunctionTest extends TestCase {
assertEquals(3, spline.getN()); assertEquals(3, spline.getN());
try { // too few knots try { // too few knots
spline = new PolynomialSplineFunction(new double[] {0}, polynomials);
new PolynomialSplineFunction(new double[] {0}, polynomials);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { // too many knots try { // too many knots
spline = new PolynomialSplineFunction(new double[] {0,1,2,3,4}, polynomials);
new PolynomialSplineFunction(new double[] {0,1,2,3,4}, polynomials);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { // knots not increasing try { // knots not increasing
spline = new PolynomialSplineFunction(new double[] {0,1, 3, 2}, polynomials);
new PolynomialSplineFunction(new double[] {0,1, 3, 2}, polynomials);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected

View File

@ -52,7 +52,7 @@ public class UnivariateRealSolverFactoryImplTest extends TestCase {
public void testNewBisectionSolverNull() { public void testNewBisectionSolverNull() {
try { try {
UnivariateRealSolver solver = factory.newBisectionSolver(null); factory.newBisectionSolver(null);
fail(); fail();
} catch(IllegalArgumentException ex) { } catch(IllegalArgumentException ex) {
// success // success
@ -67,7 +67,7 @@ public class UnivariateRealSolverFactoryImplTest extends TestCase {
public void testNewNewtonSolverNull() { public void testNewNewtonSolverNull() {
try { try {
UnivariateRealSolver solver = factory.newNewtonSolver(null); factory.newNewtonSolver(null);
fail(); fail();
} catch(IllegalArgumentException ex) { } catch(IllegalArgumentException ex) {
// success // success
@ -82,7 +82,7 @@ public class UnivariateRealSolverFactoryImplTest extends TestCase {
public void testNewBrentSolverNull() { public void testNewBrentSolverNull() {
try { try {
UnivariateRealSolver solver = factory.newBrentSolver(null); factory.newBrentSolver(null);
fail(); fail();
} catch(IllegalArgumentException ex) { } catch(IllegalArgumentException ex) {
// success // success
@ -97,7 +97,7 @@ public class UnivariateRealSolverFactoryImplTest extends TestCase {
public void testNewSecantSolverNull() { public void testNewSecantSolverNull() {
try { try {
UnivariateRealSolver solver = factory.newSecantSolver(null); factory.newSecantSolver(null);
fail(); fail();
} catch(IllegalArgumentException ex) { } catch(IllegalArgumentException ex) {
// success // success

View File

@ -40,20 +40,19 @@ public class UnivariateRealSolverUtilsTest extends TestCase {
public void testSolveBadParameters() throws MathException { public void testSolveBadParameters() throws MathException {
try { // bad endpoints try { // bad endpoints
double x = UnivariateRealSolverUtils.solve(sin,0.0, 4.0, 4.0); UnivariateRealSolverUtils.solve(sin,0.0, 4.0, 4.0);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { // bad accuracy try { // bad accuracy
double x = UnivariateRealSolverUtils.solve(sin, 0.0, 4.0, 0.0); UnivariateRealSolverUtils.solve(sin, 0.0, 4.0, 0.0);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
} }
public void testSolveSin() throws MathException { public void testSolveSin() throws MathException {
double x = UnivariateRealSolverUtils.solve(sin, 1.0, double x = UnivariateRealSolverUtils.solve(sin, 1.0, 4.0);
4.0);
assertEquals(Math.PI, x, 1.0e-4); assertEquals(Math.PI, x, 1.0e-4);
} }
@ -76,8 +75,7 @@ public class UnivariateRealSolverUtilsTest extends TestCase {
public void testSolveNoRoot() throws MathException { public void testSolveNoRoot() throws MathException {
try { try {
double x = UnivariateRealSolverUtils.solve(sin, 1.0, UnivariateRealSolverUtils.solve(sin, 1.0, 1.5);
1.5);
fail("Expecting IllegalArgumentException "); fail("Expecting IllegalArgumentException ");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -93,8 +91,7 @@ public class UnivariateRealSolverUtilsTest extends TestCase {
public void testBracketCornerSolution() throws MathException { public void testBracketCornerSolution() throws MathException {
try { try {
double[] result = UnivariateRealSolverUtils.bracket(sin, UnivariateRealSolverUtils.bracket(sin, 1.5, 0, 2.0);
1.5, 0, 2.0);
fail("Expecting ConvergenceException"); fail("Expecting ConvergenceException");
} catch (ConvergenceException ex) { } catch (ConvergenceException ex) {
// expected // expected
@ -103,25 +100,25 @@ public class UnivariateRealSolverUtilsTest extends TestCase {
public void testBadParameters() throws MathException { public void testBadParameters() throws MathException {
try { // null function try { // null function
double[] result = UnivariateRealSolverUtils.bracket(null, 1.5, 0, 2.0); UnivariateRealSolverUtils.bracket(null, 1.5, 0, 2.0);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { // initial not between endpoints try { // initial not between endpoints
double[] result = UnivariateRealSolverUtils.bracket(sin, 2.5, 0, 2.0); UnivariateRealSolverUtils.bracket(sin, 2.5, 0, 2.0);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { // endpoints not valid try { // endpoints not valid
double[] result = UnivariateRealSolverUtils.bracket(sin, 1.5, 2.0, 1.0); UnivariateRealSolverUtils.bracket(sin, 1.5, 2.0, 1.0);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { // bad maximum iterations try { // bad maximum iterations
double[] result = UnivariateRealSolverUtils.bracket(sin, 1.5, 0, 2.0, 0); UnivariateRealSolverUtils.bracket(sin, 1.5, 0, 2.0, 0);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected

View File

@ -39,7 +39,6 @@ public class ComplexUtilsTest extends TestCase {
private Complex infNegInf = new Complex(inf, negInf); private Complex infNegInf = new Complex(inf, negInf);
private Complex infInf = new Complex(inf, inf); private Complex infInf = new Complex(inf, inf);
private Complex negInfNegInf = new Complex(negInf, negInf); private Complex negInfNegInf = new Complex(negInf, negInf);
private Complex oneNaN = new Complex(1, nan);
private Complex infNaN = new Complex(inf, nan); private Complex infNaN = new Complex(inf, nan);
private Complex negInfNaN = new Complex(negInf, nan); private Complex negInfNaN = new Complex(negInf, nan);
private Complex nanInf = new Complex(nan, inf); private Complex nanInf = new Complex(nan, inf);
@ -48,11 +47,8 @@ public class ComplexUtilsTest extends TestCase {
private Complex nanZero = new Complex(nan, 0); private Complex nanZero = new Complex(nan, 0);
private Complex infZero = new Complex(inf, 0); private Complex infZero = new Complex(inf, 0);
private Complex zeroInf = new Complex(0, inf); private Complex zeroInf = new Complex(0, inf);
private Complex zeroNegInf = new Complex(0, negInf);
private Complex negInfZero = new Complex(negInf, 0); private Complex negInfZero = new Complex(negInf, 0);
private ComplexFormat fmt = new ComplexFormat();
public void testAcos() { public void testAcos() {
Complex z = new Complex(3, 4); Complex z = new Complex(3, 4);
Complex expected = new Complex(0.936812, -2.30551); Complex expected = new Complex(0.936812, -2.30551);
@ -78,7 +74,7 @@ public class ComplexUtilsTest extends TestCase {
public void testAcosNull() { public void testAcosNull() {
try { try {
Complex z = ComplexUtils.acos(null); ComplexUtils.acos(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -108,7 +104,7 @@ public class ComplexUtilsTest extends TestCase {
public void testAsinNull() { public void testAsinNull() {
try { try {
Complex z = ComplexUtils.asin(null); ComplexUtils.asin(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -139,7 +135,7 @@ public class ComplexUtilsTest extends TestCase {
public void testAtanNull() { public void testAtanNull() {
try { try {
Complex z = ComplexUtils.atan(null); ComplexUtils.atan(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -169,7 +165,7 @@ public class ComplexUtilsTest extends TestCase {
public void testCosNull() { public void testCosNull() {
try { try {
Complex z = ComplexUtils.cos(null); ComplexUtils.cos(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -199,7 +195,7 @@ public class ComplexUtilsTest extends TestCase {
public void testCoshNull() { public void testCoshNull() {
try { try {
Complex z = ComplexUtils.cosh(null); ComplexUtils.cosh(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -234,7 +230,7 @@ public class ComplexUtilsTest extends TestCase {
public void testExpNull() { public void testExpNull() {
try { try {
Complex z = ComplexUtils.exp(null); ComplexUtils.exp(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -275,7 +271,7 @@ public class ComplexUtilsTest extends TestCase {
public void testlogNull() { public void testlogNull() {
try { try {
Complex z = ComplexUtils.log(null); ComplexUtils.log(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -318,7 +314,7 @@ public class ComplexUtilsTest extends TestCase {
public void testPolar2ComplexIllegalModulus() { public void testPolar2ComplexIllegalModulus() {
try { try {
Complex z = ComplexUtils.polar2Complex(-1, 0); ComplexUtils.polar2Complex(-1, 0);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -405,13 +401,13 @@ public class ComplexUtilsTest extends TestCase {
public void testpowNull() { public void testpowNull() {
try { try {
Complex z = ComplexUtils.pow(null, Complex.ONE); ComplexUtils.pow(null, Complex.ONE);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
} }
try { try {
Complex z = ComplexUtils.pow(Complex.ONE, null); ComplexUtils.pow(Complex.ONE, null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -441,7 +437,7 @@ public class ComplexUtilsTest extends TestCase {
public void testSinNull() { public void testSinNull() {
try { try {
Complex z = ComplexUtils.sin(null); ComplexUtils.sin(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -471,7 +467,7 @@ public class ComplexUtilsTest extends TestCase {
public void testsinhNull() { public void testsinhNull() {
try { try {
Complex z = ComplexUtils.sinh(null); ComplexUtils.sinh(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -539,7 +535,7 @@ public class ComplexUtilsTest extends TestCase {
public void testSqrtNull() { public void testSqrtNull() {
try { try {
Complex z = ComplexUtils.sqrt(null); ComplexUtils.sqrt(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -558,7 +554,7 @@ public class ComplexUtilsTest extends TestCase {
public void testSqrt1zNull() { public void testSqrt1zNull() {
try { try {
Complex z = ComplexUtils.sqrt1z(null); ComplexUtils.sqrt1z(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -593,7 +589,7 @@ public class ComplexUtilsTest extends TestCase {
public void testTanNull() { public void testTanNull() {
try { try {
Complex z = ComplexUtils.tan(null); ComplexUtils.tan(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected
@ -627,7 +623,7 @@ public class ComplexUtilsTest extends TestCase {
public void testTanhNull() { public void testTanhNull() {
try { try {
Complex z = ComplexUtils.tanh(null); ComplexUtils.tanh(null);
fail("Expecting NullPointerException"); fail("Expecting NullPointerException");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// expected // expected

View File

@ -233,14 +233,14 @@ public class FractionFormatTest extends TestCase {
public void testParseProperInvalidMinus() { public void testParseProperInvalidMinus() {
String source = "2 -2 / 3"; String source = "2 -2 / 3";
try { try {
Fraction c = properFormat.parse(source); properFormat.parse(source);
fail("invalid minus in improper fraction."); fail("invalid minus in improper fraction.");
} catch (ParseException ex) { } catch (ParseException ex) {
// expected // expected
} }
source = "2 2 / -3"; source = "2 2 / -3";
try { try {
Fraction c = properFormat.parse(source); properFormat.parse(source);
fail("invalid minus in improper fraction."); fail("invalid minus in improper fraction.");
} catch (ParseException ex) { } catch (ParseException ex) {
// expected // expected

View File

@ -280,7 +280,7 @@ public class FractionTest extends TestCase {
Fraction f1 = new Fraction(3, 5); Fraction f1 = new Fraction(3, 5);
Fraction f2 = Fraction.ZERO; Fraction f2 = Fraction.ZERO;
try { try {
Fraction f = f1.divide(f2); f1.divide(f2);
fail("expecting ArithmeticException"); fail("expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
@ -417,7 +417,6 @@ public class FractionTest extends TestCase {
public void testEqualsAndHashCode() { public void testEqualsAndHashCode() {
Fraction zero = new Fraction(0,1); Fraction zero = new Fraction(0,1);
Fraction nullFraction = null; Fraction nullFraction = null;
int zeroHash = zero.hashCode();
assertTrue( zero.equals(zero)); assertTrue( zero.equals(zero));
assertFalse(zero.equals(nullFraction)); assertFalse(zero.equals(nullFraction));
assertFalse(zero.equals(new Double(0))); assertFalse(zero.equals(new Double(0)));
@ -433,7 +432,7 @@ public class FractionTest extends TestCase {
assertTrue(threeFourths.equals(Fraction.getReducedFraction(6, 8))); assertTrue(threeFourths.equals(Fraction.getReducedFraction(6, 8)));
assertTrue(Fraction.ZERO.equals(Fraction.getReducedFraction(0, -1))); assertTrue(Fraction.ZERO.equals(Fraction.getReducedFraction(0, -1)));
try { try {
Fraction f = Fraction.getReducedFraction(1, 0); Fraction.getReducedFraction(1, 0);
fail("expecting ArithmeticException"); fail("expecting ArithmeticException");
} catch (ArithmeticException ex) { } catch (ArithmeticException ex) {
// expected // expected

View File

@ -170,38 +170,38 @@ public final class BigMatrixImplTest extends TestCase {
assertClose("double, BigDecimal", m1, m3, Double.MIN_VALUE); assertClose("double, BigDecimal", m1, m3, Double.MIN_VALUE);
assertClose("string, BigDecimal", m2, m3, Double.MIN_VALUE); assertClose("string, BigDecimal", m2, m3, Double.MIN_VALUE);
try { try {
BigMatrix m4 = new BigMatrixImpl(new String[][] {{"0", "hello", "1"}}); new BigMatrixImpl(new String[][] {{"0", "hello", "1"}});
fail("Expecting NumberFormatException"); fail("Expecting NumberFormatException");
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
// expected // expected
} }
try { try {
BigMatrix m4 = new BigMatrixImpl(new String[][] {}); new BigMatrixImpl(new String[][] {});
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
BigMatrix m4 = new BigMatrixImpl(new String[][] {{},{}}); new BigMatrixImpl(new String[][] {{},{}});
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
BigMatrix m4 = new BigMatrixImpl(new String[][] {{"a", "b"},{"c"}}); new BigMatrixImpl(new String[][] {{"a", "b"},{"c"}});
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
BigMatrix m4 = new BigMatrixImpl(0, 1); new BigMatrixImpl(0, 1);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
BigMatrix m4 = new BigMatrixImpl(1, 0); new BigMatrixImpl(1, 0);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -228,7 +228,7 @@ public final class BigMatrixImplTest extends TestCase {
BigMatrixImpl m = new BigMatrixImpl(testData); BigMatrixImpl m = new BigMatrixImpl(testData);
BigMatrixImpl m2 = new BigMatrixImpl(testData2); BigMatrixImpl m2 = new BigMatrixImpl(testData2);
try { try {
BigMatrixImpl mPlusMInv = (BigMatrixImpl)m.add(m2); m.add(m2);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -250,7 +250,7 @@ public final class BigMatrixImplTest extends TestCase {
assertClose("m-n = m + -n",m.subtract(m2), assertClose("m-n = m + -n",m.subtract(m2),
m2.scalarMultiply(new BigDecimal(-1d)).add(m),entryTolerance); m2.scalarMultiply(new BigDecimal(-1d)).add(m),entryTolerance);
try { try {
BigMatrix a = m.subtract(new BigMatrixImpl(testData2)); m.subtract(new BigMatrixImpl(testData2));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -274,7 +274,7 @@ public final class BigMatrixImplTest extends TestCase {
assertClose("identity multiply",m2.multiply(identity), assertClose("identity multiply",m2.multiply(identity),
m2,entryTolerance); m2,entryTolerance);
try { try {
BigMatrix a = m.multiply(new BigMatrixImpl(bigSingular)); m.multiply(new BigMatrixImpl(bigSingular));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -342,26 +342,26 @@ public final class BigMatrixImplTest extends TestCase {
asDouble(m.solve(asBigDecimal(testVector))), asDouble(m.solve(asBigDecimal(testVector))),
normTolerance); normTolerance);
try { try {
double[] x = asDouble(m.solve(asBigDecimal(testVector2))); asDouble(m.solve(asBigDecimal(testVector2)));
fail("expecting IllegalArgumentException"); fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
BigMatrix bs = new BigMatrixImpl(bigSingular); BigMatrix bs = new BigMatrixImpl(bigSingular);
try { try {
BigMatrix a = bs.solve(bs); bs.solve(bs);
fail("Expecting InvalidMatrixException"); fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) { } catch (InvalidMatrixException ex) {
; ;
} }
try { try {
BigMatrix a = m.solve(bs); m.solve(bs);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
BigMatrix a = (new BigMatrixImpl(testData2)).solve(bs); new BigMatrixImpl(testData2).solve(bs);
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -388,7 +388,7 @@ public final class BigMatrixImplTest extends TestCase {
assertEquals("nonsingular R test 2",-1d,m.getDeterminant().doubleValue(),normTolerance); assertEquals("nonsingular R test 2",-1d,m.getDeterminant().doubleValue(),normTolerance);
try { try {
double a = new BigMatrixImpl(testData2).getDeterminant().doubleValue(); new BigMatrixImpl(testData2).getDeterminant().doubleValue();
fail("Expecting InvalidMatrixException"); fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) { } catch (InvalidMatrixException ex) {
; ;
@ -401,7 +401,7 @@ public final class BigMatrixImplTest extends TestCase {
assertEquals("identity trace",3d,m.getTrace().doubleValue(),entryTolerance); assertEquals("identity trace",3d,m.getTrace().doubleValue(),entryTolerance);
m = new BigMatrixImpl(testData2); m = new BigMatrixImpl(testData2);
try { try {
double x = m.getTrace().doubleValue(); m.getTrace().doubleValue();
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -422,7 +422,7 @@ public final class BigMatrixImplTest extends TestCase {
assertClose("identity operate",testVector,x,entryTolerance); assertClose("identity operate",testVector,x,entryTolerance);
m = new BigMatrixImpl(bigSingular); m = new BigMatrixImpl(bigSingular);
try { try {
x = asDouble(m.operate(asBigDecimal(testVector))); asDouble(m.operate(asBigDecimal(testVector)));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -461,7 +461,7 @@ public final class BigMatrixImplTest extends TestCase {
BigMatrixImpl m = new BigMatrixImpl(testData); BigMatrixImpl m = new BigMatrixImpl(testData);
BigMatrixImpl mInv = new BigMatrixImpl(testDataInv); BigMatrixImpl mInv = new BigMatrixImpl(testDataInv);
BigMatrixImpl identity = new BigMatrixImpl(id); BigMatrixImpl identity = new BigMatrixImpl(id);
BigMatrixImpl m2 = new BigMatrixImpl(testData2); new BigMatrixImpl(testData2);
assertClose("inverse multiply",m.preMultiply(mInv), assertClose("inverse multiply",m.preMultiply(mInv),
identity,entryTolerance); identity,entryTolerance);
assertClose("inverse multiply",mInv.preMultiply(m), assertClose("inverse multiply",mInv.preMultiply(m),
@ -471,7 +471,7 @@ public final class BigMatrixImplTest extends TestCase {
assertClose("identity multiply",identity.preMultiply(mInv), assertClose("identity multiply",identity.preMultiply(mInv),
mInv,entryTolerance); mInv,entryTolerance);
try { try {
BigMatrix a = m.preMultiply(new BigMatrixImpl(bigSingular)); m.preMultiply(new BigMatrixImpl(bigSingular));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -483,13 +483,13 @@ public final class BigMatrixImplTest extends TestCase {
assertClose("get row",m.getRowAsDoubleArray(0),testDataRow1,entryTolerance); assertClose("get row",m.getRowAsDoubleArray(0),testDataRow1,entryTolerance);
assertClose("get col",m.getColumnAsDoubleArray(2),testDataCol3,entryTolerance); assertClose("get col",m.getColumnAsDoubleArray(2),testDataCol3,entryTolerance);
try { try {
double[] x = m.getRowAsDoubleArray(10); m.getRowAsDoubleArray(10);
fail("expecting MatrixIndexException"); fail("expecting MatrixIndexException");
} catch (MatrixIndexException ex) { } catch (MatrixIndexException ex) {
; ;
} }
try { try {
double[] x = m.getColumnAsDoubleArray(-1); m.getColumnAsDoubleArray(-1);
fail("expecting MatrixIndexException"); fail("expecting MatrixIndexException");
} catch (MatrixIndexException ex) { } catch (MatrixIndexException ex) {
; ;

View File

@ -141,7 +141,7 @@ public final class RealMatrixImplTest extends TestCase {
RealMatrixImpl m = new RealMatrixImpl(testData); RealMatrixImpl m = new RealMatrixImpl(testData);
RealMatrixImpl m2 = new RealMatrixImpl(testData2); RealMatrixImpl m2 = new RealMatrixImpl(testData2);
try { try {
RealMatrixImpl mPlusMInv = (RealMatrixImpl)m.add(m2); m.add(m2);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -163,7 +163,7 @@ public final class RealMatrixImplTest extends TestCase {
assertClose("m-n = m + -n",m.subtract(m2), assertClose("m-n = m + -n",m.subtract(m2),
m2.scalarMultiply(-1d).add(m),entryTolerance); m2.scalarMultiply(-1d).add(m),entryTolerance);
try { try {
RealMatrix a = m.subtract(new RealMatrixImpl(testData2)); m.subtract(new RealMatrixImpl(testData2));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -187,7 +187,7 @@ public final class RealMatrixImplTest extends TestCase {
assertClose("identity multiply",m2.multiply(identity), assertClose("identity multiply",m2.multiply(identity),
m2,entryTolerance); m2,entryTolerance);
try { try {
RealMatrix a = m.multiply(new RealMatrixImpl(bigSingular)); m.multiply(new RealMatrixImpl(bigSingular));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -253,26 +253,26 @@ public final class RealMatrixImplTest extends TestCase {
assertClose("inverse-operate",mInv.operate(testVector), assertClose("inverse-operate",mInv.operate(testVector),
m.solve(testVector),normTolerance); m.solve(testVector),normTolerance);
try { try {
double[] x = m.solve(testVector2); m.solve(testVector2);
fail("expecting IllegalArgumentException"); fail("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
RealMatrix bs = new RealMatrixImpl(bigSingular); RealMatrix bs = new RealMatrixImpl(bigSingular);
try { try {
RealMatrix a = bs.solve(bs); bs.solve(bs);
fail("Expecting InvalidMatrixException"); fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) { } catch (InvalidMatrixException ex) {
; ;
} }
try { try {
RealMatrix a = m.solve(bs); m.solve(bs);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
RealMatrix a = (new RealMatrixImpl(testData2)).solve(bs); new RealMatrixImpl(testData2).solve(bs);
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -299,7 +299,7 @@ public final class RealMatrixImplTest extends TestCase {
assertEquals("nonsingular R test 2",-1d,m.getDeterminant(),normTolerance); assertEquals("nonsingular R test 2",-1d,m.getDeterminant(),normTolerance);
try { try {
double a = new RealMatrixImpl(testData2).getDeterminant(); new RealMatrixImpl(testData2).getDeterminant();
fail("Expecting InvalidMatrixException"); fail("Expecting InvalidMatrixException");
} catch (InvalidMatrixException ex) { } catch (InvalidMatrixException ex) {
; ;
@ -312,7 +312,7 @@ public final class RealMatrixImplTest extends TestCase {
assertEquals("identity trace",3d,m.getTrace(),entryTolerance); assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
m = new RealMatrixImpl(testData2); m = new RealMatrixImpl(testData2);
try { try {
double x = m.getTrace(); m.getTrace();
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -333,7 +333,7 @@ public final class RealMatrixImplTest extends TestCase {
assertClose("identity operate",testVector,x,entryTolerance); assertClose("identity operate",testVector,x,entryTolerance);
m = new RealMatrixImpl(bigSingular); m = new RealMatrixImpl(bigSingular);
try { try {
x = m.operate(testVector); m.operate(testVector);
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -372,7 +372,6 @@ public final class RealMatrixImplTest extends TestCase {
RealMatrixImpl m = new RealMatrixImpl(testData); RealMatrixImpl m = new RealMatrixImpl(testData);
RealMatrixImpl mInv = new RealMatrixImpl(testDataInv); RealMatrixImpl mInv = new RealMatrixImpl(testDataInv);
RealMatrixImpl identity = new RealMatrixImpl(id); RealMatrixImpl identity = new RealMatrixImpl(id);
RealMatrixImpl m2 = new RealMatrixImpl(testData2);
assertClose("inverse multiply",m.preMultiply(mInv), assertClose("inverse multiply",m.preMultiply(mInv),
identity,entryTolerance); identity,entryTolerance);
assertClose("inverse multiply",mInv.preMultiply(m), assertClose("inverse multiply",mInv.preMultiply(m),
@ -382,7 +381,7 @@ public final class RealMatrixImplTest extends TestCase {
assertClose("identity multiply",identity.preMultiply(mInv), assertClose("identity multiply",identity.preMultiply(mInv),
mInv,entryTolerance); mInv,entryTolerance);
try { try {
RealMatrix a = m.preMultiply(new RealMatrixImpl(bigSingular)); m.preMultiply(new RealMatrixImpl(bigSingular));
fail("Expecting illegalArgumentException"); fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -394,13 +393,13 @@ public final class RealMatrixImplTest extends TestCase {
assertClose("get row",m.getRow(0),testDataRow1,entryTolerance); assertClose("get row",m.getRow(0),testDataRow1,entryTolerance);
assertClose("get col",m.getColumn(2),testDataCol3,entryTolerance); assertClose("get col",m.getColumn(2),testDataCol3,entryTolerance);
try { try {
double[] x = m.getRow(10); m.getRow(10);
fail("expecting MatrixIndexException"); fail("expecting MatrixIndexException");
} catch (MatrixIndexException ex) { } catch (MatrixIndexException ex) {
; ;
} }
try { try {
double[] x = m.getColumn(-1); m.getColumn(-1);
fail("expecting MatrixIndexException"); fail("expecting MatrixIndexException");
} catch (MatrixIndexException ex) { } catch (MatrixIndexException ex) {
; ;

View File

@ -44,7 +44,7 @@ public class AbstractRandomGeneratorTest extends RandomDataTest {
public void testNextInt() { public void testNextInt() {
try { try {
int x = testGenerator.nextInt(-1); testGenerator.nextInt(-1);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;

View File

@ -43,7 +43,6 @@ public class RandomDataTest extends RetryTestCase {
protected long smallSampleSize = 1000; protected long smallSampleSize = 1000;
protected double[] expected = {250,250,250,250}; protected double[] expected = {250,250,250,250};
protected int largeSampleSize = 10000; protected int largeSampleSize = 10000;
private int tolerance = 50;
private String[] hex = private String[] hex =
{"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
protected RandomDataImpl randomData = null; protected RandomDataImpl randomData = null;
@ -73,7 +72,7 @@ public class RandomDataTest extends RetryTestCase {
/** test dispersion and failure modes for nextInt() */ /** test dispersion and failure modes for nextInt() */
public void testNextInt() { public void testNextInt() {
try { try {
int x = randomData.nextInt(4,3); randomData.nextInt(4,3);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -100,7 +99,7 @@ public class RandomDataTest extends RetryTestCase {
/** test dispersion and failure modes for nextLong() */ /** test dispersion and failure modes for nextLong() */
public void testNextLong() { public void testNextLong() {
try { try {
long x = randomData.nextLong(4,3); randomData.nextLong(4,3);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -127,7 +126,7 @@ public class RandomDataTest extends RetryTestCase {
/** test dispersion and failure modes for nextSecureLong() */ /** test dispersion and failure modes for nextSecureLong() */
public void testNextSecureLong() { public void testNextSecureLong() {
try { try {
long x = randomData.nextSecureLong(4,3); randomData.nextSecureLong(4,3);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -154,7 +153,7 @@ public class RandomDataTest extends RetryTestCase {
/** test dispersion and failure modes for nextSecureInt() */ /** test dispersion and failure modes for nextSecureInt() */
public void testNextSecureInt() { public void testNextSecureInt() {
try { try {
long x = randomData.nextSecureInt(4,3); randomData.nextSecureInt(4,3);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -186,13 +185,12 @@ public class RandomDataTest extends RetryTestCase {
*/ */
public void testNextPoisson() { public void testNextPoisson() {
try { try {
long x = randomData.nextPoisson(0); randomData.nextPoisson(0);
fail("zero mean -- expecting IllegalArgumentException"); fail("zero mean -- expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
Frequency f = new Frequency(); Frequency f = new Frequency();
long v = 0;
for (int i = 0; i<largeSampleSize; i++) { for (int i = 0; i<largeSampleSize; i++) {
try { try {
f.addValue(randomData.nextPoisson(4.0d)); f.addValue(randomData.nextPoisson(4.0d));
@ -207,13 +205,13 @@ public class RandomDataTest extends RetryTestCase {
new Double(cumFreq).doubleValue()/new Double(sumFreq).doubleValue(); new Double(cumFreq).doubleValue()/new Double(sumFreq).doubleValue();
assertEquals("cum Poisson(4)",cumPct,0.7851,0.2); assertEquals("cum Poisson(4)",cumPct,0.7851,0.2);
try { try {
long x = randomData.nextPoisson(-1); randomData.nextPoisson(-1);
fail("negative mean supplied -- IllegalArgumentException expected"); fail("negative mean supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
long x = randomData.nextPoisson(0); randomData.nextPoisson(0);
fail("0 mean supplied -- IllegalArgumentException expected"); fail("0 mean supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -224,13 +222,13 @@ public class RandomDataTest extends RetryTestCase {
/** test dispersion and failute modes for nextHex() */ /** test dispersion and failute modes for nextHex() */
public void testNextHex() { public void testNextHex() {
try { try {
String x = randomData.nextHexString(-1); randomData.nextHexString(-1);
fail("negative length supplied -- IllegalArgumentException expected"); fail("negative length supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
String x = randomData.nextHexString(0); randomData.nextHexString(0);
fail("zero length supplied -- IllegalArgumentException expected"); fail("zero length supplied -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -278,13 +276,13 @@ public class RandomDataTest extends RetryTestCase {
/** test dispersion and failute modes for nextHex() */ /** test dispersion and failute modes for nextHex() */
public void testNextSecureHex() { public void testNextSecureHex() {
try { try {
String x = randomData.nextSecureHexString(-1); randomData.nextSecureHexString(-1);
fail("negative length -- IllegalArgumentException expected"); fail("negative length -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
String x = randomData.nextSecureHexString(0); randomData.nextSecureHexString(0);
fail("zero length -- IllegalArgumentException expected"); fail("zero length -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -332,13 +330,13 @@ public class RandomDataTest extends RetryTestCase {
/** test failure modes and dispersion of nextUniform() */ /** test failure modes and dispersion of nextUniform() */
public void testNextUniform() { public void testNextUniform() {
try { try {
double x = randomData.nextUniform(4,3); randomData.nextUniform(4,3);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = randomData.nextUniform(3,3); randomData.nextUniform(3,3);
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -378,7 +376,7 @@ public class RandomDataTest extends RetryTestCase {
/** test failure modes and distribution of nextGaussian() */ /** test failure modes and distribution of nextGaussian() */
public void testNextGaussian() { public void testNextGaussian() {
try { try {
double x = randomData.nextGaussian(0,0); randomData.nextGaussian(0,0);
fail("zero sigma -- IllegalArgumentException expected"); fail("zero sigma -- IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -399,7 +397,7 @@ public class RandomDataTest extends RetryTestCase {
/** test failure modes and distribution of nextExponential() */ /** test failure modes and distribution of nextExponential() */
public void testNextExponential() { public void testNextExponential() {
try { try {
double x = randomData.nextExponential(-1); randomData.nextExponential(-1);
fail("negative mean -- expecting IllegalArgumentException"); fail("negative mean -- expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -469,16 +467,16 @@ public class RandomDataTest extends RetryTestCase {
// test reseeding without first using the generators // test reseeding without first using the generators
RandomDataImpl rd = new RandomDataImpl(); RandomDataImpl rd = new RandomDataImpl();
rd.reSeed(100); rd.reSeed(100);
double ret = rd.nextLong(1,2); rd.nextLong(1,2);
RandomDataImpl rd2 = new RandomDataImpl(); RandomDataImpl rd2 = new RandomDataImpl();
rd2.reSeedSecure(2000); rd2.reSeedSecure(2000);
ret = rd2.nextSecureLong(1,2); rd2.nextSecureLong(1,2);
rd = new RandomDataImpl(); rd = new RandomDataImpl();
rd.reSeed(); rd.reSeed();
ret = rd.nextLong(1,2); rd.nextLong(1,2);
rd2 = new RandomDataImpl(); rd2 = new RandomDataImpl();
rd2.reSeedSecure(); rd2.reSeedSecure();
ret = rd2.nextSecureLong(1,2); rd2.nextSecureLong(1,2);
} }
/** tests for nextSample() sampling from Collection */ /** tests for nextSample() sampling from Collection */
@ -540,7 +538,6 @@ public class RandomDataTest extends RetryTestCase {
} }
private int findSample(Object[] u, Object[] samp) { private int findSample(Object[] u, Object[] samp) {
int result = -1;
for (int i = 0; i < u.length; i++) { for (int i = 0; i < u.length; i++) {
HashSet set = (HashSet) u[i]; HashSet set = (HashSet) u[i];
HashSet sampSet = new HashSet(); HashSet sampSet = new HashSet();
@ -596,7 +593,6 @@ public class RandomDataTest extends RetryTestCase {
} }
private int findPerm(int[][] p, int[] samp) { private int findPerm(int[][] p, int[] samp) {
int result = -1;
for (int i = 0; i < p.length; i++) { for (int i = 0; i < p.length; i++) {
boolean good = true; boolean good = true;
for (int j = 0; j < samp.length; j++) { for (int j = 0; j < samp.length; j++) {

View File

@ -40,8 +40,6 @@ public final class FrequencyTest extends TestCase {
private int oneI = 1; private int oneI = 1;
private int twoI = 2; private int twoI = 2;
private int threeI=3; private int threeI=3;
private String oneS = "1";
private String twoS = "2";
private double tolerance = 10E-15; private double tolerance = 10E-15;
private Frequency f = null; private Frequency f = null;

View File

@ -36,12 +36,8 @@ public final class StatUtilsTest extends TestCase {
private double sumSq = 18; private double sumSq = 18;
private double sum = 8; private double sum = 8;
private double var = 0.666666666666666666667; private double var = 0.666666666666666666667;
private double std = Math.sqrt(var);
private double n = 4;
private double min = 1; private double min = 1;
private double max = 3; private double max = 3;
private double skewness = 0;
private double kurtosis = 0.5;
private double tolerance = 10E-15; private double tolerance = 10E-15;
private double nan = Double.NaN; private double nan = Double.NaN;
@ -423,7 +419,7 @@ public final class StatUtilsTest extends TestCase {
public void testGeometricMean() throws Exception { public void testGeometricMean() throws Exception {
double[] test = null; double[] test = null;
try { try {
double x = StatUtils.geometricMean(test); StatUtils.geometricMean(test);
fail("Expecting IllegalArgumentException"); fail("Expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected

View File

@ -41,8 +41,6 @@ public final class DescriptiveStatisticsImplTest extends TestCase {
private double n = 4; private double n = 4;
private double min = 1; private double min = 1;
private double max = 3; private double max = 3;
private double skewness = 0;
private double kurtosis = 0.5;
private double tolerance = 10E-15; private double tolerance = 10E-15;
public DescriptiveStatisticsImplTest(String name) { public DescriptiveStatisticsImplTest(String name) {
@ -196,13 +194,13 @@ public final class DescriptiveStatisticsImplTest extends TestCase {
assertEquals("expecting max",5,u.getPercentile(99),10E-12); assertEquals("expecting max",5,u.getPercentile(99),10E-12);
assertEquals("expecting middle",3,u.getPercentile(50),10E-12); assertEquals("expecting middle",3,u.getPercentile(50),10E-12);
try { try {
double x = u.getPercentile(0); u.getPercentile(0);
fail("expecting IllegalArgumentException for getPercentile(0)"); fail("expecting IllegalArgumentException for getPercentile(0)");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = u.getPercentile(120); u.getPercentile(120);
fail("expecting IllegalArgumentException for getPercentile(120)"); fail("expecting IllegalArgumentException for getPercentile(120)");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;

View File

@ -42,8 +42,6 @@ public final class DescriptiveStatisticsTest extends TestCase {
private double n = 4; private double n = 4;
private double min = 1; private double min = 1;
private double max = 3; private double max = 3;
private double skewness = 0;
private double kurtosis = 0.5;
private double tolerance = 10E-15; private double tolerance = 10E-15;
public DescriptiveStatisticsTest(String name) { public DescriptiveStatisticsTest(String name) {
@ -251,13 +249,13 @@ public final class DescriptiveStatisticsTest extends TestCase {
assertEquals("expecting max",5,u.getPercentile(99),10E-12); assertEquals("expecting max",5,u.getPercentile(99),10E-12);
assertEquals("expecting middle",3,u.getPercentile(50),10E-12); assertEquals("expecting middle",3,u.getPercentile(50),10E-12);
try { try {
double x = u.getPercentile(0); u.getPercentile(0);
fail("expecting IllegalArgumentException for getPercentile(0)"); fail("expecting IllegalArgumentException for getPercentile(0)");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = u.getPercentile(120); u.getPercentile(120);
fail("expecting IllegalArgumentException for getPercentile(120)"); fail("expecting IllegalArgumentException for getPercentile(120)");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
@ -331,7 +329,7 @@ public final class DescriptiveStatisticsTest extends TestCase {
public void testNewInstanceClassNull() { public void testNewInstanceClassNull() {
try { try {
DescriptiveStatistics u = DescriptiveStatistics.newInstance((Class)null); DescriptiveStatistics.newInstance((Class)null);
fail("null is not a valid descriptive statistics class"); fail("null is not a valid descriptive statistics class");
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// success // success
@ -347,7 +345,9 @@ public final class DescriptiveStatisticsTest extends TestCase {
DescriptiveStatisticsImpl.class); DescriptiveStatisticsImpl.class);
assertNotNull(u); assertNotNull(u);
assertTrue(u instanceof DescriptiveStatisticsImpl); assertTrue(u instanceof DescriptiveStatisticsImpl);
} catch (Exception ex) { } catch (InstantiationException ex) {
fail();
} catch (IllegalAccessException ex) {
fail(); fail();
} }
} }

View File

@ -45,8 +45,6 @@ public final class ListUnivariateImplTest extends TestCase {
private double n = 4; private double n = 4;
private double min = 1; private double min = 1;
private double max = 3; private double max = 3;
private double skewness = 0;
private double kurtosis = 0.5;
private double tolerance = 10E-15; private double tolerance = 10E-15;
public ListUnivariateImplTest(String name) { public ListUnivariateImplTest(String name) {

View File

@ -44,8 +44,6 @@ public final class MixedListUnivariateImplTest extends TestCase {
private double n = 4; private double n = 4;
private double min = 1; private double min = 1;
private double max = 3; private double max = 3;
private double skewness = 0;
private double kurtosis = 0.5;
private double tolerance = 10E-15; private double tolerance = 10E-15;
private TransformerMap transformers = new TransformerMap(); private TransformerMap transformers = new TransformerMap();
@ -102,8 +100,6 @@ public final class MixedListUnivariateImplTest extends TestCase {
} }
public void testN0andN1Conditions() throws Exception { public void testN0andN1Conditions() throws Exception {
List list = new ArrayList();
DescriptiveStatistics u = new ListUnivariateImpl(new ArrayList(),transformers); DescriptiveStatistics u = new ListUnivariateImpl(new ArrayList(),transformers);
assertTrue( assertTrue(

View File

@ -54,7 +54,6 @@ public final class StatisticalSummaryValuesTest extends TestCase {
public void testEqualsAndHashCode() { public void testEqualsAndHashCode() {
StatisticalSummaryValues u = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6); StatisticalSummaryValues u = new StatisticalSummaryValues(1, 2, 3, 4, 5, 6);
StatisticalSummaryValues t = null; StatisticalSummaryValues t = null;
int emptyHash = u.hashCode();
assertTrue("reflexive", u.equals(u)); assertTrue("reflexive", u.equals(u));
assertFalse("non-null compared to null", u.equals(t)); assertFalse("non-null compared to null", u.equals(t));
assertFalse("wrong type", u.equals(new Double(0))); assertFalse("wrong type", u.equals(new Double(0)));

View File

@ -117,7 +117,6 @@ public final class SummaryStatisticsImplTest extends TestCase {
} }
public void testNaNContracts() { public void testNaNContracts() {
double nan = Double.NaN;
assertTrue("mean not NaN",Double.isNaN(u.getMean())); assertTrue("mean not NaN",Double.isNaN(u.getMean()));
assertTrue("min not NaN",Double.isNaN(u.getMin())); assertTrue("min not NaN",Double.isNaN(u.getMin()));
assertTrue("std dev not NaN",Double.isNaN(u.getStandardDeviation())); assertTrue("std dev not NaN",Double.isNaN(u.getStandardDeviation()));

View File

@ -32,11 +32,9 @@ public class TTestTest extends TestCase {
protected TTest testStatistic = new TTestImpl(); protected TTest testStatistic = new TTestImpl();
private double[] tooShortObs = { 1.0 }; private double[] tooShortObs = { 1.0 };
private double[] nullObserved = null;
private double[] emptyObs = {}; private double[] emptyObs = {};
private SummaryStatistics emptyStats = SummaryStatistics.newInstance(); private SummaryStatistics emptyStats = SummaryStatistics.newInstance();
private SummaryStatistics nullStats = null; SummaryStatistics tooShortStats = null;
SummaryStatistics tooShortStats = null;
public TTestTest(String name) { public TTestTest(String name) {
super(name); super(name);
@ -74,14 +72,14 @@ public class TTestTest extends TestCase {
testStatistic.tTest(mu, sampleStats), 10E-10); testStatistic.tTest(mu, sampleStats), 10E-10);
try { try {
testStatistic.t(mu, nullObserved); testStatistic.t(mu, (double[]) null);
fail("arguments too short, IllegalArgumentException expected"); fail("arguments too short, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
testStatistic.t(mu, nullStats); testStatistic.t(mu, (SummaryStatistics) null);
fail("arguments too short, IllegalArgumentException expected"); fail("arguments too short, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -289,7 +287,6 @@ public class TTestTest extends TestCase {
double[] sample1 = {1d, 3d, 5d, 7d}; double[] sample1 = {1d, 3d, 5d, 7d};
double[] sample2 = {0d, 6d, 11d, 2d}; double[] sample2 = {0d, 6d, 11d, 2d};
double[] sample3 = {5d, 7d, 8d, 10d}; double[] sample3 = {5d, 7d, 8d, 10d};
double[] sample4 = {0d, 2d};
// Target values computed using R, version 1.8.1 (linux version) // Target values computed using R, version 1.8.1 (linux version)
assertEquals(-0.3133, testStatistic.pairedT(sample1, sample2), 1E-4); assertEquals(-0.3133, testStatistic.pairedT(sample1, sample2), 1E-4);

View File

@ -193,11 +193,8 @@ public class TestUtilsTest extends TestCase {
} }
private double[] tooShortObs = { 1.0 }; private double[] tooShortObs = { 1.0 };
private double[] nullObserved = null;
private double[] emptyObs = {}; private double[] emptyObs = {};
private SummaryStatistics emptyStats = SummaryStatistics.newInstance(); private SummaryStatistics emptyStats = SummaryStatistics.newInstance();
private SummaryStatistics nullStats = null;
SummaryStatistics tooShortStats = null;
public void testOneSampleT() throws Exception { public void testOneSampleT() throws Exception {
double[] observed = double[] observed =
@ -220,14 +217,14 @@ public class TestUtilsTest extends TestCase {
TestUtils.tTest(mu, sampleStats), 10E-10); TestUtils.tTest(mu, sampleStats), 10E-10);
try { try {
TestUtils.t(mu, nullObserved); TestUtils.t(mu, (double[]) null);
fail("arguments too short, IllegalArgumentException expected"); fail("arguments too short, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
TestUtils.t(mu, nullStats); TestUtils.t(mu, (SummaryStatistics) null);
fail("arguments too short, IllegalArgumentException expected"); fail("arguments too short, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -261,13 +258,13 @@ public class TestUtilsTest extends TestCase {
} }
try { try {
TestUtils.t(mu, tooShortStats); TestUtils.t(mu, (SummaryStatistics) null);
fail("insufficient data to compute t statistic, IllegalArgumentException expected"); fail("insufficient data to compute t statistic, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// exptected // exptected
} }
try { try {
TestUtils.tTest(mu, tooShortStats); TestUtils.tTest(mu, (SummaryStatistics) null);
fail("insufficient data to perform t test, IllegalArgumentException expected"); fail("insufficient data to perform t test, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// exptected // exptected
@ -363,7 +360,7 @@ public class TestUtilsTest extends TestCase {
} }
try { try {
TestUtils.tTest(sampleStats1, tooShortStats, .01); TestUtils.tTest(sampleStats1, (SummaryStatistics) null, .01);
fail("insufficient data, IllegalArgumentException expected"); fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -377,7 +374,7 @@ public class TestUtilsTest extends TestCase {
} }
try { try {
TestUtils.tTest(sampleStats1, tooShortStats); TestUtils.tTest(sampleStats1, (SummaryStatistics) null);
fail("insufficient data, IllegalArgumentException expected"); fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -391,7 +388,7 @@ public class TestUtilsTest extends TestCase {
} }
try { try {
TestUtils.t(sampleStats1, tooShortStats); TestUtils.t(sampleStats1, (SummaryStatistics) null);
fail("insufficient data, IllegalArgumentException expected"); fail("insufficient data, IllegalArgumentException expected");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
// expected // expected
@ -435,7 +432,6 @@ public class TestUtilsTest extends TestCase {
double[] sample1 = {1d, 3d, 5d, 7d}; double[] sample1 = {1d, 3d, 5d, 7d};
double[] sample2 = {0d, 6d, 11d, 2d}; double[] sample2 = {0d, 6d, 11d, 2d};
double[] sample3 = {5d, 7d, 8d, 10d}; double[] sample3 = {5d, 7d, 8d, 10d};
double[] sample4 = {0d, 2d};
// Target values computed using R, version 1.8.1 (linux version) // Target values computed using R, version 1.8.1 (linux version)
assertEquals(-0.3133, TestUtils.pairedT(sample1, sample2), 1E-4); assertEquals(-0.3133, TestUtils.pairedT(sample1, sample2), 1E-4);

View File

@ -222,7 +222,7 @@ public final class SimpleRegressionTest extends TestCase {
regression.getSlopeConfidenceInterval() < regression.getSlopeConfidenceInterval(0.01)); regression.getSlopeConfidenceInterval() < regression.getSlopeConfidenceInterval(0.01));
try { try {
double x = regression.getSlopeConfidenceInterval(1); regression.getSlopeConfidenceInterval(1);
fail("expecting IllegalArgumentException for alpha = 1"); fail("expecting IllegalArgumentException for alpha = 1");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;

View File

@ -46,11 +46,11 @@ public final class MathUtilsTest extends TestCase {
int bigNeg = Integer.MIN_VALUE; int bigNeg = Integer.MIN_VALUE;
assertEquals(big, MathUtils.addAndCheck(big, 0)); assertEquals(big, MathUtils.addAndCheck(big, 0));
try { try {
int res = MathUtils.addAndCheck(big, 1); MathUtils.addAndCheck(big, 1);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
try { try {
int res = MathUtils.addAndCheck(bigNeg, -1); MathUtils.addAndCheck(bigNeg, -1);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
} }
@ -60,11 +60,11 @@ public final class MathUtilsTest extends TestCase {
int bigNeg = Integer.MIN_VALUE; int bigNeg = Integer.MIN_VALUE;
assertEquals(big, MathUtils.mulAndCheck(big, 1)); assertEquals(big, MathUtils.mulAndCheck(big, 1));
try { try {
int res = MathUtils.mulAndCheck(big, 2); MathUtils.mulAndCheck(big, 2);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
try { try {
int res = MathUtils.mulAndCheck(bigNeg, 2); MathUtils.mulAndCheck(bigNeg, 2);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
} }
@ -74,20 +74,19 @@ public final class MathUtilsTest extends TestCase {
int bigNeg = Integer.MIN_VALUE; int bigNeg = Integer.MIN_VALUE;
assertEquals(big, MathUtils.subAndCheck(big, 0)); assertEquals(big, MathUtils.subAndCheck(big, 0));
try { try {
int res = MathUtils.subAndCheck(big, -1); MathUtils.subAndCheck(big, -1);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
try { try {
int res = MathUtils.subAndCheck(bigNeg, 1); MathUtils.subAndCheck(bigNeg, 1);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) {} } catch (ArithmeticException ex) {}
} }
public void testSubAndCheckErrorMessage() { public void testSubAndCheckErrorMessage() {
int big = Integer.MAX_VALUE; int big = Integer.MAX_VALUE;
int bigNeg = Integer.MIN_VALUE;
try { try {
int res = MathUtils.subAndCheck(big, -1); MathUtils.subAndCheck(big, -1);
fail("Expecting ArithmeticException"); fail("Expecting ArithmeticException");
} catch (ArithmeticException ex) { } catch (ArithmeticException ex) {
assertEquals("overflow: subtract", ex.getMessage()); assertEquals("overflow: subtract", ex.getMessage());
@ -136,27 +135,27 @@ public final class MathUtilsTest extends TestCase {
public void testBinomialCoefficientFail() { public void testBinomialCoefficientFail() {
try { try {
long x = MathUtils.binomialCoefficient(4,5); MathUtils.binomialCoefficient(4,5);
fail ("expecting IllegalArgumentException"); fail ("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = MathUtils.binomialCoefficientDouble(4,5); MathUtils.binomialCoefficientDouble(4,5);
fail ("expecting IllegalArgumentException"); fail ("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = MathUtils.binomialCoefficientLog(4,5); MathUtils.binomialCoefficientLog(4,5);
fail ("expecting IllegalArgumentException"); fail ("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
long x = MathUtils.binomialCoefficient(67,34); MathUtils.binomialCoefficient(67,34);
fail ("expecting ArithmeticException"); fail ("expecting ArithmeticException");
} catch (ArithmeticException ex) { } catch (ArithmeticException ex) {
; ;
@ -181,25 +180,25 @@ public final class MathUtilsTest extends TestCase {
public void testFactorialFail() { public void testFactorialFail() {
try { try {
long x = MathUtils.factorial(-1); MathUtils.factorial(-1);
fail ("expecting IllegalArgumentException"); fail ("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = MathUtils.factorialDouble(-1); MathUtils.factorialDouble(-1);
fail ("expecting IllegalArgumentException"); fail ("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = MathUtils.factorialLog(-1); MathUtils.factorialLog(-1);
fail ("expecting IllegalArgumentException"); fail ("expecting IllegalArgumentException");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
; ;
} }
try { try {
double x = MathUtils.factorial(21); MathUtils.factorial(21);
fail ("expecting ArithmeticException"); fail ("expecting ArithmeticException");
} catch (ArithmeticException ex) { } catch (ArithmeticException ex) {
; ;
@ -241,7 +240,7 @@ public final class MathUtilsTest extends TestCase {
int test = 10; int test = 10;
while (!foundLimit) { while (!foundLimit) {
try { try {
double x = MathUtils.binomialCoefficient(test, test / 2); MathUtils.binomialCoefficient(test, test / 2);
} catch (ArithmeticException ex) { } catch (ArithmeticException ex) {
foundLimit = true; foundLimit = true;
System.out.println System.out.println
@ -284,7 +283,7 @@ public final class MathUtilsTest extends TestCase {
int test = 10; int test = 10;
while (!foundLimit) { while (!foundLimit) {
try { try {
double x = MathUtils.factorial(test); MathUtils.factorial(test);
} catch (ArithmeticException ex) { } catch (ArithmeticException ex) {
foundLimit = true; foundLimit = true;
System.out.println System.out.println

View File

@ -25,8 +25,6 @@ public class TestBean {
private String y = "1.0"; private String y = "1.0";
private Double z = new Double(2.0);
/** /**
* *
*/ */
@ -66,7 +64,6 @@ public class TestBean {
* *
*/ */
public void setZ(Double double1) { public void setZ(Double double1) {
z = double1;
} }
} }

View File

@ -40,11 +40,14 @@ Commons Math Release Notes</title>
</properties> </properties>
<body> <body>
<release version="1.2-SNAPSHOT" date="TBD"> <release version="1.2-SNAPSHOT" date="TBD">
<action dev="luc" type="fix">
Fixed numerous warnings in test code.
</action>
<action dev="luc" type="fix" issue="MATH-156" due-to="Tyler Ward"> <action dev="luc" type="fix" issue="MATH-156" due-to="Tyler Ward">
Use the initial guess provided by the user in BrentSolver.solve(), thus Use the initial guess provided by the user in BrentSolver.solve(), thus
improving speed. improving speed.
</action> </action>
<action dev="luc" type="update"> <action dev="luc" type="add">
Added the estimation optimization, geometry and ode package from the Added the estimation optimization, geometry and ode package from the
Mantissa library. Mantissa library.
</action> </action>