public static void VerifySolutionAndPerformance(this IProjectEulerProblem problem) { if (problem.ExpectedSolution == null) { return; } problem .SolutionShouleBe(problem.ExpectedSolution) .SolveTimeShouldBeLessThan((problem.Benchmark * 1.1 + 5).ToLong()); }
public static TimedResult SolveWithTime(this IProjectEulerProblem problem) { var stopwatch = new Stopwatch(); stopwatch.Start(); var solution = problem.Solve(); stopwatch.Stop(); return(new TimedResult(problem.GetName(), solution, stopwatch.ElapsedMilliseconds)); }
public static TimedResult SolutionShouleBe(this IProjectEulerProblem problem, object expectedSolution) { var result = problem.SolveWithTime(); if (result.Solution is long && expectedSolution is int) { expectedSolution = ((int)expectedSolution).ToLong(); } if (!expectedSolution.Equals(result.Solution)) { throw new Exception($"{result.Name} expected a solution of {expectedSolution}, but returned {result.Solution}."); } Assert.AreEqual(expectedSolution, result.Solution); return(result); }
public static string GetName(this IProjectEulerProblem problem) => problem.GetType().Name;