@Test public void testsubtract() { assertEquals(subtractOne, zero.subtract(one)); assertEquals(one, zero.subtract(subtractOne)); assertEquals(posRat, posRat.subtract(zero)); assertEquals(negRat, negRat.subtract(zero)); assertEquals(zero, subtractOne.subtract(subtractOne)); assertEquals(new Fraction(1, 2), new Fraction(3, 2).subtract(one)); assertEquals(new Fraction(1, 4), new Fraction(-1, 4).subtract(new Fraction(-1, 2))); assertEquals(new Fraction(-3, 10), new Fraction(-21, 20).subtract(new Fraction(-3, 4))); assertEquals(new Fraction(100, 111), new Fraction(9587, 8547).subtract(new Fraction(17, 77))); }
public void test1() { Fraction r1 = new Fraction(2, 3); Fraction r2 = new Fraction(4, 6); Fraction r3 = new Fraction(4, 9); Fraction r4 = new Fraction(4, 3); Fraction r5 = new Fraction(0, 1); Fraction r6 = new Fraction(1, 1); Fraction r7 = new Fraction(1, 3); Fraction r8 = new Fraction(2, 1); Fraction r9 = new Fraction(2, 9); Fraction r10 = new Fraction(-1, 3); assertEquals(r1, r2); assertEquals(r3, r1.multiply(r2)); assertEquals(r1, r1.multiply(r6)); assertEquals(r1, r6.multiply(r1)); assertEquals(r5, r5.multiply(r1)); assertEquals(r10, r10.multiply(r6)); assertEquals(r6, r1.divide(r2)); assertEquals(r5, r5.divide(r1)); assertEquals(r1, r1.divide(r6)); assertEquals(r7, r3.divide(r4)); try { assertEquals(r7, r3.divide(r5)); } catch (ArithmeticException e) { assertTrue(true); } assertEquals(r4, r1.add(r2)); assertEquals(r8, r2.add(r4)); assertEquals(r6, r1.add(r7)); assertEquals(r6, r5.add(r6)); assertEquals(r1, r10.add(r6)); assertEquals(r5, r1.subtract(r2)); assertEquals(r9, r2.subtract(r3)); assertEquals(r4, r4.subtract(r5)); assertEquals(r10, r7.subtract(r1)); }