Example #1
0
        public void BinaryEuclideanAlg_NegativeDigits_CorrectGCD()
        {
            //Act
            var target = GCDFinder.BinaryEuclideanAlg(_digitOne * -1, _digitTwo * -1);

            //Assert
            Assert.AreEqual(_expectedGCD, target);
        }
Example #2
0
        public void BinaryEuclideanAlg_TwoNormalDigits_CorrectGDC()
        {
            //Act
            var target = GCDFinder.BinaryEuclideanAlg(_digitOne, _digitTwo);

            //Assert
            Assert.AreEqual(_expectedGCD, target);
        }
Example #3
0
        public void BinaryEuclideanAlg_LotsOfDigits_CorrectGCD()
        {
            //Arrange
            var otherDigits = new decimal[] { 570, 36 };
            //Act
            var target = GCDFinder.EuclideanAlg(_digitOne, _digitTwo, otherDigits);

            //Assert
            Assert.AreEqual(_expectedGCD, target);
        }
Example #4
0
        static void Main(string[] args)
        {
            //Содержит числа введенные пользователем
            List <decimal> digits = new List <decimal>();

            //Приглашение пользователя к вводу чисел
            Checker.UserInputVerifiable("Пожалуйста, введите числа для поиска НОД, разделяя их символом ';'", (string input) =>
            {
                string[] inputSplited = input.Split(';', StringSplitOptions.RemoveEmptyEntries);

                if (inputSplited.Length < 2)
                {
                    Checker.ErrorWriteLine("Слишком мало чисел. Пожалуйста введит по крайне мере 2 числа.");
                    return(false);
                }

                foreach (var digitStr in inputSplited)
                {
                    if (!decimal.TryParse(digitStr, out var digit))
                    {
                        Checker.ErrorWriteLine($"Не удалось распознать число.\nПозиция: {input.IndexOf(digitStr) + 1}\nВвод: {digitStr}");
                        digits.Clear();
                        return(false);
                    }
                    digits.Add(digit);
                }
                return(true);
            });

            //Первое введенное число
            var digitOne = digits[0];

            digits.RemoveAt(0);

            //Второе введенное число
            var digitTwo = digits[0];

            digits.RemoveAt(0);

            //Время затрачиваемое при работе алгоритма Евклида
            TimeSpan euclideanTime;

            //Время затрачиваемое при работе бинарного алгоритма Евклида
            TimeSpan binaryEuclideanTime;

            var euclideanGCD       = GCDFinder.EuclideanAlg(digitOne, digitTwo, out euclideanTime, digits.ToArray());
            var binaryEuclideanGCD = GCDFinder.BinaryEuclideanAlg(digitOne, digitTwo, out binaryEuclideanTime, digits.ToArray());

            Console.WriteLine("{0,-20}\t{1,-20}\t{2}", "Алгоритм", "НОД", "Время");
            Console.WriteLine("{0,-20}\t{1,-20}\t{2} мс", "Евклид", euclideanGCD, euclideanTime.TotalMilliseconds);
            Console.WriteLine("{0,-20}\t{1,-20}\t{2} мс", "Стейна", binaryEuclideanGCD, binaryEuclideanTime.TotalMilliseconds);
            Console.WriteLine("Разница по времени: {0} мс", Math.Abs(euclideanTime.TotalMilliseconds - binaryEuclideanTime.TotalMilliseconds));
        }
Example #5
0
 public void GetGCDBySteinsAlgorithmTest_InvalidNumberOfParameters_ArgumentException(params int[] args)
 => Assert.Throws <ArgumentException>(() => GCDFinder.GetGCDBySteinsAlgorithm(out _, args));
Example #6
0
 public int GetGCDBySteinsAlgorithmTest_NegativeNumbers(params int[] args)
 => GCDFinder.GetGCDBySteinsAlgorithm(out _, args);
Example #7
0
 public int GetGCDBySteinsAlgorithmTest_Zeros(params int[] args)
 => GCDFinder.GetGCDBySteinsAlgorithm(out _, args);
 public int BinaryGcdAlgorithmTest(params int[] numbers)
 => GCDFinder.BinaryGcdAlgorithm(numbers);
 public void EuclideanGCD_ManyArgs_MinIntValue(params int[] numbers)
 => Assert.Throws <OverflowException>(() => GCDFinder.EuclideanGCD(numbers));
 public int EuclideanGCD_ManyArgs_TimeTest(params int[] numbers)
 {
     (int result, TimeSpan time) = GCDFinder.EuclideanGCD(numbers);
     Debug.WriteLine("Time required: " + time.Ticks); //Time required: 4602
     return(result);
 }
 public int EuclideanGCD_2Args_IsCorrect(int firstNumber, int secondNumber)
 {
     (int result, _) = GCDFinder.EuclideanGCD(firstNumber, secondNumber);
     return(result);
 }
 public void ArgumentNullException_GCDSteinTest()
 {
     Assert.Throws <ArgumentNullException>(() => { GCDFinder.FindGCDwithStein(null); });
 }
 public void NegativeContainingSequences_GCDSteinTests(int[] numbers, int expectedResult)
 {
     Assert.AreEqual(expectedResult, GCDFinder.FindGCDwithStein(numbers));
 }
 public void ArgumentNullException_GCDEuclidTest()
 {
     Assert.Throws <ArgumentNullException>(() => { GCDFinder.FindGCDwithEuclid(null); });
 }
 public void ZeroContainingSequences_GCDEuclidTests(int[] numbers, int expectedResult)
 {
     Assert.AreEqual(expectedResult, GCDFinder.FindGCDwithEuclid(numbers));
 }
 public void NotEnoughNumbers_GCDSteinTest(int[] numbers)
 {
     Assert.Throws <ArgumentException>(() => { GCDFinder.FindGCDwithStein(numbers); });
 }
 public void SteinGCD_2Args_MinIntValue(int firstNumber, int secondNumber)
 => Assert.Throws <OverflowException>(() => GCDFinder.SteinGCD(firstNumber, secondNumber));
Example #18
0
 public int GetGCDByEuclideanAlgorithmTest_PositiveNumbers(int[] args)
 => GCDFinder.GetGCDByEuclideanAlgorithm(out _, args);
 public int EuclideanGCD_ManyArgs_IsCorrect(params int[] numbers)
 {
     (int result, _) = GCDFinder.EuclideanGCD(numbers);
     return(result);
 }
Example #20
0
 public int GetGCDByEuclideanAlgorithmTest_Zeros(params int[] args)
 => GCDFinder.GetGCDByEuclideanAlgorithm(out _, args);
 public void EuclideanGCD_3Args_MinIntValue(int firstNumber, int secondNumber, int thirdNumber)
 => Assert.Throws <OverflowException>(() => GCDFinder.EuclideanGCD(firstNumber, secondNumber, thirdNumber));
Example #22
0
 public void GetGCDByEuclideanAlgorithmTest_NullArgs_ArgumentNullException()
 => Assert.Throws <ArgumentNullException>(() => GCDFinder.GetGCDByEuclideanAlgorithm(out _, null));
 public int SteinGCD_3Args_IsCorrect(int firstNumber, int secondNumber, int thirdNumber)
 {
     (int result, _) = GCDFinder.SteinGCD(firstNumber, secondNumber, thirdNumber);
     return(result);
 }
 public int EuclidGcdAlgorithmTest(params int[] numbers)
 => GCDFinder.EuclidGcdAlgorithm(numbers);