Added a few unit tests.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1209119 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-12-01 15:25:19 +00:00
parent ee2e728f63
commit 5af9537a5f
1 changed files with 38 additions and 0 deletions

View File

@ -136,6 +136,44 @@ public class FractionFormatTest {
}
}
@Test
public void testParseOne1() {
String source = "1 / 1";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
Assert.assertEquals(1, c.getNumerator());
Assert.assertEquals(1, c.getDenominator());
}
@Test
public void testParseOne2() {
String source = "10 / 10";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
Assert.assertEquals(1, c.getNumerator());
Assert.assertEquals(1, c.getDenominator());
}
@Test
public void testParseZero1() {
String source = "0 / 1";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
Assert.assertEquals(0, c.getNumerator());
Assert.assertEquals(1, c.getDenominator());
}
@Test
public void testParseZero2() {
String source = "-0 / 1";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
Assert.assertEquals(0, c.getNumerator());
Assert.assertEquals(1, c.getDenominator());
// This test shows that the sign is not preserved.
Assert.assertEquals(Double.POSITIVE_INFINITY, 1d / c.doubleValue(), 0);
}
@Test
public void testParseInvalid() {
String source = "a";