tobrien     2004/05/23 14:34:19

  Modified:    math/src/test/org/apache/commons/math/distribution
                        GammaDistributionTest.java
                        ExponentialDistributionTest.java
                        ChiSquareDistributionTest.java
                        FDistributionTest.java
               math/src/test/org/apache/commons/math/util
                        BeanTransformerTest.java
                        DefaultTransformerTest.java
  Log:
  Addressed exception "swallowing" in test coverage.  From Phil's recent

  email: "If the test case throws an unexpected exception, the test 

  should fail.  ....[fix] these by changing the test method signature to 

  throws Exception.  This also eliminates the need to import 

  MathException everywhere."

  
  Revision  Changes    Path
  1.16      +13 -31    
jakarta-commons/math/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java
  
  Index: GammaDistributionTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- GammaDistributionTest.java        23 May 2004 00:33:40 -0000      1.15
  +++ GammaDistributionTest.java        23 May 2004 21:34:19 -0000      1.16
  @@ -16,15 +16,13 @@
   
   package org.apache.commons.math.distribution;
   
  -import org.apache.commons.math.MathException;
  -
   import junit.framework.TestCase;
   
   /**
    * @version $Revision$ $Date$
    */
   public class GammaDistributionTest extends TestCase {
  -    public void testProbabilities() {
  +    public void testProbabilities() throws Exception {
           testProbability(-1.000, 4.0, 2.0, .0000);
           testProbability(15.501, 4.0, 2.0, .9499);
           testProbability(0.504, 4.0, 1.0, .0018);
  @@ -32,40 +30,24 @@
           testProbability(5.000, 2.0, 2.0, .7127);
       }
   
  -    public void testValues() {
  +    public void testValues() throws Exception {
           testValue(15.501, 4.0, 2.0, .9499);
           testValue(0.504, 4.0, 1.0, .0018);
           testValue(10.011, 1.0, 2.0, .9933);
           testValue(5.000, 2.0, 2.0, .7127);
       }
   
  -    private void testProbability(
  -        double x,
  -        double a,
  -        double b,
  -        double expected) {
  -        try {
  -            double actual =
  -                DistributionFactory
  -                    .newInstance()
  -                    .createGammaDistribution(a, b)
  -                    .cumulativeProbability(x);
  -            assertEquals("probability for " + x, expected, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  +    private void testProbability(double x, double a, double b, double expected) 
throws Exception {
  +        DistributionFactory factory = DistributionFactory.newInstance();
  +             GammaDistribution distribution = factory.createGammaDistribution( a, b 
);
  +        double actual = distribution.cumulativeProbability(x);
  +        assertEquals("probability for " + x, expected, actual, 10e-4);
       }
   
  -    private void testValue(double expected, double a, double b, double p) {
  -        try {
  -            double actual =
  -                DistributionFactory
  -                    .newInstance()
  -                    .createGammaDistribution(a, b)
  -                    .inverseCumulativeProbability(p);
  -            assertEquals("critical value for " + p, expected, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  +    private void testValue(double expected, double a, double b, double p) throws 
Exception {
  +             DistributionFactory factory = DistributionFactory.newInstance();
  +             GammaDistribution distribution = factory.createGammaDistribution( a, b 
);
  +        double actual = distribution.inverseCumulativeProbability(p);
  +        assertEquals("critical value for " + p, expected, actual, 10e-4);
       }
   }
  
  
  
  1.14      +37 -51    
jakarta-commons/math/src/test/org/apache/commons/math/distribution/ExponentialDistributionTest.java
  
  Index: ExponentialDistributionTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/ExponentialDistributionTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ExponentialDistributionTest.java  23 May 2004 00:33:40 -0000      1.13
  +++ ExponentialDistributionTest.java  23 May 2004 21:34:19 -0000      1.14
  @@ -15,7 +15,6 @@
    */
   package org.apache.commons.math.distribution;
   
  -import org.apache.commons.math.MathException;
   import org.apache.commons.math.TestUtils;
   
   import junit.framework.TestCase;
  @@ -52,135 +51,122 @@
           super.tearDown();
       }
   
  -    public void testInverseCumulativeProbability001() {
  +    public void testInverseCumulativeProbability001() throws Exception {
           testValue(.005003, .001);
       }
   
  -    public void testInverseCumulativeProbability010() {
  +    public void testInverseCumulativeProbability010() throws Exception {
           testValue(0.050252, .010);
       }
   
  -    public void testInverseCumulativeProbability025() {
  +    public void testInverseCumulativeProbability025() throws Exception {
           testValue(0.126589, .025);
       }
   
  -    public void testInverseCumulativeProbability050() {
  +    public void testInverseCumulativeProbability050() throws Exception {
           testValue(0.256566, .050);
       }
   
  -    public void testInverseCumulativeProbability100() {
  +    public void testInverseCumulativeProbability100() throws Exception {
           testValue(0.526803, .100);
       }
   
  -    public void testInverseCumulativeProbability999() {
  +    public void testInverseCumulativeProbability999() throws Exception {
           testValue(34.5388, .999);
       }
   
  -    public void testInverseCumulativeProbability990() {
  +    public void testInverseCumulativeProbability990() throws Exception {
           testValue(23.0259, .990);
       }
   
  -    public void testInverseCumulativeProbability975() {
  +    public void testInverseCumulativeProbability975() throws Exception {
           testValue(18.4444, .975);
       }
   
  -    public void testInverseCumulativeProbability950() {
  +    public void testInverseCumulativeProbability950() throws Exception {
           testValue(14.9787, .950);
       }
   
  -    public void testInverseCumulativeProbability900() {
  +    public void testInverseCumulativeProbability900() throws Exception {
           testValue(11.5129, .900);
       }
   
  -    public void testCumulativeProbability001() {
  +    public void testCumulativeProbability001() throws Exception {
           testProbability(0.005003, .001);
       }
   
  -    public void testCumulativeProbability010() {
  +    public void testCumulativeProbability010() throws Exception {
           testProbability(0.050252, .010);
       }
   
  -    public void testCumulativeProbability025() {
  +    public void testCumulativeProbability025() throws Exception {
           testProbability(0.126589, .025);
       }
   
  -    public void testCumulativeProbability050() {
  +    public void testCumulativeProbability050() throws Exception {
           testProbability(0.256566, .050);
       }
   
  -    public void testCumulativeProbability100() {
  +    public void testCumulativeProbability100() throws Exception {
           testProbability(0.526803, .100);
       }
   
  -    public void testCumulativeProbability999() {
  +    public void testCumulativeProbability999() throws Exception {
           testProbability(34.5388, .999);
       }
   
  -    public void testCumulativeProbability990() {
  +    public void testCumulativeProbability990() throws Exception {
           testProbability(23.0259, .990);
       }
   
  -    public void testCumulativeProbability975() {
  +    public void testCumulativeProbability975() throws Exception {
           testProbability(18.4444, .975);
       }
   
  -    public void testCumulativeProbability950() {
  +    public void testCumulativeProbability950() throws Exception {
           testProbability(14.9787, .950);
       }
   
  -    public void testCumulativeProbability900() {
  +    public void testCumulativeProbability900() throws Exception {
           testProbability(11.5129, .900);
       }
   
  -    public void testCumulativeProbabilityNegative() {
  +    public void testCumulativeProbabilityNegative() throws Exception {
           testProbability(-1.0, 0.0);
       }
   
  -    public void testCumulativeProbabilityZero() {
  +    public void testCumulativeProbabilityZero() throws Exception {
           testProbability(0.0, 0.0);
       }
   
  -    public void testInverseCumulativeProbabilityNegative() {
  +    public void testInverseCumulativeProbabilityNegative() throws Exception {
           testValue(Double.NaN, -1.0);
       }
   
  -    public void testInverseCumulativeProbabilityZero() {
  +    public void testInverseCumulativeProbabilityZero() throws Exception {
           testValue(0.0, 0.0);
       }
   
  -    public void testInverseCumulativeProbabilityOne() {
  +    public void testInverseCumulativeProbabilityOne() throws Exception {
           testValue(Double.POSITIVE_INFINITY, 1.0);
       }
   
  -    public void testInverseCumulativeProbabilityPositive() {
  +    public void testInverseCumulativeProbabilityPositive() throws Exception {
           testValue(Double.NaN, 2.0);
       }
   
  -    public void testCumulativeProbability2() {
  -        try {
  -            double actual = exp.cumulativeProbability(0.25, 0.75);
  -            assertEquals(0.0905214, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  +    public void testCumulativeProbability2() throws Exception {
  +        double actual = exp.cumulativeProbability(0.25, 0.75);
  +        assertEquals(0.0905214, actual, 10e-4);
  +    }
   
  +    private void testProbability(double x, double expected) throws Exception {
  +        double actual = exp.cumulativeProbability(x);
  +        TestUtils.assertEquals(expected, actual, 10e-4);
       }
   
  -    private void testProbability(double x, double expected) {
  -        try {
  -            double actual = exp.cumulativeProbability(x);
  -            TestUtils.assertEquals(expected, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  -    }
  -
  -    private void testValue(double expected, double p) {
  -        try {
  -            double actual = exp.inverseCumulativeProbability(p);
  -            TestUtils.assertEquals(expected, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  +    private void testValue(double expected, double p) throws Exception {
  +        double actual = exp.inverseCumulativeProbability(p);
  +        TestUtils.assertEquals(expected, actual, 10e-4);
       }
   }
  
  
  
  1.14      +11 -23    
jakarta-commons/math/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
  
  Index: ChiSquareDistributionTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ChiSquareDistributionTest.java    21 Feb 2004 21:35:17 -0000      1.13
  +++ ChiSquareDistributionTest.java    23 May 2004 21:34:19 -0000      1.14
  @@ -16,8 +16,6 @@
   
   package org.apache.commons.math.distribution;
   
  -import org.apache.commons.math.MathException;
  -
   import junit.framework.TestCase;
   
   /**
  @@ -50,7 +48,7 @@
                super.tearDown();
        }
   
  -    public void testLowerTailProbability(){
  +    public void testLowerTailProbability() throws Exception {
           testProbability( .210, .001);
           testProbability( .554, .010);
           testProbability( .831, .025);
  @@ -58,7 +56,7 @@
           testProbability(1.610, .100);
       }
   
  -    public void testUpperTailProbability(){
  +    public void testUpperTailProbability() throws Exception {
           testProbability(20.515, .999);
           testProbability(15.086, .990);
           testProbability(12.833, .975);
  @@ -66,7 +64,7 @@
           testProbability( 9.236, .900);
       }
       
  -    public void testLowerTailValues(){
  +    public void testLowerTailValues() throws Exception {
           testValue(.001,  .210);
           testValue(.010,  .554);
           testValue(.025,  .831);
  @@ -74,7 +72,7 @@
           testValue(.100, 1.610);
       }
       
  -    public void testUpperTailValues(){
  +    public void testUpperTailValues() throws Exception {
           testValue(.999, 20.515);
           testValue(.990, 15.086);
           testValue(.975, 12.833);
  @@ -82,23 +80,13 @@
           testValue(.900,  9.236);
       }
       
  -    private void testProbability(double x, double expected){
  -        try {
  -            double actual = chiSquare.cumulativeProbability(x);
  -            assertEquals("probability for " + x, expected, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  -        
  +    private void testProbability(double x, double expected) throws Exception {
  +        double actual = chiSquare.cumulativeProbability(x);
  +        assertEquals("probability for " + x, expected, actual, 10e-4);
       }
       
  -    private void testValue(double p, double expected){
  -        try {
  -            double actual = chiSquare.inverseCumulativeProbability(p);
  -            assertEquals("value for " + p, expected, actual, 10e-4);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  -        
  +    private void testValue(double p, double expected) throws Exception {
  +        double actual = chiSquare.inverseCumulativeProbability(p);
  +        assertEquals("value for " + p, expected, actual, 10e-4);
       }
   }
  
  
  
  1.13      +13 -23    
jakarta-commons/math/src/test/org/apache/commons/math/distribution/FDistributionTest.java
  
  Index: FDistributionTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/FDistributionTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FDistributionTest.java    23 May 2004 00:33:40 -0000      1.12
  +++ FDistributionTest.java    23 May 2004 21:34:19 -0000      1.13
  @@ -15,8 +15,6 @@
    */
   package org.apache.commons.math.distribution;
   
  -import org.apache.commons.math.MathException;
  -
   import junit.framework.TestCase;
   
   /**
  @@ -49,49 +47,41 @@
           super.tearDown();
       }
   
  -    public void testLowerTailProbability() {
  +    public void testLowerTailProbability() throws Exception {
           testProbability(1.0 / 10.67, .010);
           testProbability(1.0 / 6.98, .025);
           testProbability(1.0 / 4.95, .050);
           testProbability(1.0 / 3.40, .100);
       }
   
  -    public void testUpperTailProbability() {
  +    public void testUpperTailProbability() throws Exception {
           testProbability(8.75, .990);
           testProbability(5.99, .975);
           testProbability(4.39, .950);
           testProbability(3.11, .900);
       }
   
  -    public void testLowerTailValues() {
  +    public void testLowerTailValues() throws Exception {
           testValue(1.0 / 10.67, .010);
           testValue(1.0 / 6.98, .025);
           testValue(1.0 / 4.95, .050);
           testValue(1.0 / 3.40, .100);
       }
   
  -    public void testUpperTailValues() {
  +    public void testUpperTailValues() throws Exception {
           testValue(8.75, .990);
           testValue(5.99, .975);
           testValue(4.39, .950);
           testValue(3.11, .900);
       }
   
  -    private void testProbability(double x, double expected) {
  -        try {
  -            double actual = f.cumulativeProbability(x);
  -            assertEquals("probability for " + x, expected, actual, 1e-3);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  -    }
  -
  -    private void testValue(double expected, double p) {
  -        try {
  -            double actual = f.inverseCumulativeProbability(p);
  -            assertEquals("value for " + p, expected, actual, 1e-2);
  -        } catch (MathException e) {
  -            e.printStackTrace();
  -        }
  +    private void testProbability(double x, double expected) throws Exception {
  +             double actual = f.cumulativeProbability(x);
  +        assertEquals("probability for " + x, expected, actual, 1e-3);
  +    }
  +
  +    private void testValue(double expected, double p) throws Exception {
  +        double actual = f.inverseCumulativeProbability(p);
  +        assertEquals("value for " + p, expected, actual, 1e-2);
       }
   }
  
  
  
  1.11      +5 -13     
jakarta-commons/math/src/test/org/apache/commons/math/util/BeanTransformerTest.java
  
  Index: BeanTransformerTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/util/BeanTransformerTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BeanTransformerTest.java  23 May 2004 00:33:41 -0000      1.10
  +++ BeanTransformerTest.java  23 May 2004 21:34:19 -0000      1.11
  @@ -70,30 +70,22 @@
       /**
        * 
        */
  -    public void testTransform() {
  +    public void testTransform() throws Exception {
           BeanTransformer b = new BeanTransformer("x");
           TestBean target = new TestBean();
                double value = Double.NaN;
  -             try {
  -                     value = b.transform(target);
  -             } catch (MathException e) {
  -                     e.printStackTrace();
  -             }
  +             value = b.transform(target);
                TestUtils.assertEquals(1.0, value, 1.0e-2);
       }
       
       /**
        * 
        */
  -    public void testTransformInvalidType(){
  +    public void testTransformInvalidType() throws Exception {
           BeanTransformer b = new BeanTransformer("y");
           TestBean target = new TestBean();
           try {
  -            try {
  -                             b.transform(target);
  -                     } catch (MathException e) {
  -                             e.printStackTrace();
  -                     }
  +                     b.transform(target);
               fail("Expecting ClassCastException");
           } catch(ClassCastException ex){
               // success
  
  
  
  1.12      +9 -25     
jakarta-commons/math/src/test/org/apache/commons/math/util/DefaultTransformerTest.java
  
  Index: DefaultTransformerTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/util/DefaultTransformerTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultTransformerTest.java       23 May 2004 00:33:41 -0000      1.11
  +++ DefaultTransformerTest.java       23 May 2004 21:34:19 -0000      1.12
  @@ -28,15 +28,11 @@
       /**
        * 
        */
  -    public void testTransformDouble(){
  +    public void testTransformDouble() throws Exception {
           double expected = 1.0;
           Double input = new Double(expected);
           DefaultTransformer t = new DefaultTransformer();
  -        try {
  -                     assertEquals(expected, t.transform(input), 1.0e-4);
  -             } catch (MathException e) {
  -                     e.printStackTrace();
  -             }
  +             assertEquals(expected, t.transform(input), 1.0e-4);
       }
       
       /**
  @@ -55,43 +51,31 @@
       /**
        * 
        */
  -    public void testTransformInteger(){
  +    public void testTransformInteger() throws Exception {
           double expected = 1.0;
           Integer input = new Integer(1);
           DefaultTransformer t = new DefaultTransformer();
  -        try {
  -                     assertEquals(expected, t.transform(input), 1.0e-4);
  -             } catch (MathException e) {
  -                     e.printStackTrace();
  -             }
  +             assertEquals(expected, t.transform(input), 1.0e-4);
       }        
       
       /**
        * 
        */
  -    public void testTransformBigDecimal(){
  +    public void testTransformBigDecimal() throws Exception {
           double expected = 1.0;
           BigDecimal input = new BigDecimal("1.0");
           DefaultTransformer t = new DefaultTransformer();
  -        try {
  -                     assertEquals(expected, t.transform(input), 1.0e-4);
  -             } catch (MathException e) {
  -                     e.printStackTrace();
  -             }
  +             assertEquals(expected, t.transform(input), 1.0e-4);
       }        
       
       /**
        * 
        */
  -    public void testTransformString(){
  +    public void testTransformString() throws Exception {
           double expected = 1.0;
           String input = "1.0";
           DefaultTransformer t = new DefaultTransformer();
  -        try {
  -                     assertEquals(expected, t.transform(input), 1.0e-4);
  -             } catch (MathException e) {
  -                     e.printStackTrace();
  -             }
  +             assertEquals(expected, t.transform(input), 1.0e-4);
       }
       
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to