Exemple #1
0
        public static void VerifySolutionAndPerformance(this IProjectEulerProblem problem)
        {
            if (problem.ExpectedSolution == null)
            {
                return;
            }

            problem
            .SolutionShouleBe(problem.ExpectedSolution)
            .SolveTimeShouldBeLessThan((problem.Benchmark * 1.1 + 5).ToLong());
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 public static string GetName(this IProjectEulerProblem problem) => problem.GetType().Name;