@Test public void testSimplify() { Fraction a = new Fraction(2, 4); a = a.simplify(); assertEquals(a, (new Fraction(1, 2))); assertTrue(a.toValue() == 0.5); }
@Test public void testDivide() { assertEquals(myFraction1.divide(myFraction2).toString(), "4 / 3"); assertEquals(myFraction3.divide(myFraction4).toString(), "5 / 2"); myFraction1 = myFraction1.add(myFraction1); }
@Test public void testMultiply() { assertEquals(myFraction1.multiply(myFraction2).toString(), "12 / 25"); assertEquals(myFraction3.multiply(myFraction4).toString(), "10 / 49"); myFraction1 = myFraction1.add(myFraction1); }
@Test public void testSubtract() { assertEquals(myFraction1.subtract(myFraction2).toString(), "1 / 5"); assertEquals(myFraction3.subtract(myFraction4).toString(), "3 / 7"); myFraction1 = myFraction1.add(myFraction1); }
@Test public void testAdd() { assertEquals(myFraction1.add(myFraction2).toString(), "7 / 5"); assertEquals(myFraction3.add(myFraction4).toString(), "1"); myFraction1 = myFraction1.add(myFraction1); }