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@1066303 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2011-02-02 01:57:12 +00:00
parent eb221effa3
commit 84074bf247
5 changed files with 54 additions and 122 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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

View File

@ -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() {

View File

@ -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);
}
}