commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1209119 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java
Date Thu, 01 Dec 2011 15:25:19 GMT
Author: erans
Date: Thu Dec  1 15:25:19 2011
New Revision: 1209119

URL: http://svn.apache.org/viewvc?rev=1209119&view=rev
Log:
Added a few unit tests.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java?rev=1209119&r1=1209118&r2=1209119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java
Thu Dec  1 15:25:19 2011
@@ -137,6 +137,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";
         String msg = "should not be able to parse '10 / a'.";



Mime
View raw message