public void Run()
        {
            //DynamicStrategyDemo();

            //var tp = new TextProcessorStatic<HtmlListStrategy>();
            //tp.AppendList(new[] { "foo", "bar", "baz" });
            //Console.WriteLine(tp);

            var solver = new QuadraticEquationSolver(new RealDiscriminantStrategy());

            var solution = solver.Solve(1, 4, 5);

            var solution2 = solver.Solve(1, 10, 16);
        }
Exemplo n.º 2
0
        public void FunctionalTest()
        {
            //Creating a loop (for) to generate more situations
            //Создадим цикл, чтобы сгенерировать больше ситуаций
            for (int i = 0; i < 100; i++)
            {
                var rnd = new Random();

                //Initialize random value for coefficients of double variable type
                //Инициализируем случайные значения типа Double для переменных (коэффициентов)
                var a = rnd.NextDouble() * 100;
                var b = rnd.NextDouble() * 100;
                var c = rnd.NextDouble() * 100;

                //Solving the equation with random coefficients
                //Решаем уравнение со случайными коэффициентами
                var result = QuadraticEquationSolver.Solve(a, b, c);

                //Checking the quadratic equation solver, which should be zero
                //Подставляем корни в квадратичное уравнение, которое должно быть равно 0
                foreach (var x in result)
                {
                    Assert.AreEqual(0, a * x * x + b * x + c, 1e-10);
                    //Take into account a certain interval
                    //Учитываем не строгое равенство, а близость на таком промежутке 1е-10
                }
            }
        }
Exemplo n.º 3
0
            public void NegativeTestOrdinaryStrategy()
            {
                var strategy = new OrdinaryDiscriminantStrategy();
                var solver   = new QuadraticEquationSolver(strategy);
                var results  = solver.Solve(1, 4, 5);

                Assert.That(results.Item1, Is.EqualTo(new Complex(-2, 1)));
                Assert.That(results.Item2, Is.EqualTo(new Complex(-2, -1)));
            }
Exemplo n.º 4
0
            public void PositiveTestRealStrategy()
            {
                var strategy = new RealDiscriminantStrategy();
                var solver   = new QuadraticEquationSolver(strategy);
                var results  = solver.Solve(1, 10, 16);

                Assert.That(results.Item1, Is.EqualTo(new Complex(-2, 0)));
                Assert.That(results.Item2, Is.EqualTo(new Complex(-8, 0)));
            }
Exemplo n.º 5
0
 public void TwoRoots()
 {
     // arrange
     var(rootX1, rootX2) = (3.0, -1.0);
     // act
     var(x1, x2) = QuadraticEquationSolver.Solve(1.0, -2.0, -3.0);
     // assert
     Assert.AreEqual(rootX1, x1);
     Assert.AreEqual(rootX2, x2);
 }
Exemplo n.º 6
0
        void Test(double a, double b, double c, params double[] expectedResult)
        {
            var result = QuadraticEquationSolver.Solve(a, b, c);

            Assert.AreEqual(expectedResult.Length, result.Length);
            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(expectedResult[i], result[i]);
            }
        }
Exemplo n.º 7
0
        public void AllCoefficientsAreZero()
        {
            // arrange
            var(rootX1, rootX2) = (double.NaN, double.NaN);

            // act
            var(x1, x2) = QuadraticEquationSolver.Solve(0.0, 0.0, 0.0);

            // assert
            //result roots are same x1 == x2
            Assert.AreEqual(double.IsNaN(rootX1), double.IsNaN(x1));
            Assert.AreEqual(double.IsNaN(rootX2), double.IsNaN(x2));
        }
Exemplo n.º 8
0
        public void FirstCoefficientIsZeroSecondIsNegative()
        {
            // arrange
            var(rootX1, rootX2) = (double.PositiveInfinity, double.NaN);

            // act
            var(x1, x2) = QuadraticEquationSolver.Solve(0.0, -2.0, 3.0);

            // assert
            //result roots are same x1 == x2
            Assert.AreEqual(double.IsInfinity(rootX1), double.IsInfinity(x1));
            Assert.AreEqual(double.IsNaN(rootX2), double.IsNaN(x2));
        }
Exemplo n.º 9
0
        public void NoRoots()
        {
            // arrange
            var(rootX1, rootX2) = (double.NaN, double.NaN);

            // act
            var(x1, x2) = QuadraticEquationSolver.Solve(5.0, 2.0, 3.0);

            // assert
            //result roots are same x1 == x2
            Assert.AreEqual(double.IsNaN(rootX1), double.IsNaN(x1));
            Assert.AreEqual(double.IsNaN(rootX2), double.IsNaN(x2));
        }
Exemplo n.º 10
0
        //result roots are same x1 == x2
        public void OneRoot()
        {
            // arrange
            var(rootX1, rootX2) = (-6.0, -6.0);

            // act
            var(x1, x2) = QuadraticEquationSolver.Solve(1.0, 12.0, 36.0);

            // assert
            //result roots are same x1 == x2
            Assert.AreEqual(rootX1, x1);
            Assert.AreEqual(rootX2, x2);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var a = double.Parse(Console.ReadLine());
            var b = double.Parse(Console.ReadLine());
            var c = double.Parse(Console.ReadLine());

            var result = QuadraticEquationSolver.Solve(a, b, c);

            foreach (var response in result)
            {
                Console.WriteLine(response);
            }
        }
Exemplo n.º 12
0
 public void FunctionalTest()
 {
     for (int i = 0; i < 100; i++)
     {
         var rnd    = new Random();
         var a      = rnd.NextDouble() * 10;
         var b      = rnd.NextDouble() * 10;
         var c      = rnd.NextDouble() * 10;
         var result = QuadraticEquationSolver.Solve(a, b, c);
         foreach (var x in result)
         {
             Assert.AreEqual(0, a * x * x + b * x + c, 1e-10);
         }
     }
 }
Exemplo n.º 13
0
        //coefficients A and B is Zero
        //коэффициенты А и В равны нулю

        //Unit test. Accepts coefficient values(A, B, C) ​​and an array of quadratic equation solver
        //Модульное тестирование. Принимает значения коэффициентов(A, B, C) и массив из корней
        public static void TestEquation(double a, double b, double c, params double[] expectedResult)
        {
            var result = QuadraticEquationSolver.Solve(a, b, c);

            //Compare the expected number of solutions with the equations to the actual
            //Сравниваем ожидаемое количество решений уравнения и действительное
            Assert.AreEqual(expectedResult.Length, result.Length);

            //Compare the expected correct decisions to the actual
            //Сравниваем ожидаемые правильные решения и действительное
            for (int index = 0; index < result.Length; index++)
            {
                Assert.AreEqual(expectedResult[index], result[index]);
            }
        }
Exemplo n.º 14
0
            public void NegativeTestRealStrategy()
            {
                var strategy   = new RealDiscriminantStrategy();
                var solver     = new QuadraticEquationSolver(strategy);
                var results    = solver.Solve(1, 4, 5);
                var complexNaN = new Complex(double.NaN, double.NaN);

                Assert.That(results.Item1, Is.EqualTo(complexNaN));
                Assert.That(results.Item2, Is.EqualTo(complexNaN));

                Assert.IsTrue(double.IsNaN(results.Item1.Real));
                Assert.IsTrue(double.IsNaN(results.Item1.Imaginary));
                Assert.IsTrue(double.IsNaN(results.Item2.Real));
                Assert.IsTrue(double.IsNaN(results.Item2.Imaginary));
            }
Exemplo n.º 15
0
        public void FunctionalTest()
        {
            var rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                var a      = rnd.NextDouble() * 10;
                var b      = rnd.NextDouble() * 10;
                var c      = rnd.NextDouble() * 10;
                var result = QuadraticEquationSolver.Solve(a, b, c);
                for (int j = 0; j < result.Length; j++)
                {
                    Assert.AreEqual(0, a * result[j] * result[j] + b * result[j] + c, 10e-6);
                }
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            //Accept values of user coefficients
            //Принимаем значения коэффициентов пользователя
            var a = double.Parse(Console.ReadLine());
            var b = double.Parse(Console.ReadLine());
            var c = double.Parse(Console.ReadLine());

            //Quadratic Equation Solver
            //Решение квадратного уравнения
            var result = QuadraticEquationSolver.Solve(a, b, c);

            //Showing the solution on the console
            //Выводим решение на консоль
            for (int i = 0; i < result.Length; i++)
            {
                Console.WriteLine(result[i]);
            }
        }
Exemplo n.º 17
0
 private static void Main(string[] args)
 {
     var quadraticEquationSolver = new QuadraticEquationSolver();
     var solutions = quadraticEquationSolver.Solve(1, -4, 1);
 }
Exemplo n.º 18
0
 public IQuadraticEquationSolution FindSolutionsInRealNumbers(Delta delta)
 {
     return(QuadraticEquationSolver.Solve(this, delta));
 }