Exemple #1
0
        public void ThreeCoefficients_shouldBeEqualTheRightDescriminant()
        {
            var coef     = new int[] { 1, 2, 3 };
            var expected = -8;

            var discriminant = EquationsSolver.FindDescriminant(coef);

            Assert.AreEqual(expected, discriminant);
        }
Exemple #2
0
        public void Descriminant_shouldHaveRightTypeOfDescriminant_3()
        {
            int descriminant = 0;
            int expected     = 1;

            int typeOfDesc = EquationsSolver.DescriminantValidation(descriminant);

            Assert.AreEqual(typeOfDesc, expected);
        }
        public void QuadraticEquation_shouldBeCorrect_2()
        {
            string equation = "12x^2-16y-27=0";
            bool   expected = false;

            bool validationResult = EquationsSolver.ValidationOfEquation(equation);

            Assert.AreEqual(expected, validationResult);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string equation;
            string solveTheNextEquation = "next";

            while (solveTheNextEquation.Equals("next"))
            {
                solveTheNextEquation = "-";
                Console.Write("Введите квадратное уравнение в виде ax^2+bx+c=0 : ");
                equation = Console.ReadLine();
                if (EquationsSolver.ValidationOfEquation(equation))
                {
                    int[] coefficient = EquationsSolver.ParseString(equation);

                    if (coefficient[0] != 0)
                    {
                        int      descriminant = EquationsSolver.FindDescriminant(coefficient);
                        int      typeOfDesc   = EquationsSolver.DescriminantValidation(descriminant);
                        string   stringAnswer = EquationsSolver.CalculatingAnswer(typeOfDesc, descriminant, coefficient);
                        string[] answer       = EquationsSolver.OutputOfAnswer(stringAnswer);

                        if (typeOfDesc == 0)
                        {
                            Console.WriteLine("Нет корней.");
                        }
                        else if (typeOfDesc == 1)
                        {
                            Console.WriteLine("\nУравнение имеет два одинаковых корня : ");
                        }
                        else if (typeOfDesc == 2)
                        {
                            Console.WriteLine("\nУравнение имеет два различных корня : ");
                        }

                        if (!answer[0].Equals("_") && !answer[1].Equals("_"))
                        {
                            Console.WriteLine("\nПервый корень = " + answer[0]);
                            Console.WriteLine("Второй корень = " + answer[1]);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Вы ввели не квадратное уравнение!");
                    }
                }
                else
                {
                    Console.WriteLine("Вы ввели уравнение неверно!");
                }
                Console.WriteLine("\nДля решения следующего уравнения введите 'next'");
                solveTheNextEquation = Console.ReadLine();
            }
            Console.ReadKey();
        }
        public void Equation_shouldBeEqualRightAnswer()
        {
            string equation = "4x^2+6x+2=0";

            int[]  coef     = new int[] { 4, 6, 2 };
            string expected = "-0,5 -1";

            string answer = EquationsSolver.CalculatingAnswer
                                (EquationsSolver.DescriminantValidation(EquationsSolver.FindDescriminant(coef)),
                                EquationsSolver.FindDescriminant(coef), EquationsSolver.ParseString(equation));

            Assert.AreEqual(expected, answer);
        }
        public void Equation_shouldGiveRightArguments_5()
        {
            string equation = "19x^2+0x-22=0";

            int[] expected = { 19, 0, -22 };

            int[] coef = EquationsSolver.ParseString(equation);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(expected[i], coef[i]);
            }
        }
        public void Equation_shouldGiveRightArguments_3()
        {
            string equation = "2x^2+7x-0=0";

            int[] expected = { 2, 7, 0 };

            int[] coef = EquationsSolver.ParseString(equation);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(expected[i], coef[i]);
            }
        }