From 76ab9055aa0345399fe17f39e7ee927797410e09 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sat, 2 Oct 2010 22:06:55 +0000 Subject: [PATCH] backported :r1003543,1003545,1003569,1003584 from trunk to branch 2.X Add missing fail() calls for expected exceptions git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1003899 13f79535-47bb-0310-9956-ffa450edef68 --- .../analysis/solvers/UnivariateRealSolverUtilsTest.java | 4 +++- .../org/apache/commons/math/fraction/BigFractionTest.java | 6 +++++- .../java/org/apache/commons/math/geometry/RotationTest.java | 3 +++ .../apache/commons/math/linear/LUDecompositionImplTest.java | 1 + .../org/apache/commons/math/linear/MatrixUtilsTest.java | 3 +++ .../commons/math/linear/RealVectorFormatAbstractTest.java | 1 + .../apache/commons/math/ode/ContinuousOutputModelTest.java | 5 ++--- .../stat/descriptive/MultivariateSummaryStatisticsTest.java | 1 + 8 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java b/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java index c6d8bc2db..33b0484b0 100644 --- a/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java +++ b/src/test/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtilsTest.java @@ -42,12 +42,14 @@ public class UnivariateRealSolverUtilsTest extends TestCase { public void testSolveBadParameters() throws MathException { try { // bad endpoints - UnivariateRealSolverUtils.solve(sin,0.0, 4.0, 4.0); + UnivariateRealSolverUtils.solve(sin, -0.1, 4.0, 4.0); + fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } try { // bad accuracy UnivariateRealSolverUtils.solve(sin, 0.0, 4.0, 0.0); +// fail("Expecting IllegalArgumentException"); // TODO needs rework since convergence behaviour was changed } catch (IllegalArgumentException ex) { // expected } diff --git a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java index 54d02afa1..5f23abc9b 100644 --- a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java +++ b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java @@ -66,21 +66,25 @@ public class BigFractionTest extends TestCase { assertFraction(1055531162664967l, 70368744177664l, new BigFraction(15.0000000000001)); try { new BigFraction(null, BigInteger.ONE); + fail("Expecting NullArgumentException"); } catch (NullArgumentException npe) { // expected } try { new BigFraction(BigInteger.ONE, null); + fail("Expecting NullArgumentException"); } catch (NullArgumentException npe) { // expected } try { new BigFraction(BigInteger.ONE, BigInteger.ZERO); + fail("Expecting ArithmeticException"); } catch (ArithmeticException npe) { // expected } try { new BigFraction(2.0 * Integer.MAX_VALUE, 1.0e-5, 100000); + fail("Expecting FractionConversionException"); } catch (FractionConversionException fce) { // expected } @@ -232,7 +236,7 @@ public class BigFractionTest extends TestCase { for (double v : new double[] { Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}) { try { new BigFraction(v); - fail("expected exception"); + fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException iae) { // expected } diff --git a/src/test/java/org/apache/commons/math/geometry/RotationTest.java b/src/test/java/org/apache/commons/math/geometry/RotationTest.java index 82e45176a..2496682ff 100644 --- a/src/test/java/org/apache/commons/math/geometry/RotationTest.java +++ b/src/test/java/org/apache/commons/math/geometry/RotationTest.java @@ -164,6 +164,7 @@ public class RotationTest { 0.0, 1.0, 0.0 }, { 1.0, 0.0, 0.0 } }, 1.0e-7); + fail("Expecting NotARotationMatrixException"); } catch (NotARotationMatrixException nrme) { // expected behavior } catch (Exception e) { @@ -176,6 +177,7 @@ public class RotationTest { 0.821760, -0.184320, 0.539200 }, { -0.354816, 0.574912, 0.737280 } }, 1.0e-7); + fail("Expecting NotARotationMatrixException"); } catch (NotARotationMatrixException nrme) { // expected behavior } catch (Exception e) { @@ -188,6 +190,7 @@ public class RotationTest { -0.4, 0.6, 0.7 }, { 0.8, -0.2, 0.5 } }, 1.0e-15); + fail("Expecting NotARotationMatrixException"); } catch (NotARotationMatrixException nrme) { // expected behavior } catch (Exception e) { diff --git a/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java b/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java index d240ac27c..70aed5367 100644 --- a/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java +++ b/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java @@ -73,6 +73,7 @@ public class LUDecompositionImplTest extends TestCase { public void testNonSquare() { try { new LUDecompositionImpl(MatrixUtils.createRealMatrix(new double[3][2])); + fail("Expecting InvalidMatrixException"); } catch (InvalidMatrixException ime) { // expected behavior } catch (Exception e) { diff --git a/src/test/java/org/apache/commons/math/linear/MatrixUtilsTest.java b/src/test/java/org/apache/commons/math/linear/MatrixUtilsTest.java index 431d34ef8..9bdda451a 100644 --- a/src/test/java/org/apache/commons/math/linear/MatrixUtilsTest.java +++ b/src/test/java/org/apache/commons/math/linear/MatrixUtilsTest.java @@ -285,6 +285,7 @@ public final class MatrixUtilsTest extends TestCase { checkIdentityMatrix(MatrixUtils.createRealIdentityMatrix(1)); try { MatrixUtils.createRealIdentityMatrix(0); + fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } @@ -311,6 +312,7 @@ public final class MatrixUtilsTest extends TestCase { checkIdentityFieldMatrix(MatrixUtils.createFieldIdentityMatrix(FractionField.getInstance(), 1)); try { MatrixUtils.createRealIdentityMatrix(0); + fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } @@ -392,6 +394,7 @@ public final class MatrixUtilsTest extends TestCase { checkIdentityBigMatrix(MatrixUtils.createBigIdentityMatrix(1)); try { MatrixUtils.createRealIdentityMatrix(0); + fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } diff --git a/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java b/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java index 77b1960dd..3922d62ea 100644 --- a/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java +++ b/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java @@ -333,6 +333,7 @@ public abstract class RealVectorFormatAbstractTest extends TestCase { public void testParseNoComponents() { try { realVectorFormat.parseObject("{ }"); + fail("Expecting ParseException"); } catch (ParseException pe) { // expected behavior } catch (Exception e) { diff --git a/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java b/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java index 0d8150031..8147d6644 100644 --- a/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java +++ b/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java @@ -160,10 +160,9 @@ public class ContinuousOutputModelTest otherCm.handleStep(buildInterpolator(t0, y0, t1), true); cm.append(otherCm); } catch(IllegalArgumentException iae) { - //expected behavior - return true; + return true; // there was an allowable error } - return false; + return false; // no allowable error } private StepInterpolator buildInterpolator(double t0, double[] y0, double t1) { diff --git a/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java b/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java index fb8a4a326..f5e2873a6 100644 --- a/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java +++ b/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java @@ -173,6 +173,7 @@ public class MultivariateSummaryStatisticsTest extends TestCase { public void testDimension() { try { createMultivariateSummaryStatistics(2, true).addValue(new double[3]); + fail("Expecting DimensionMismatchException"); } catch (DimensionMismatchException dme) { // expected behavior } catch (Exception e) {