public SolutionEquation Execute(double a, double b, double c)
        {
            if (a == 0)
            {
                if (b == 0)
                {
                    return(SolutionEquation.CreateInfinityCountSolutions());
                }
                return(SolutionEquation.CreateSolutions(-c / b));
            }

            var descrimenant = b * b - 4 * a * c;

            if (descrimenant < 0)
            {
                return(SolutionEquation.CreateWithoutSolutions());
            }

            if (descrimenant == 0)
            {
                return(SolutionEquation.CreateSolutions(-b / (2 * a)));
            }

            var sqrtDescrimenant = Math.Sqrt(descrimenant);

            var x1 = (-b - sqrtDescrimenant) / (2 * a);
            var x2 = (-b + sqrtDescrimenant) / (2 * a);

            return(SolutionEquation.CreateSolutions(x1, x2));
        }
Ejemplo n.º 2
0
        public void GetViewSolution_OneSolutions_CorrectPartView()
        {
            // arrange
            var x = 1;
            var paramsEquation = new ParamsEquation(0, 0, 0);
            var s = SolutionEquation.CreateSolutions(x);

            // act
            var view = paramsEquation.GetViewSolution(s);

            // assert
            Assert.IsTrue(view.Contains(paramsEquation.ToString()));
            Assert.IsTrue(view.Contains($"один корень: x = {x}"));
        }
Ejemplo n.º 3
0
        public void GetViewSolution_TwoSolutions_CorrectPartView()
        {
            // arrange
            var x1             = 1;
            var x2             = 2;
            var paramsEquation = new ParamsEquation(0, 0, 0);
            var s = SolutionEquation.CreateSolutions(x1, x2);

            // act
            var view = paramsEquation.GetViewSolution(s);

            // assert
            Assert.IsTrue(view.Contains(paramsEquation.ToString()));
            Assert.IsTrue(view.Contains($"два корня: x1 = {x1}, x2 = {x2}"));
        }