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
This commit is contained in:
Sebastian Bazley 2011-02-02 01:43:25 +00:00
parent b8152e7e41
commit eb221effa3
1 changed files with 24 additions and 73 deletions

View File

@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.Assert; import org.junit.Assert;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.exception.MathParseException;
public abstract class ComplexFormatAbstractTest { public abstract class ComplexFormatAbstractTest {
@ -154,144 +153,96 @@ public abstract class ComplexFormatAbstractTest {
public void testParseSimpleNoDecimals() { public void testParseSimpleNoDecimals() {
String source = "1 + 1i"; String source = "1 + 1i";
Complex expected = new Complex(1, 1); Complex expected = new Complex(1, 1);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseSimpleWithDecimals() { public void testParseSimpleWithDecimals() {
String source = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i"; String source = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i";
Complex expected = new Complex(1.23, 1.43); Complex expected = new Complex(1.23, 1.43);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseSimpleWithDecimalsTrunc() { public void testParseSimpleWithDecimalsTrunc() {
String source = "1" + getDecimalCharacter() + "2323 + 1" + getDecimalCharacter() + "4343i"; String source = "1" + getDecimalCharacter() + "2323 + 1" + getDecimalCharacter() + "4343i";
Complex expected = new Complex(1.2323, 1.4343); Complex expected = new Complex(1.2323, 1.4343);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseNegativeReal() { public void testParseNegativeReal() {
String source = "-1" + getDecimalCharacter() + "2323 + 1" + getDecimalCharacter() + "4343i"; String source = "-1" + getDecimalCharacter() + "2323 + 1" + getDecimalCharacter() + "4343i";
Complex expected = new Complex(-1.2323, 1.4343); Complex expected = new Complex(-1.2323, 1.4343);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseNegativeImaginary() { public void testParseNegativeImaginary() {
String source = "1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343i"; String source = "1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343i";
Complex expected = new Complex(1.2323, -1.4343); Complex expected = new Complex(1.2323, -1.4343);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseNegativeBoth() { public void testParseNegativeBoth() {
String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343i"; String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343i";
Complex expected = new Complex(-1.2323, -1.4343); Complex expected = new Complex(-1.2323, -1.4343);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseZeroReal() { public void testParseZeroReal() {
String source = "0" + getDecimalCharacter() + "0 - 1" + getDecimalCharacter() + "4343i"; String source = "0" + getDecimalCharacter() + "0 - 1" + getDecimalCharacter() + "4343i";
Complex expected = new Complex(0.0, -1.4343); Complex expected = new Complex(0.0, -1.4343);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseZeroImaginary() { public void testParseZeroImaginary() {
String source = "-1" + getDecimalCharacter() + "2323"; String source = "-1" + getDecimalCharacter() + "2323";
Complex expected = new Complex(-1.2323, 0); Complex expected = new Complex(-1.2323, 0);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseDifferentImaginaryChar() { public void testParseDifferentImaginaryChar() {
String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343j"; String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343j";
Complex expected = new Complex(-1.2323, -1.4343); Complex expected = new Complex(-1.2323, -1.4343);
try { Complex actual = complexFormatJ.parse(source);
Complex actual = complexFormatJ.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParseNan() { public void testParseNan() {
String source = "(NaN) + (NaN)i"; String source = "(NaN) + (NaN)i";
Complex expected = new Complex(Double.NaN, Double.NaN); Complex expected = new Complex(Double.NaN, Double.NaN);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testParsePositiveInfinity() { public void testParsePositiveInfinity() {
String source = "(Infinity) + (Infinity)i"; String source = "(Infinity) + (Infinity)i";
Complex expected = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); Complex expected = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test
public void testPaseNegativeInfinity() { public void testPaseNegativeInfinity() {
String source = "(-Infinity) - (Infinity)i"; String source = "(-Infinity) - (Infinity)i";
Complex expected = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); Complex expected = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
try { Complex actual = complexFormat.parse(source);
Complex actual = complexFormat.parse(source); Assert.assertEquals(expected, actual);
Assert.assertEquals(expected, actual);
} catch (MathParseException ex) {
Assert.fail(ex.getMessage());
}
} }
@Test @Test