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,1);

        // Test 1 (addition)
        Fraction sum = a.add(b).reduce();
        System.out.println(a + " + " + b + " = " + sum);

        // Test 2 (subtraction)
        Fraction difference = a.subtract(b).reduce();
        System.out.println(a + " - " + b + " = " + difference);

        // Test 3 (multiplication)
        Fraction product = a.multiply(b).reduce();
        System.out.println(a + " * " + b + " = " + product);

        // Test 4 (division)
        Fraction quotient = a.divide(b).reduce();
        System.out.println(a + " / " + b + " = " + quotient);

        // Test 5 (static method Fraction.gcd(long, long))
        Fraction f1 = new Fraction(16170, 510510);
        long gcd = Fraction.gcd(f1.n, f1.d);
        System.out.println("gcd(" + f1.n + "," + f1.d + ")" + " = " + gcd);

        // Test 6 (reduce)
        System.out.print(f1 + " = ");
        f1.reduce();  // reduce() mutates f1
        System.out.println(f1);

        // 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);
        //
        Fraction f4 = a.add(b).subtract(c.multiply(d).divide(e)).reduce();
        System.out.println(a + " + " + b + " - " + c + " * " + d + " / " + e + " = " + f4);
    }
}