Example #1
0
        public static void Test()
        {
            Console.WriteLine();
            Console.WriteLine("Алгоритм Евклида поиска НОД");
            var a = 1234567890;
            var b = 12;

            Console.WriteLine("Тестируется поиск НОД между " + a + " и " + b);

            int temp      = 0;
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            temp = Evklid.Subtraction(a, b);             //1a
            var elapsed_time = stopwatch.ElapsedMilliseconds;

            stopwatch.Stop();
            Console.WriteLine("Задание 1а результат: " + temp + ". Время на выполнение:" + elapsed_time + "ms.");

            stopwatch.Reset();
            stopwatch.Start();
            temp         = Evklid.Division(a, b);        //1b
            elapsed_time = stopwatch.ElapsedMilliseconds;
            stopwatch.Stop();
            Console.WriteLine("Задание 1b результат: " + temp + ". Время на выполнение:" + elapsed_time + "ms.");
        }
Example #2
0
        static void Main(string[] args)
        {
            long a;

            do
            {
                Console.WriteLine("Введите число a:");
            }while (!Int64.TryParse(Console.ReadLine(), out a));

            long b;

            do
            {
                Console.WriteLine("Введите число b:");
            }while (!Int64.TryParse(Console.ReadLine(), out b));
            long time;

            Console.WriteLine(Evklid.Gcd(a, b, out time));
            Console.WriteLine("Затраченное время на Gcd - " + time.ToString());
            Console.WriteLine(Evklid.BinaryGcd(a, b, out time));
            Console.WriteLine("Затраченное время на GcdBinary - " + time.ToString());
            Console.WriteLine(Evklid.GcdMany(out time, 150586, 4548595, 90012522, 7525482, -5, 1055842554, 15025485));
            Console.WriteLine("Затраченное время на GcdMany - " + time.ToString());
            Console.ReadLine();
        }
Example #3
0
        public void Gcd_140and70_70()
        {
            long time;
            long number = Evklid.Gcd(140, 70, out time);

            Assert.AreEqual(number, 70);
            Assert.AreEqual(time, 0);
        }
        public void TestFindNODBinar()
        {
            int[] arr      = { 116150, 232704 };
            int   result   = Evklid.FindNodBinar(arr);
            int   expected = 202;

            Assert.AreEqual(expected, result);
        }
        public void TestFindNod()
        {
            int[] arr      = { 48, 30, 18 };
            int   result   = Evklid.FindNod(arr);
            int   expected = 6;

            Assert.AreEqual(expected, result);
        }
Example #6
0
        public void BinaryGcd_10and20_10()
        {
            //arrange
            var expected = 10L;
            var time     = 0L;

            //act
            var actual = Evklid.BinaryGcd(10, 20, out time);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, time, 1);
        }
Example #7
0
        public void BinaryGcd_0and15_15()
        {
            //arrange
            var expected = 15L;
            var time     = 0L;

            //act
            var actual = Evklid.BinaryGcd(0, 15, out time);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, time, 1);
        }
Example #8
0
        public void BinaryGcd_70and140_70()
        {
            //arrange
            var expected = 70L;
            var time     = 0L;

            //act
            var actual = Evklid.BinaryGcd(70, 140, out time);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, time, 1);
        }
Example #9
0
        public void GcdMany_10and15and20and25and50and100_5()
        {
            //arrange
            var expected = 5L;
            var time     = 0L;

            //act
            var actual = Evklid.GcdMany(out time, 10, 15, 20, 25, 50, 100);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, time, 1);
        }
Example #10
0
        public void BinaryGcd_minus20and31_1()
        {
            //arrange
            var expected = 1L;
            var time     = 0L;

            //act
            var actual = Evklid.BinaryGcd(-20, 31, out time);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, time, 1);
        }
Example #11
0
        public void BinaryGcd_31and16_1()
        {
            //arrange
            var expected = 1L;
            var time     = 0L;

            //act
            var actual = Evklid.BinaryGcd(31, 16, out time);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, time, 1);
        }
Example #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length < 1 && textBox2.Text.Length < 1)
            {
                MessageBox.Show("Введите числа a и b");
            }
            long timeGcd;
            long timeGcdBinary;
            long timeGcdMany;

            string[] data = richTextBox1.Text.Split(',').ToArray();

            long[] datalong = data.Select(x => Int64.Parse(x)).ToArray();
            textBox3.Text = Evklid.Gcd(Convert.ToInt64(textBox2.Text), Convert.ToInt64(textBox1.Text), out timeGcd).ToString();
            textBox4.Text = Evklid.BinaryGcd(Convert.ToInt64(textBox2.Text), Convert.ToInt64(textBox1.Text), out timeGcdBinary).ToString();
            textBox5.Text = Evklid.GcdMany(out timeGcdMany, datalong).ToString();

            chart1.Series["Execution Time"].Points.AddXY("Gcd", timeGcd);
            chart1.Series["Execution Time"].Points.AddXY("GcdMany", timeGcdMany);
            chart1.Series["Execution Time"].Points.AddXY("GcdBinary", timeGcdBinary);
        }