[Test]                                     // bir methodun test methodu olabilmesi için Test attribute'dan beslenmesi(süslenmesi) lazım.
        public void ToplaMethoduCalisiyormu_Test() // Test methodunun isimlendirilmesi önemlidir. Gereksinim neyse onun adı_Test -> isimlendirme standardı
        {
            // Arrange
            Random random   = new Random(); // burada ihtiyacımız olan değişkenleri tanımladık.
            int    x        = random.Next(3, 50);
            int    y        = random.Next(5, 30);
            int    beklenen = x + y; // beklediğimiz sonucu oluşturduk.

            // Act
            FirstMethod method    = new FirstMethod();  // test edeceğimiz class'ı çağırdık
            int         testSonuc = method.Topla(x, y); // burada gerçekleşecek olan sonucu istedik.

            // Assert
            Assert.AreEqual(beklenen, testSonuc, "{0} + {1} = {2} olmalıdır ", x, y, beklenen); // İstediğimiz sonuç şu -> beklenen değer ile (ilk parametre) gerçekleşen değer (ikinci parametre) birbirine eşit olması.
                                                                                                // verdiğimiz 3. parametre test fail olursa gösterilecek olan mesajdır.
                                                                                                // AreNotEqual -> bu method istediğimiz değer dışında bir şey olursa testi başarıyla sonuçlandırır. '!=' düşünebiliriz.
                                                                                                // AreSame  -> AreEqual değerlerinin aynı olmasına bakarken, are same referanslarının aynı olmasına bakar.
                                                                                                // AreNotSame -> bu ise AreNotEqual gibidir. Referansları eşit değilse test başarılı geçer.
                                                                                                // Inonclusive -> test başarılı fakat yeterli değil anlamındadır.
                                                                                                // IsInstanceOfType -> belirttiğimiz değerin o tipte olup olmadığına bakar --> Assert.IsInstanceOfType(beklenen,typeof(string))
                                                                                                // IsNotInstanceOfType -> belirttiğin değer beklediğin tipte değilse test başarılı olur.
                                                                                                // IsNull           -> dönen değer eğer 'null' boş ise test başarıyla sonuçlanır.
                                                                                                // IsNotNull        -> dönen değer null değilse test başarıyla sonuçlanır.
                                                                                                // Fail             -> belli bir şartta testin fail olmasını istersek bu methodu kullanıyoruz.
        }
示例#2
0
        static void UseHeuristicAlgorithm(FirstMethod firstMethod, List <Point> points, List <int> tList)
        {
            HeuristicAlgorithm heuristicAlgorithm = new HeuristicAlgorithm(firstMethod, points);

            heuristicAlgorithm.T = tList;
            heuristicAlgorithm.RunHeuristicAlgorithm();
            Console.WriteLine("-------------------------------------------------------");
        }
示例#3
0
        public void Generator_ForSequence2()
        {
            int[] expected = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
            var   method   = new FirstMethod();

            int[] actual = Generator.GenerateSequence(11, 1, 2, method).ToArray();

            Assert.AreEqual(expected, actual);
        }
        public void CarpMethoduCalisiyormu_Test()
        {
            Random random   = new Random();
            int    x        = random.Next(3, 50);
            int    y        = random.Next(5, 30);
            int    beklenen = x * y * 2; // beklenen değer

            FirstMethod firstMethod = new FirstMethod();
            int         testSonuc   = firstMethod.Carp(x, y);

            Assert.AreNotEqual(beklenen, testSonuc); // beklediğimiz değer ile sonuc değeri birbirine eşit olmadığı için test başarıyla sonuçlandı.
        }
        public HeuristicAlgorithm(FirstMethod firstMethod, IEnumerable <Point> points)
        {
            this.points = points.ToList();
            switch (firstMethod)
            {
            case FirstMethod.First:
                firstZ = points.ElementAt(0);
                break;

            case FirstMethod.Last:
                firstZ = points.Last();
                break;

            case FirstMethod.Random:
                firstZ = points.ElementAt(new Random().Next(0, points.Count()));
                break;

            default:
                throw new InvalidOperationException();
            }
        }
示例#6
0
        private void rButton1_Click(object sender, EventArgs e)
        {
            tabControl1.TabPages[1].Enabled = false;
            tabControl1.TabPages[2].Enabled = false;

            if (sRun)
            {
                sRun = false;
                super.Abort();
                rButton1.Text = "запуск";

                tabControl1.TabPages[1].Enabled = true;
                tabControl1.TabPages[2].Enabled = true;

                return;
            }

            sRun          = true;
            rButton1.Text = "cтоп";

            mainChart.ChartAreas[0].AxisX.Title = "x";
            mainChart.ChartAreas[0].AxisY.Title = "u";

            super = new Thread(() =>
            {
                double u0  = Convert.ToDouble(u0TextBox1.Text.Replace('.', ','));
                double h   = Convert.ToDouble(hTextBox1.Text.Replace('.', ','));
                int n      = Convert.ToInt32(nTextBox1.Text.Replace('.', ','));
                double eps = Convert.ToDouble(epsTextBox1.Text.Replace('.', ','));
                double rb  = Convert.ToDouble(rbTextBox1.Text.Replace('.', ','));

                bool ctrl = !checkBox1.Checked;

                FirstMethod m = new FirstMethod((x, u) => (-1) * 5 / 2 * u, 0, u0, h, eps, ctrl);

                mainChart.Invoke(new Action(() => {
                    mainChart.Series["Численное решение"].Points.Clear();
                    mainChart.Series["Точное решение"].Points.Clear();


                    chart1.Series["h"].Points.Clear();
                }));

                ++nums;
                info             = new DotForm();
                info.label1.Text = "Запуск номер" + nums + "; Метод 2";



                minDot = double.MaxValue;
                maxDot = double.MinValue;

                double minStep = double.MaxValue;
                double mns     = 0;

                double maxStep = double.MinValue;
                double mxs     = 0;

                double maxDiff = 0;
                double mxd     = 0;

                int count = 0;
                Dot p     = null;

                double maxOLP = 0;

                foreach (var i in Enumerable.Range(0, n))
                {
                    double step = m.Step;
                    p           = m.nextStep(out double contr, out double olp);
                    if (Math.Abs(p.Y) < 1e-8)
                    {
                        p.Y = 0;
                    }
                    if (Math.Abs(p.Y) > 10e+20)
                    {
                        break;
                    }
                    if (Math.Abs(p.X) < 1e-8)
                    {
                        p.X = 0;
                    }
                    if (Math.Abs(p.X) > 10e+20)
                    {
                        break;
                    }

                    mainChart.Invoke(new Action(() =>
                    {
                        mainChart.Series["Численное решение"].Points.AddXY(p.X, p.Y);
                        chart1.Series["h"].Points.AddXY(i, step);
                    }));

                    Console.WriteLine(p.X + " " + p.Y);

                    mainChart.Invoke(new Action(() =>
                    {
                        info.dataGridView1.Rows.Add(i + "", p.Y, contr, olp, step, m.C1, m.C2, u0 * Math.Exp(-5 / 2 * p.X), Math.Abs(u0 * Math.Exp(-5 / 2 * p.X) - p.Y));
                    }));

                    if (minDot > p.Y)
                    {
                        minDot = p.Y;
                    }

                    if (maxDot < p.Y)
                    {
                        maxDot = p.Y;
                    }

                    if (p.X > rb)
                    {
                        break;
                    }

                    if (maxOLP < Math.Abs(olp))
                    {
                        maxOLP = Math.Abs(olp);
                    }

                    if (step > maxStep)
                    {
                        maxStep = step;
                        mxs     = p.X;
                    }

                    if (step < minStep)
                    {
                        minStep = step;
                        mns     = p.X;
                    }

                    if (maxDiff < Math.Abs(u0 * Math.Exp(-5 / 2 * p.X) - p.Y))
                    {
                        maxDiff = Math.Abs(u0 * Math.Exp(-5 / 2 * p.X) - p.Y);
                        mxd     = p.X;
                    }

                    count++;
                }

                mainChart.Invoke(new Action(() =>
                {
                    correctAxis(rb, minDot - 0.01, maxDot + 0.01);
                    info.param.Text = $"n = : {count}, \nb-Xn: {rb - p.X}, \nmaxOLP: {maxOLP}, \nC1: {m.C1}, \nC2: {m.C2}, \nmax Hi: {maxStep} -> x: {mxs}, \nmin Hi: {minStep} -> x: {mns}, \nMaxDiff: {maxDiff} -> x: {mxd}";

                    info.Show();

                    sRun          = false;
                    rButton1.Text = "запуск";

                    tabControl1.TabPages[1].Enabled = true;
                    tabControl1.TabPages[2].Enabled = true;
                }));
            });

            super.Start();
        }
示例#7
0
        private void rButton1_Click(object sender, EventArgs e)
        {
            ++chartCount;
            string chartName = "Численное решение №" + chartCount;
            var    settings  = mainChart.Series.Add(chartName);

            settings.ChartType = SeriesChartType.Line;

            if (sRun)
            {
                sRun = false;
                super.Abort();
                rButton1.Text = "запуск";
                return;
            }

            sRun          = true;
            rButton1.Text = "cтоп";

            mainChart.ChartAreas[0].AxisX.Title = "x";
            mainChart.ChartAreas[0].AxisY.Title = "u";

            super = new Thread(() =>
            {
                double u0  = Convert.ToDouble(u0TextBox1.Text.Replace('.', ','));
                double h   = Convert.ToDouble(hTextBox1.Text.Replace('.', ','));
                int n      = Convert.ToInt32(nTextBox1.Text.Replace('.', ','));
                double eps = Convert.ToDouble(epsTextBox1.Text.Replace('.', ','));
                double rb  = Convert.ToDouble(rbTextBox1.Text.Replace('.', ','));

                double r = Convert.ToDouble(rTextBox1.Text.Replace('.', ','));
                double l = Convert.ToDouble(lTextBox1.Text.Replace('.', ','));
                double v = Convert.ToDouble(vTextBox1.Text.Replace('.', ','));

                double param = Convert.ToDouble(paramTextBox.Text.Replace('.', ','));

                bool ctrl = !checkBox1.Checked;

                FirstMethod m = new FirstMethod((x, u) => (-r * u / l) + (v / l), 0, u0, h, eps, ctrl);

                mainChart.Invoke(new Action(() => {
                    mainChart.Series[chartName].Points.Clear();
                    //chart1.Series["h"].Points.Clear();
                }));

                ++nums;
                info             = new DotForm();
                info.label1.Text = "Запуск номер " + nums + ";";



                minDot = double.MaxValue;
                maxDot = double.MinValue;

                double minStep = double.MaxValue;
                double mns     = 0;

                double maxStep = double.MinValue;
                double mxs     = 0;

                double maxDiff = 0;
                double mxd     = 0;

                int count = 0;
                Dot p     = null;

                double maxOLP = 0;

                foreach (var i in Enumerable.Range(0, n))
                {
                    double step = m.Step;
                    p           = m.nextStep(out double contr, out double olp);
                    if (Math.Abs(p.Y) < 1e-8)
                    {
                        p.Y = 0;
                    }
                    if (Math.Abs(p.Y) > 10e+20)
                    {
                        break;
                    }
                    if (Math.Abs(p.X) < 1e-8)
                    {
                        p.X = 0;
                    }
                    if (Math.Abs(p.X) > 10e+20)
                    {
                        break;
                    }

                    mainChart.Invoke(new Action(() =>
                    {
                        mainChart.Series[chartName].Points.AddXY(p.X, p.Y);
                        //chart1.Series["h"].Points.AddXY(i, step);
                    }));

                    Console.WriteLine(p.X + " " + p.Y);

                    mainChart.Invoke(new Action(() =>
                    {
                        info.dataGridView1.Rows.Add(i + "", p.X, p.Y, contr, olp, step, m.C1, m.C2, CurFunction(u0, v, r, l, p.X), Math.Abs(CurFunction(u0, v, r, l, p.X) - p.Y));
                    }));

                    if (minDot > p.Y)
                    {
                        minDot = p.Y;
                    }

                    if (maxDot < p.Y)
                    {
                        maxDot = p.Y;
                    }

                    if (p.X >= rb - param && p.X <= rb)
                    {
                        break;
                    }

                    if (p.X + m.Step > rb)
                    {
                        while (p.X + m.Step > rb)
                        {
                            m.Step /= 2;
                        }
                    }

                    if (maxOLP < Math.Abs(olp))
                    {
                        maxOLP = Math.Abs(olp);
                    }

                    if (step > maxStep)
                    {
                        maxStep = step;
                        mxs     = p.X;
                    }

                    if (step < minStep)
                    {
                        minStep = step;
                        mns     = p.X;
                    }

                    if (maxDiff < Math.Abs(CurFunction(u0, v, r, l, p.X) - p.Y))
                    {
                        maxDiff = Math.Abs(CurFunction(u0, v, r, l, p.X) - p.Y);
                        mxd     = p.X;
                    }

                    count++;
                }

                mainChart.Invoke(new Action(() =>
                {
                    correctAxis(rb, minDot - 0.01, maxDot + 0.01);
                    info.param.Text = $"Номер шага = : {count}, \nРасстояние до правой границы: {rb - p.X}, \nМаксимальная оценка локальной погрешности (ОЛП): {maxOLP}, \nКоличество делений шага: {m.C1}, \nКоличество удвоений шага: {m.C2}, \nМаксимальный шаг: {maxStep}, достигнут в точке: {mxs}, \nМинимальный шаг: {minStep} , достигнут в точке: {mns}, \nМаксимальное расстояние до функции: {maxDiff}, в точке: {mxd}";

                    info.Show();

                    sRun          = false;
                    rButton1.Text = "запуск";
                }));
            });

            super.Start();
        }