public void TestEuclideanGcdAlgorithm_30_18_42_returned_6()
        {
            var numbers            = new[] { 30, 18, 42 };
            var euclideanAlgorithm = new EuclideanAlgorithm();

            var actual = euclideanAlgorithm.Calculate(numbers).GreatestCommonDivisor;

            Assert.AreEqual(6, actual);
        }
        public void TestEuclideanGcdAlgorithm_GCD()
        {
            var euclideanAlgorithm = new EuclideanAlgorithm();
            var numbers            = new[]
            {
                new[] { 30, 18 },
                new[] { 5, 45 },
                new[] { 18, 30 }
            };

            var expected = new[] { 6, 5, 6 };

            for (var i = 0; i < numbers.Length; i++)
            {
                var actual = euclideanAlgorithm.Calculate(numbers[i]).GreatestCommonDivisor;
                Assert.AreEqual(expected[i], actual);
            }
        }
Пример #3
0
        public BigInteger D()
        {
            if (!P.Equals(null) && !Q.Equals(null))
            {
                EuclideanAlgorithm client = new EuclideanAlgorithm();
                List <BigInteger>  result = client.Calculate(PhiN(), E);
                if (result[1] < 0)
                {
                    result[1] = result[1] + PhiN();
                }

                return(result[1]);
            }
            else
            {
                return(0);
            }
        }
Пример #4
0
        public void Option1()
        {
            EuclideanAlgorithm client = new EuclideanAlgorithm();

            if (!String.IsNullOrWhiteSpace(Number1.Text) && !String.IsNullOrWhiteSpace(Number2.Text))
            {
                BigInteger        A   = BigInteger.Parse(Number1.Text);
                BigInteger        B   = BigInteger.Parse(Number2.Text);
                List <BigInteger> res = client.Calculate(A, B);
                GCD.Text = "" + res[0];
                X.Text   = "" + res[1];
                Y.Text   = "" + res[2];
            }
            else
            {
                Message("Los cuadros de texto de números a comprobar no pueden ser vacíos.", 3);
            }
        }
Пример #5
0
        public static int FindGcdByEuclidean_TwoNumbers_GCD(int val1, int val2)
        {
            IAlgorithm algorithm = new EuclideanAlgorithm();

            return(algorithm.Calculate(val1, val2));
        }