예제 #1
0
        public void AdditionMiddleNegativeFraction()
        {
            Fraction fraction    = new Fraction(2, 4);
            Fraction fractionTwo = new Fraction(-2, 4);

            Fraction fractionResult = fraction.Addition(fractionTwo);

            Assert.AreEqual(0, fractionResult.Numerator);
            Assert.AreEqual(1, fractionResult.Denominator);
        }
예제 #2
0
        public void AdditionBigFraction()
        {
            Fraction fraction    = new Fraction(1, 1);
            Fraction fractionTwo = new Fraction(100000000, 1);

            Fraction fractionResult = fraction.Addition(fractionTwo);

            Assert.AreEqual(100000001, fractionResult.Numerator);
            Assert.AreEqual(1, fractionResult.Denominator);
        }
예제 #3
0
        public static void MainFraction()
        {
            int count = 0;

            Console.WriteLine("Введите количество дробей в массиве");
            try
            {
                count = Operation.GetInt();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Fraction sum = new Fraction(0, 1);

            Fraction[] array  = new Fraction[count];
            Random     random = new Random();

            for (int i = 0; i < count; i++)
            {
                Fraction value = new Fraction(random.Next(-10, 10), random.Next(1, 10));
                array[i] = value;
                Console.WriteLine(array[i]);
            }

            Array.Sort(array);

            Console.WriteLine("\r\nОтсортированный массив:\r\n");
            Operation.PrintArray(array);

            for (int i = 0; i < count; i++)
            {
                sum = sum.Addition(array[i]);
            }

            Console.WriteLine("\r\nСумма дробей = " + sum);

            Console.ReadKey();
        }