commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r264689 - /jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/fraction/FractionTest.java
Date Tue, 30 Aug 2005 03:28:44 GMT
Author: psteitz
Date: Mon Aug 29 20:28:42 2005
New Revision: 264689

URL: http://svn.apache.org/viewcvs?rev=264689&view=rev
Log:
Added tests for fraction equals and reduced fraction.

Modified:
    jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/fraction/FractionTest.java

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/fraction/FractionTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/fraction/FractionTest.java?rev=264689&r1=264688&r2=264689&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/fraction/FractionTest.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/fraction/FractionTest.java
Mon Aug 29 20:28:42 2005
@@ -412,4 +412,34 @@
             fail("expecting ArithmeticException but got: " + f.toString());
         } catch (ArithmeticException ex) {}
     }
+    
+    public void testEqualsAndHashCode() {
+        Fraction zero  = new Fraction(0,1);
+        Fraction nullFraction = null;
+        int zeroHash = zero.hashCode();
+        assertTrue( zero.equals(zero));
+        assertFalse(zero.equals(nullFraction));
+        assertFalse(zero.equals(new Double(0)));
+        Fraction zero2 = new Fraction(0,2);
+        assertTrue(zero.equals(zero2));
+        assertEquals(zero.hashCode(), zero2.hashCode());
+        Fraction one = new Fraction(1,1);
+        assertFalse((one.equals(zero) ||zero.equals(one)));
+    }
+    
+    public void testGetReducedFraction() {
+        Fraction threeFourths = new Fraction(3, 4);
+        assertTrue(threeFourths.equals(Fraction.getReducedFraction(6, 8)));
+        assertTrue(Fraction.ZERO.equals(Fraction.getReducedFraction(0, -1)));
+        try {
+            Fraction f = Fraction.getReducedFraction(1, 0);
+            fail("expecting ArithmeticException");
+        } catch (ArithmeticException ex) {
+            // expected
+        }
+        assertEquals(Fraction.getReducedFraction
+                (2, Integer.MIN_VALUE).getNumerator(),-1);
+        assertEquals(Fraction.getReducedFraction
+                (1, -1).getNumerator(), -1);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message