assertEquals("1/3", rational.toString());
}
public void testToSimpleString() throws Exception
{
Rational third1 = new Rational(1, 3);
Rational third2 = new Rational(2, 6);
assertEquals("1/3", third1.toSimpleString(true));
assertEquals("1/3", third2.toSimpleString(true));
assertEquals(third1, third2);
Rational twoThirds = new Rational(10, 15);
assertEquals("2/3", twoThirds.toSimpleString(true));
Rational two = new Rational(10, 5);
assertTrue(two.isInteger());
assertEquals("2", two.toSimpleString(true));
assertEquals("2", two.toSimpleString(false));
Rational twoFifths = new Rational(4, 10);
assertEquals("0.4", twoFifths.toSimpleString(true));
assertEquals("2/5", twoFifths.toSimpleString(false));
Rational threeEigths = new Rational(3, 8);
assertEquals("3/8", threeEigths.toSimpleString(true));
Rational zero = new Rational(0, 8);
assertTrue(zero.isInteger());
assertEquals("0", zero.toSimpleString(true));
assertEquals("0", zero.toSimpleString(false));
zero = new Rational(0, 0);
assertTrue(zero.isInteger());
assertEquals("0", zero.toSimpleString(true));
assertEquals("0", zero.toSimpleString(false));
// not sure this is a nice presentation of rationals. won't implement it for now.
// Rational twoAndAHalf = new Rational(10,4);
// assertEquals("2 1/2", twoAndAHalf.toSimpleString());
}