public void validate() { Random r = new Random(); double tol = 0.0001; Squirtulator mySqrt = new Squirtulator(tol); int[] randNums = new int[10000]; for (var i = 0; i < randNums.Length; i++) { randNums[i] = r.Next(100000); if (Math.Round(getSquareRoot(randNums[i]), 3) != Math.Round(mySqrt.getSquareRoot(randNums[i]), 3)) { throw new Exception("Something's fucky!"); } ; } Console.WriteLine("Looks accurate to me!"); }
static void Main(string[] args) { /* * Console.WriteLine("Enter a number to find the square root:"); * double num = double.Parse(Console.ReadLine()); * * Console.WriteLine("Enter an acceptable margin of error:"); * double tolerance = double.Parse(Console.ReadLine()); */ double num = double.Parse(args[0]); double tolerance = double.Parse(args[1]); Squirtulator sq = new Squirtulator(tolerance); double result = sq.getSquareRoot(num); SqrtTest validation = new SqrtTest(); validation.validate(); Console.WriteLine(result); }