Exemplo n.º 1
0
  public void testDoubleValue() {
    Fraction first = new Fraction(1, 2);
    Fraction second = new Fraction(1, 3);

    assertEquals(0.5, first.doubleValue(), 0.0);
    assertEquals(1.0 / 3.0, second.doubleValue(), 0.0);
  }
Exemplo n.º 2
0
  public void testCompareTo() {
    Fraction first = new Fraction(1, 2);
    Fraction second = new Fraction(1, 3);
    Fraction third = new Fraction(1, 2);

    assertEquals(0, first.compareTo(first));
    assertEquals(0, first.compareTo(third));
    assertEquals(1, first.compareTo(second));
    assertEquals(-1, second.compareTo(first));

    // these two values are different approximations of PI
    // the first  one is approximately PI - 3.07e-18
    // the second one is approximately PI + 1.936e-17
    Fraction pi1 = new Fraction(1068966896, 340262731);
    Fraction pi2 = new Fraction(411557987, 131002976);
    assertEquals(-1, pi1.compareTo(pi2));
    assertEquals(1, pi2.compareTo(pi1));
    assertEquals(0.0, pi1.doubleValue() - pi2.doubleValue(), 1.0e-20);
  }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 public void visit(int row, int column, Fraction value) {
   data[row][column] = value.doubleValue();
 }