From eb221effa33711ad69bc3266df8a90985369c1fe Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Wed, 2 Feb 2011 01:43:25 +0000 Subject: [PATCH] No point catching and then calling fail - just let JUnit do the work git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1066301 13f79535-47bb-0310-9956-ffa450edef68 --- .../complex/ComplexFormatAbstractTest.java | 97 +++++-------------- 1 file changed, 24 insertions(+), 73 deletions(-) diff --git a/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java b/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java index 0824c6a19..f68561e57 100644 --- a/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java +++ b/src/test/java/org/apache/commons/math/complex/ComplexFormatAbstractTest.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.junit.Assert; import org.apache.commons.math.util.FastMath; -import org.apache.commons.math.exception.MathParseException; public abstract class ComplexFormatAbstractTest { @@ -154,144 +153,96 @@ public abstract class ComplexFormatAbstractTest { public void testParseSimpleNoDecimals() { String source = "1 + 1i"; Complex expected = new Complex(1, 1); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseSimpleWithDecimals() { String source = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i"; Complex expected = new Complex(1.23, 1.43); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseSimpleWithDecimalsTrunc() { String source = "1" + getDecimalCharacter() + "2323 + 1" + getDecimalCharacter() + "4343i"; Complex expected = new Complex(1.2323, 1.4343); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseNegativeReal() { String source = "-1" + getDecimalCharacter() + "2323 + 1" + getDecimalCharacter() + "4343i"; Complex expected = new Complex(-1.2323, 1.4343); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseNegativeImaginary() { String source = "1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343i"; Complex expected = new Complex(1.2323, -1.4343); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseNegativeBoth() { String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343i"; Complex expected = new Complex(-1.2323, -1.4343); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseZeroReal() { String source = "0" + getDecimalCharacter() + "0 - 1" + getDecimalCharacter() + "4343i"; Complex expected = new Complex(0.0, -1.4343); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseZeroImaginary() { String source = "-1" + getDecimalCharacter() + "2323"; Complex expected = new Complex(-1.2323, 0); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseDifferentImaginaryChar() { String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343j"; Complex expected = new Complex(-1.2323, -1.4343); - try { - Complex actual = complexFormatJ.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormatJ.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParseNan() { String source = "(NaN) + (NaN)i"; Complex expected = new Complex(Double.NaN, Double.NaN); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testParsePositiveInfinity() { String source = "(Infinity) + (Infinity)i"; Complex expected = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test public void testPaseNegativeInfinity() { String source = "(-Infinity) - (Infinity)i"; Complex expected = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - try { - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } catch (MathParseException ex) { - Assert.fail(ex.getMessage()); - } + Complex actual = complexFormat.parse(source); + Assert.assertEquals(expected, actual); } @Test