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 c15e0ecc7..390080ffe 100644 --- a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java +++ b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java @@ -38,7 +38,7 @@ public class BigFractionTest extends TestCase { assertEquals(expectedDenominator, actual.getDenominatorAsLong()); } - public void testConstructor() { + public void testConstructor() throws Exception { assertFraction(0, 1, new BigFraction(0, 1)); assertFraction(0, 1, new BigFraction(0l, 2l)); assertFraction(0, 1, new BigFraction(0, -1)); @@ -52,13 +52,10 @@ public class BigFractionTest extends TestCase { assertFraction(11, 1, new BigFraction(11l)); assertFraction(11, 1, new BigFraction(new BigInteger("11"))); - try { - assertFraction(0, 1, new BigFraction(0.00000000000001, 1.0e-5, 100)); - assertFraction(2, 5, new BigFraction(0.40000000000001, 1.0e-5, 100)); - assertFraction(15, 1, new BigFraction(15.0000000000001, 1.0e-5, 100)); - } catch (ConvergenceException ex) { - fail(ex.getMessage()); - } + assertFraction(0, 1, new BigFraction(0.00000000000001, 1.0e-5, 100)); + assertFraction(2, 5, new BigFraction(0.40000000000001, 1.0e-5, 100)); + assertFraction(15, 1, new BigFraction(15.0000000000001, 1.0e-5, 100)); + assertEquals(0.00000000000001, new BigFraction(0.00000000000001).doubleValue(), 0.0); assertEquals(0.40000000000001, new BigFraction(0.40000000000001).doubleValue(), 0.0); assertEquals(15.0000000000001, new BigFraction(15.0000000000001).doubleValue(), 0.0); diff --git a/src/test/java/org/apache/commons/math/fraction/FractionTest.java b/src/test/java/org/apache/commons/math/fraction/FractionTest.java index fc690171d..aec875331 100644 --- a/src/test/java/org/apache/commons/math/fraction/FractionTest.java +++ b/src/test/java/org/apache/commons/math/fraction/FractionTest.java @@ -34,7 +34,7 @@ public class FractionTest extends TestCase { assertEquals(expectedDenominator, actual.getDenominator()); } - public void testConstructor() { + public void testConstructor() throws Exception { assertFraction(0, 1, new Fraction(0, 1)); assertFraction(0, 1, new Fraction(0, 2)); assertFraction(0, 1, new Fraction(0, -1)); @@ -58,14 +58,9 @@ public class FractionTest extends TestCase { } catch (MathArithmeticException ex) { // success } - try { - assertFraction(0, 1, new Fraction(0.00000000000001)); - assertFraction(2, 5, new Fraction(0.40000000000001)); - assertFraction(15, 1, new Fraction(15.0000000000001)); - - } catch (ConvergenceException ex) { - fail(ex.getMessage()); - } + assertFraction(0, 1, new Fraction(0.00000000000001)); + assertFraction(2, 5, new Fraction(0.40000000000001)); + assertFraction(15, 1, new Fraction(15.0000000000001)); } public void testGoldenRatio() { @@ -212,19 +207,15 @@ public class FractionTest extends TestCase { assertEquals(1L, second.longValue()); } - public void testConstructorDouble() { - try { - assertFraction(1, 2, new Fraction(0.5)); - assertFraction(1, 3, new Fraction(1.0 / 3.0)); - assertFraction(17, 100, new Fraction(17.0 / 100.0)); - assertFraction(317, 100, new Fraction(317.0 / 100.0)); - assertFraction(-1, 2, new Fraction(-0.5)); - assertFraction(-1, 3, new Fraction(-1.0 / 3.0)); - assertFraction(-17, 100, new Fraction(17.0 / -100.0)); - assertFraction(-317, 100, new Fraction(-317.0 / 100.0)); - } catch (ConvergenceException ex) { - fail(ex.getMessage()); - } + public void testConstructorDouble() throws Exception { + assertFraction(1, 2, new Fraction(0.5)); + assertFraction(1, 3, new Fraction(1.0 / 3.0)); + assertFraction(17, 100, new Fraction(17.0 / 100.0)); + assertFraction(317, 100, new Fraction(317.0 / 100.0)); + assertFraction(-1, 2, new Fraction(-0.5)); + assertFraction(-1, 3, new Fraction(-1.0 / 3.0)); + assertFraction(-17, 100, new Fraction(17.0 / -100.0)); + assertFraction(-317, 100, new Fraction(-317.0 / 100.0)); } public void testAbs() { diff --git a/src/test/java/org/apache/commons/math/geometry/Vector3DFormatAbstractTest.java b/src/test/java/org/apache/commons/math/geometry/Vector3DFormatAbstractTest.java index 5e75922fd..f4b4fa57b 100644 --- a/src/test/java/org/apache/commons/math/geometry/Vector3DFormatAbstractTest.java +++ b/src/test/java/org/apache/commons/math/geometry/Vector3DFormatAbstractTest.java @@ -163,12 +163,8 @@ public abstract class Vector3DFormatAbstractTest { public void testParseSimpleNoDecimals() { String source = "{1; 1; 1}"; Vector3D expected = new Vector3D(1, 1, 1); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -192,12 +188,8 @@ public abstract class Vector3DFormatAbstractTest { "43; 1" + getDecimalCharacter() + "63}"; Vector3D expected = new Vector3D(1.23, 1.43, 1.63); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -208,12 +200,8 @@ public abstract class Vector3DFormatAbstractTest { "4343; 1" + getDecimalCharacter() + "6333}"; Vector3D expected = new Vector3D(1.2323, 1.4343, 1.6333); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -224,12 +212,8 @@ public abstract class Vector3DFormatAbstractTest { "4343; 1" + getDecimalCharacter() + "6333}"; Vector3D expected = new Vector3D(-1.2323, 1.4343, 1.6333); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -240,12 +224,8 @@ public abstract class Vector3DFormatAbstractTest { "4343; 1" + getDecimalCharacter() + "6333}"; Vector3D expected = new Vector3D(1.2323, -1.4343, 1.6333); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -256,12 +236,8 @@ public abstract class Vector3DFormatAbstractTest { "4343; -1" + getDecimalCharacter() + "6333}"; Vector3D expected = new Vector3D(1.2323, 1.4343, -1.6333); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -272,12 +248,8 @@ public abstract class Vector3DFormatAbstractTest { "4343; -1" + getDecimalCharacter() + "6333}"; Vector3D expected = new Vector3D(-1.2323, -1.4343, -1.6333); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -288,12 +260,8 @@ public abstract class Vector3DFormatAbstractTest { "4343; 1" + getDecimalCharacter() + "6333}"; Vector3D expected = new Vector3D(0.0, -1.4343, 1.6333); - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test @@ -304,45 +272,29 @@ public abstract class Vector3DFormatAbstractTest { "4343 : 1" + getDecimalCharacter() + "6333]"; Vector3D expected = new Vector3D(1.2323, 1.4343, 1.6333); - try { - Vector3D actual = vector3DFormatSquare.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormatSquare.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseNan() { String source = "{(NaN); (NaN); (NaN)}"; - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(Vector3D.NaN, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(Vector3D.NaN, actual); } @Test public void testParsePositiveInfinity() { String source = "{(Infinity); (Infinity); (Infinity)}"; - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(Vector3D.POSITIVE_INFINITY, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(Vector3D.POSITIVE_INFINITY, actual); } @Test public void testParseNegativeInfinity() { String source = "{(-Infinity); (-Infinity); (-Infinity)}"; - try { - Vector3D actual = vector3DFormat.parse(source); - Assert.assertEquals(Vector3D.NEGATIVE_INFINITY, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Vector3D actual = vector3DFormat.parse(source); + Assert.assertEquals(Vector3D.NEGATIVE_INFINITY, actual); } @Test diff --git a/src/test/java/org/apache/commons/math/stat/FrequencyTest.java b/src/test/java/org/apache/commons/math/stat/FrequencyTest.java index 0fa1ff8e0..135bfaf27 100644 --- a/src/test/java/org/apache/commons/math/stat/FrequencyTest.java +++ b/src/test/java/org/apache/commons/math/stat/FrequencyTest.java @@ -197,7 +197,7 @@ public final class FrequencyTest extends TestCase { /** * Tests toString() */ - public void testToString(){ + public void testToString() throws Exception { f.addValue(oneL); f.addValue(twoL); f.addValue(oneI); @@ -207,21 +207,17 @@ public final class FrequencyTest extends TestCase { //System.out.println(s); assertNotNull(s); BufferedReader reader = new BufferedReader(new StringReader(s)); - try { - String line = reader.readLine(); // header line - assertNotNull(line); + String line = reader.readLine(); // header line + assertNotNull(line); - line = reader.readLine(); // one's or two's line - assertNotNull(line); + line = reader.readLine(); // one's or two's line + assertNotNull(line); - line = reader.readLine(); // one's or two's line - assertNotNull(line); + line = reader.readLine(); // one's or two's line + assertNotNull(line); - line = reader.readLine(); // no more elements - assertNull(line); - } catch(IOException ex){ - fail(ex.getMessage()); - } + line = reader.readLine(); // no more elements + assertNull(line); } public void testIntegerValues() { diff --git a/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java b/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java index 3c5006cc5..e7b8ef004 100644 --- a/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java +++ b/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java @@ -32,7 +32,7 @@ public class ContinuedFractionTest extends TestCase { super(name); } - public void testGoldenRatio(){ + public void testGoldenRatio() throws Exception { ContinuedFraction cf = new ContinuedFraction() { @Override @@ -46,11 +46,7 @@ public class ContinuedFractionTest extends TestCase { } }; - try { - double gr = cf.evaluate(0.0, 10e-9); - assertEquals(1.61803399, gr, 10e-9); - } catch (MathException e) { - fail(e.getMessage()); - } + double gr = cf.evaluate(0.0, 10e-9); + assertEquals(1.61803399, gr, 10e-9); } }