示例#1
0
        public void Test_Iterations(int startIteration, int numberOfIterations, double expected)
        {
            var pi = new Nilikantha();

            pi.Iterations(startIteration, numberOfIterations);
            Assert.That(Math.Abs(expected - pi.Calculate()), Is.LessThan(0.000000001));
        }
示例#2
0
        public void Test_NumberOfIterations(int iterations, double expected)
        {
            var pi = new Nilikantha();

            pi.NumberOfIterations = iterations;
            Assert.That(Math.Abs(expected - pi.Calculate()), Is.LessThan(0.000000001));
        }
        public double Get(int iterations, string modelToUse)
        {
            IterativeMethod pi = null;

            switch (modelToUse)
            {
            case "Gregory-Leibniz":
                pi = new Gregory_Leibniz();
                break;

            case "Nilikantha":
                pi = new Nilikantha();
                break;

            default:
                throw new System.Exception($"Could not find [{modelToUse}] model.");
            }
            pi.NumberOfIterations = iterations;
            return(pi.Calculate());
        }
示例#4
0
        static void Run(CalculatePi_CLI_Options options)
        {
            IIterativeMethod pi;

            if (options.Model == "Gregory_Leibniz")
            {
                pi = new Gregory_Leibniz();
            }
            else if (options.Model == "Nilikantha")
            {
                pi = new Nilikantha();
            }
            else
            {
                throw new Exception($"Unknown model [{options.Model}]");
            }
            pi.NumberOfIterations = options.Iterations;
            var result = pi.Calculate();

            Console.WriteLine($"Result = [{result}]");
        }