public void Interest_WhenSumNumeratorIsTooSmallOrTooLarge_ShouldThrowArithmeticException()
 {
     Fraction fraction6 = new Fraction(long.MaxValue, 1);
     Console.WriteLine("{0} = {1}\n", fraction6.SimpleFractionToString(), fraction6);
     Fraction fraction7 = new Fraction(1, 1);
     Console.WriteLine("{0} = {1}\n", fraction7.SimpleFractionToString(), fraction7);
     Fraction tooLarge = fraction6 + fraction7;
 }
 public void Interest_WhenMultiplicationNominatorIsTooLargeOrTooSmall_ShouldThrowArithmeticException()
 {
     Fraction fraction6 = new Fraction(2, 1);
     Console.WriteLine("{0} = {1}\n", fraction6.SimpleFractionToString(), fraction6);
     Fraction fraction7 = new Fraction(long.MaxValue, 1);
     Console.WriteLine("{0} = {1}\n", fraction7.SimpleFractionToString(), fraction7);
     Fraction tooLarge = fraction6 * fraction7;
 }
 static void Main()
 {
     Fraction fraction1 = new Fraction(8, 10);
     Fraction fraction2 = new Fraction(4, 10);
     Fraction result = fraction1 - fraction2;
     Console.WriteLine(result.Numerator);
     Console.WriteLine(result.Denominator);
     Console.WriteLine(result);
 }
        static void Main(string[] args)
        {
            Fraction fraction1 = new Fraction(22, 7);
            Fraction fraction2 = new Fraction(40, 4);
            Fraction result = fraction1 + fraction2;
            Console.WriteLine(result.Numerator);
            Console.WriteLine(result.Denominator);
            Console.WriteLine(result);

        }
Пример #5
0
        public static Fraction operator -(Fraction f1, Fraction f2)
        {
            long commonDevider = CalculateMCD(f1.Denominator, f2.Denominator);

            long numerator = ((commonDevider / f1.Denominator) * f1.numerator) - ((commonDevider / f2.Denominator) * f2.numerator);

            Fraction result = new Fraction(numerator, commonDevider);

            return result;
        }
 static void Main(string[] args)
 {
     Fraction fraction1 = new Fraction(17, 8);
     Fraction fraction2 = new Fraction(34, 13);
     Fraction result = fraction1 + fraction2;
     Console.WriteLine(result.Numerator);
     Console.WriteLine(result.Denumerator);
     Console.WriteLine(result);
    
 }
Пример #7
0
        internal static void Main()
        {
            // Normalized => numerator and denominator divided by 2 (the GCD of 22 and 8)
            Fraction fraction1 = new Fraction(22, 8);

            // Normalized => numerator and denominator divided by 4 (the GCD of 40 and 4)
            Fraction fraction2 = new Fraction(40, 4);
            Fraction resultSum = fraction1 + fraction2;

            Console.WriteLine(
                "{0} + {1} = {2} = {3}\n", 
                fraction1.SimpleFractionToString(), 
                fraction2.SimpleFractionToString(), 
                resultSum.SimpleFractionToString(), 
                resultSum);

            Fraction resultSubtraction = fraction1 - fraction2;
            Console.WriteLine(
                "{0} - {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultSubtraction.SimpleFractionToString(),
                resultSubtraction);

            Fraction resultMultiplication = fraction1 * fraction2;
            Console.WriteLine(
                "{0} * {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultMultiplication.SimpleFractionToString(),
                resultMultiplication);

            Fraction resultDivision = fraction1 / fraction2;
            Console.WriteLine(
                "{0} / {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultDivision.SimpleFractionToString(),
                resultDivision);

            Fraction fraction3 = new Fraction(0, -1);
            Console.WriteLine("{0} = {1}\n", fraction3.SimpleFractionToString(), fraction3);

            Fraction fraction4 = new Fraction(5, -3);
            Console.WriteLine("{0} = {1}\n", fraction4.SimpleFractionToString(), fraction4);

            Fraction fraction5 = new Fraction(10, 5); // Will be normalized to 2/1
            Console.WriteLine("{0} = {1}\n", fraction5.SimpleFractionToString(), fraction5);

            Fraction fraction6 = new Fraction(long.MaxValue, 1);
            Console.WriteLine("{0} = {1}\n", fraction6.SimpleFractionToString(), fraction6);

            Fraction fraction7 = new Fraction(1, 1);
            Console.WriteLine("{0} = {1}\n", fraction7.SimpleFractionToString(), fraction7);
        }
        public void Test_DivisionOperatorMethod()
        {
            // arrange
            Fraction fraction1 = new Fraction(22, 8);
            Fraction fraction2 = new Fraction(40, 4);
            Fraction expected = new Fraction(11, 40);

            // assert
            Fraction actual = fraction1 / fraction2;
            Assert.AreEqual(expected, actual, "Fractions quotent not calculated correctly");
        }
Пример #9
0
        static void Main()
        {
            var fraction1 = new Fraction(22, 7);
            var fraction2 = new Fraction(40, 4);

            var result = fraction1 + fraction2;

            Console.WriteLine(result.Numerator);
            Console.WriteLine(result.Denominator);
            Console.WriteLine(result);
        }
Пример #10
0
        internal static void Main()
        {
            // Normalized => numerator and denominator divided by 2 (the GCD of 22 and 8)
            Fraction fraction1 = new Fraction(22, 8);

            // Normalized => numerator and denominator divided by 4 (the GCD of 40 and 4)
            Fraction fraction2 = new Fraction(40, 4);
            Fraction resultSum = fraction1 + fraction2;

            Console.WriteLine(
                "{0} + {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultSum.SimpleFractionToString(),
                resultSum);

            Fraction resultSubtraction = fraction1 - fraction2;

            Console.WriteLine(
                "{0} - {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultSubtraction.SimpleFractionToString(),
                resultSubtraction);

            Fraction resultMultiplication = fraction1 * fraction2;

            Console.WriteLine(
                "{0} * {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultMultiplication.SimpleFractionToString(),
                resultMultiplication);

            Fraction resultDivision = fraction1 / fraction2;

            Console.WriteLine(
                "{0} / {1} = {2} = {3}\n",
                fraction1.SimpleFractionToString(),
                fraction2.SimpleFractionToString(),
                resultDivision.SimpleFractionToString(),
                resultDivision);

            Fraction fraction3 = new Fraction(0, -1);

            Console.WriteLine("{0} = {1}\n", fraction3.SimpleFractionToString(), fraction3);

            Fraction fraction4 = new Fraction(5, -3);

            Console.WriteLine("{0} = {1}\n", fraction4.SimpleFractionToString(), fraction4);

            Fraction fraction5 = new Fraction(10, 5); // Will be normalized to 2/1

            Console.WriteLine("{0} = {1}\n", fraction5.SimpleFractionToString(), fraction5);

            Fraction fraction6 = new Fraction(long.MaxValue, 1);

            Console.WriteLine("{0} = {1}\n", fraction6.SimpleFractionToString(), fraction6);

            Fraction fraction7 = new Fraction(1, 1);

            Console.WriteLine("{0} = {1}\n", fraction7.SimpleFractionToString(), fraction7);
        }
Пример #11
0
        public static Fraction operator -(Fraction fractionA, Fraction fractionB)
        {
            Fraction result = fractionA + new Fraction(fractionB.Numerator * -1, fractionB.Denumerator);

            return(result);
        }
        public void Test_SubtractionOperatorMethod()
        {
            // arrange
            Fraction fraction1 = new Fraction(22, 8);
            Fraction fraction2 = new Fraction(40, 4);
            Fraction expected = new Fraction(-29, 4);

            // assert
            Fraction actual = fraction1 - fraction2;
            Assert.AreEqual(expected, actual, "Fractions difference not calculated correctly");
        }
        public void Test_MultiplicationOperatorMethod()
        {
            // arrange
            Fraction fraction1 = new Fraction(22, 8);
            Fraction fraction2 = new Fraction(40, 4);
            Fraction expected = new Fraction(55, 2);

            // assert
            Fraction actual = fraction1 * fraction2;
            Assert.AreEqual(expected, actual, "Fractions product not calculated correctly");
        }
 public void Interest_WhenDenominatorIsNegative_ShouldThrowDivideByZeroException()
 {
     Fraction fraction = new Fraction(1, 0);
 }
 public void Fraction_WithAllArgumentsValid_ShouldPassTest()
 {
     Fraction fraction = new Fraction(0, -1);
 }
        public void Test_SumOperatorMethod()
        {
            // arrange
            Fraction fraction1 = new Fraction(22, 8);
            Fraction fraction2 = new Fraction(40, 4);
            Fraction expected = new Fraction(51, 4);

            // assert
            Fraction actual = fraction1 + fraction2;
            Assert.AreEqual(expected, actual, "Fractions sum not calculated correctly");
        }