public void Test_Iterations(int startIteration, int numberOfIterations, double expected) { var pi = new Gregory_Leibniz(); pi.Iterations(startIteration, numberOfIterations); Assert.That(Math.Abs(expected - pi.Calculate()), Is.LessThan(0.000001)); }
public void Test_NumberOfIterations(int iterations, double expectedDifference) { var pi = new Gregory_Leibniz(); pi.NumberOfIterations = iterations; Assert.That(Math.Abs(3.14159265359 - pi.Calculate()), Is.LessThan(expectedDifference)); }
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()); }
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}]"); }