public class FractionTest {

    public static void main(String[] args) {

        Fraction a = new Fraction(1,2);
        Fraction b = new Fraction(3,4);
        Fraction c = new Fraction(1,4);
        Fraction d = new Fraction(2,3);
        Fraction e = new Fraction(2,3);

        // Test 1 (addition)
        Fraction sum = a.add(b).reduce();
        System.out.println(a.n + "/" + a.d + " + " + b.n + "/" + b.d + " = " + sum.n + "/" + sum.d);

        // Test 2 (subtraction)
        Fraction difference = a.subtract(b).reduce();
        System.out.println(a.n + "/" + a.d + " - " + b.n + "/" + b.d + " = " + difference.n + "/" + difference.d);

        // Test 3 (multiplication)
        Fraction product = a.multiply(b).reduce();
        System.out.println(a.n + "/" + a.d + " * " + b.n + "/" + b.d + " = " + product.n + "/" + product.d);

        // Test 4 (division)
        Fraction quotient = a.divide(b).reduce();
        System.out.println(a.n + "/" + a.d + " / " + b.n + "/" + b.d + " = " + quotient.n + "/" + quotient.d);

        // Test 5 (static method Fraction.gcd(int, int))
        Fraction f1 = new Fraction(16170, 510510);
        int gcd = Fraction.gcd(f1.n, f1.d);
        System.out.println("gcd(" + f1.n + "," + f1.d + ")" + " = " + gcd);

        // Test 6 (reduce)
        System.out.print(f1.n + "/" + f1.d + " = ");
        f1.reduce();  // reduce() mutates f1
        System.out.println(f1.n + "/" + f1.d);

        // Test 7 (chaining) Notice that add(), subtract(), multiply(), and divide()
        // do not mutate their instances. Also notice the order of operations.
        Fraction f3 = a.add(b).subtract(c).multiply(d).divide(e).reduce();
        System.out.println("(a + b - c) * d / e = " + f3.n + "/" + f3.d);

        // TODO: EC_0 : Override Object.toString() in Fraction to simplify the print statements.

        // TODO: EC_1 : 1/-4 should be displayed as -1/4
    }
}
