using System;

class FractionTest
{
    static void Main()
    {
        Fraction frac1 = new Fraction(5, 2);
        Fraction frac2 = new Fraction(5, 0);

        // Ausgabe
        Console.WriteLine("{0} geteilt durch {1} = {2}",
                          frac1.Numerator, frac1.Denominator, frac1.GetDecimalNumber());
        Console.WriteLine("{0} geteilt durch {1} = {2}",
                          frac2.Numerator, frac2.Denominator, frac2.GetDecimalNumber());

        // explizite Umwandlung in double
        Console.WriteLine("\n explizite Umwandlung in double \n");
        double f1 = (double)frac1;
        Console.WriteLine("({0}/{1}) als double: {2}",
                          frac1.Numerator, frac1.Denominator, f1);
        double f2 = (double)frac2;
        Console.WriteLine("({0}/{1}) als double: {2}",
                          frac2.Numerator, frac2.Denominator, f2);

        // implizite Umwandlung aus int
        Console.WriteLine("\n implizite Umwandlung aus int \n");
        Fraction frac3 = 15;
        Console.WriteLine("{0} wird zu ({1}/{2})",
                          15, frac3.Numerator, frac3.Denominator);

        // explizite Umwandlung in int
        Console.WriteLine("\n explizite Umwandlung in int \n");
        int n1 = (int)frac1;
        Console.WriteLine("({0}/{1}) als int: {2}",
                          frac1.Numerator, frac1.Denominator, n1);
        try
        {
            int n2 = (int)frac2;
            Console.WriteLine("({0}/{1}) als int: {2}",
                              frac2.Numerator, frac2.Denominator, n2);
        }
        catch (DivideByZeroException)
        {
            Console.WriteLine("keine Umwandlung wenn Nenner = 0");
        }

        // Addition und Subtraktion
        Console.WriteLine("\n Addition und Subtraktion \n");
        Fraction fracOne = new Fraction(5, 2);
        Fraction fracTwo = new Fraction(3, 2);

        Fraction fracThree = fracOne + fracTwo;
        Console.WriteLine("({0}/{1}) + ({2}/{3}) = ({4}/{5})",
                          fracOne.Numerator, fracOne.Denominator,
                          fracTwo.Numerator, fracTwo.Denominator,
                          fracThree.Numerator, fracThree.Denominator);

        Fraction fracFour = fracThree - fracTwo;
        Console.WriteLine("({0}/{1}) - ({2}/{3}) = ({4}/{5})",
                          fracThree.Numerator, fracThree.Denominator,
                          fracTwo.Numerator, fracTwo.Denominator,
                          fracFour.Numerator, fracFour.Denominator);

        Console.WriteLine("");
        fracOne = new Fraction(123, 8);
        fracTwo = new Fraction(15, 3);

        fracThree = fracOne + fracTwo;
        Console.WriteLine("({0}/{1}) + ({2}/{3}) = ({4}/{5})",
                          fracOne.Numerator, fracOne.Denominator,
                          fracTwo.Numerator, fracTwo.Denominator,
                          fracThree.Numerator, fracThree.Denominator);

        fracFour = fracThree - fracTwo;
        Console.WriteLine("({0}/{1}) - ({2}/{3}) = ({4}/{5})",
                          fracThree.Numerator, fracThree.Denominator,
                          fracTwo.Numerator, fracTwo.Denominator,
                          fracFour.Numerator, fracFour.Denominator);

        /*
                // ggT
                Console.WriteLine("\n ggT \n");
                Console.WriteLine("ggT von ({0}/{1}) = {2}", frac1.Numerator, frac1.Denominator, frac1.GCD(frac1.Numerator, frac1.Denominator));
                Console.WriteLine("ggT von ({0}/{1}) = {2}", frac2.Numerator, frac2.Denominator, frac2.GCD(frac2.Numerator, frac2.Denominator));
                Console.WriteLine("ggT von ({0}/{1}) = {2}", fracOne.Numerator, fracOne.Denominator, fracOne.GCD(fracOne.Numerator, fracOne.Denominator));
                Console.WriteLine("ggT von ({0}/{1}) = {2}", fracTwo.Numerator, fracTwo.Denominator, fracTwo.GCD(fracTwo.Numerator, fracTwo.Denominator));
                Console.WriteLine("ggT von ({0}/{1}) = {2}", fracThree.Numerator, fracThree.Denominator, fracThree.GCD(fracThree.Numerator, fracThree.Denominator));
                Console.WriteLine("ggT von ({0}/{1}) = {2}", fracFour.Numerator, fracFour.Denominator, fracFour.GCD(fracFour.Numerator, fracFour.Denominator));
        */

        // kürzen
        Console.WriteLine("\n kürzen \n");
        Fraction f = new Fraction(1107, 9);
        f.Reduce();
        Console.WriteLine("(1107/9) -> ({0}/{1})", f.Numerator, f.Denominator);
        f = new Fraction(9, 1107);
        f.Reduce();
        Console.WriteLine("(9/1107) -> ({0}/{1})", f.Numerator, f.Denominator);


        /*** Vergleichsmethoden testen ***/

        // Test auf Gleichheit
        Console.Write("\n Test auf Gleichheit (==): ");

        frac1 = new Fraction(100, 10);
        if (frac1 == frac1)
            Console.Write(".");
        else
            return;
        // Null
        if (frac1 == null)
            return;
        else
            Console.Write(".");

        frac1 = new Fraction(100, 10);
        frac2 = new Fraction(100, 10);
        if (frac1 == frac2)
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(200, 20);
        if (frac1 == frac2)
            Console.Write(".");
        else
            return;
        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(40, -8);
        if (frac1 == frac2)
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(41, -8);
        if (frac1 == frac2)
            return;
        else
            Console.Write(".");
        Console.WriteLine(" okay ");

        // Test auf Ungleichheit
        Console.Write("\n Test auf Ungleichheit (!=): ");

        // Reflexivität
        frac1 = new Fraction(100, 10);
        if (frac1 != frac1)
            return;
        else
            Console.Write(".");
        // Null
        if (frac1 != null)
            Console.Write(".");
        else
            return;

        frac2 = new Fraction(100, 10);
        if (frac1 != frac2)
            return;
        else
            Console.Write(".");
        frac2 = new Fraction(200, 20);
        if (frac1 != frac2)
            return;
        else
            Console.Write(".");
        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(40, -8);
        if (frac1 != frac2)
            return;
        else
            Console.Write(".");
        frac2 = new Fraction(41, -8);
        if (frac1 != frac2)
            Console.Write(".");
        else
            return;
        Console.WriteLine(" okay ");

        // Test auf Gleichheit
        Console.Write("\n Test auf Gleichheit (equals): ");

        // Reflexivität
        frac1 = new Fraction(100, 10);
        if (frac1.Equals(frac1))
            Console.Write(".");
        else
            return;
        if (frac1.Equals((Object)frac1))
            Console.Write(".");
        else
            return;
        // Null
        if (frac1.Equals(null))
            return;
        else
            Console.Write(".");

        frac1 = new Fraction(100, 10);
        frac2 = new Fraction(100, 10);
        if (frac1.Equals(frac2))
            Console.Write(".");
        else
            return;
        if (frac1.Equals((Object)frac2))
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(200, 20);
        if (frac1.Equals(frac2))
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(200, 20);
        if (frac1.Equals((Object)frac2))
            Console.Write(".");
        else
            return;
        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(40, -8);
        if (frac1.Equals(frac2))
            Console.Write(".");
        else
            return;
        if (frac1.Equals((Object)frac2))
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(41, -8);
        if (frac1.Equals(frac2))
            return;
        else
            Console.Write(".");
        if (frac1.Equals((Object)frac2))
            return;
        else
            Console.Write(".");
        Console.WriteLine(" okay ");

        // Teste Hashcode
        Console.Write("\n Teste Hashcode : ");

        frac1 = new Fraction(100, 10);
        frac2 = new Fraction(100, 10);
        if (frac1.GetHashCode() == frac2.GetHashCode())
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(200, 20);
        if (frac1.GetHashCode() == frac2.GetHashCode())
            Console.Write(".");
        else
            return;
        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(40, -8);
        if (frac1.GetHashCode() == frac2.GetHashCode())
            Console.Write(".");
        else
            return;
        frac2 = new Fraction(41, -8);
        if (frac1.GetHashCode() == frac2.GetHashCode())
            Console.Write("bad");
        else
            Console.Write(".");
        frac2 = new Fraction(51, -8);
        if (frac1.GetHashCode() == frac2.GetHashCode())
            Console.Write("bad");
        else
            Console.Write(".");
        Console.WriteLine(" okay ");

        // Teste ComapreTo
        Console.Write("\n Teste CompareTo : ");

        frac1 = new Fraction(100, 10);
        if (frac1.CompareTo(frac1) == 0)
            Console.Write(".");
        else
            return;

        frac1 = new Fraction(100, 10);
        frac2 = new Fraction(100, 10);
        if (frac1.CompareTo(frac2) == 0)
            Console.Write(".");
        else
            return;

        frac1 = new Fraction(100, 10);
        frac2 = new Fraction(200, 20);
        if (frac1.CompareTo(frac2) == 0)
            Console.Write(".");
        else
            return;

        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(40, -8);
        if (frac1.CompareTo(frac2) == 0)
            Console.Write(".");
        else
            return;

        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(40, -8);
        if (frac2.CompareTo(frac1) == 0)
            Console.Write(".");
        else
            return;

        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(41, -8);
        if (frac1.CompareTo(frac2) < 0)
            Console.Write(".");
        else
            return;
        if (frac2.CompareTo(frac1) > 0)
            Console.Write(".");
        else
            return;

        frac1 = new Fraction(-15, 3);
        frac2 = new Fraction(39, -8);
        if (frac1.CompareTo(frac2) > 0)
            Console.Write(".");
        else
            return;
        if (frac2.CompareTo(frac1) < 0)
            Console.Write(".");
        else
            return;

        try
        {
            frac1 = new Fraction(-15, 3);
            string s = "Hallo";
            if (frac1.CompareTo(s) < 0)
                return;
        }
        catch (Exception)
        {
            Console.Write(".");
        }

        Console.WriteLine(" okay ");

        // Teste <, <=, >, >=
        Console.Write("\n Teste <, <=, >, >= : ");

        frac1 = new Fraction(99, 10);
        frac2 = new Fraction(100, 10);
        if (frac1 < frac2 == true)
            Console.Write(".");
        else
            return;
        if (frac1 <= frac2 == true)
            Console.Write(".");
        else
            return;
        if (frac1 >= frac2 == false)
            Console.Write(".");
        else
            return;
        if (frac1 > frac2 == false)
            Console.Write(".kleiner");
        else
            return;

        frac1 = new Fraction(100, 10);
        frac2 = new Fraction(100, 10);
        if (frac1 < frac2 == false)
            Console.Write(".");
        else
            return;
        if (frac1 <= frac2 == true)
            Console.Write(".");
        else
            return;
        if (frac1 >= frac2 == true)
            Console.Write(".");
        else
            return;
        if (frac1 > frac2 == false)
            Console.Write(".gleich");
        else
            return;

        frac1 = new Fraction(101, 10);
        frac2 = new Fraction(100, 10);
        if (frac1 < frac2 == false)
            Console.Write(".");
        else
            return;
        if (frac1 <= frac2 == false)
            Console.Write(".");
        else
            return;
        if (frac1 >= frac2 == true)
            Console.Write(".");
        else
            return;
        if (frac1 > frac2 == true)
            Console.Write(".groesser");
        else
            return;


        Console.WriteLine(" okay ");


    }
}