コード例 #1
0
        public void UnitTestSolveDiscriminant()
        {
            SquareEquationService SquareEquationService = new SquareEquationService();

            double D = SquareEquationService.SolveDiscriminant(new SquareEquation {
                a = 1, b = 4, c = 1
            });

            Assert.Equal(D, 12.0);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ISquareEquation       SquareEquation = new SquareEquationService();
            List <SquareEquation> SquareEquationsList;

            string path = @"C:\Users\overl\source\repos\TestSquareExample\TestSquareExample\SquareEquationContent.txt";
            double D;

            SquareEquationsList = SquareEquation.CreateConnectionFile(path);
            try
            {
                foreach (SquareEquation item in SquareEquationsList)
                {
                    D = SquareEquation.SolveDiscriminant(item);

                    if (D > 0)
                    {
                        double[] Root = SquareEquation.SearchRoot(item, D);
                        Console.WriteLine(Root[0] + " " + Root[1]);
                    }
                    else if (D == 0)
                    {
                        double Root = SquareEquation.SearchRoot(item);
                        Console.WriteLine(Root);
                    }
                    else
                    {
                        Console.WriteLine("Never to solve equation");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Empty");
            }
        }