コード例 #1
0
ファイル: FractionTest.java プロジェクト: PAMSE/APGBench
 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.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);
 }
コード例 #2
0
ファイル: FractionTest.java プロジェクト: PAMSE/APGBench
 public void testEqualsAndHashCode() {
   Fraction zero = new Fraction(0, 1);
   Fraction nullFraction = null;
   assertTrue(zero.equals(zero));
   assertFalse(zero.equals(nullFraction));
   assertFalse(zero.equals(Double.valueOf(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)));
 }