public void SimplifyTest()
 {
     Fraction target = new Fraction(10, 2);
     target.Simplify();
     Assert.AreEqual(5, target.numerator);
     Assert.AreEqual(1, target.denominator);
 }
Пример #2
0
        public static Fraction operator +(Fraction a, Fraction b)
        {
            BigInteger denom = a.denominator;
            BigInteger n1 = a.numerator, n2 = b.numerator;
            if (denom != b.denominator)
            {
                denom = a.denominator * b.denominator;
                n1 = checked(n1 * b.denominator);
                n2 = checked(n2 * a.denominator);
            }

            Fraction ret = new Fraction(n1 + n2, denom);
            ret.Simplify();
            return ret;
        }
        public void op_DivisionTest()
        {
            Fraction expected = new Fraction(1, 2);
            Fraction actual = new Fraction(1) / new Fraction(2);
            Assert.AreEqual(true, expected == actual);

            expected = new Fraction(3, 2);
            actual = new Fraction(3) / new Fraction(2);
            Assert.AreEqual(true, expected == actual);

            actual = new Fraction(1, 2) / new Fraction(1, 6);
            actual.Simplify();
            expected = new Fraction(3, 1);
            Assert.AreEqual(true, expected == actual);
        }
Пример #4
0
 static void Main(string[] args)
 {
     Fraction product = new Fraction(1);
     for (int a = 10; a < 100; a++)
     {
         for (int b = a+1; b < 100; b++)
         {
             Fraction f = new Fraction(a, b);
             if (Cancels(f))
             {
                 product = product * f;
             }
         }
     }
     product.Simplify();
     Euler.Utils.OutputAnswer(product.denominator.ToString());
 }