private SolverState PerformStandardTest( Puzzle puzzle, ExitConditions exit = null, Func <SolverNode, bool>?inspector = null ) { exit = exit ?? new ExitConditions { Duration = TimeSpan.FromSeconds(60), StopOnSolution = true, TotalNodes = int.MaxValue, TotalDead = int.MaxValue }; // arrange var solver = new SingleThreadedForwardReverseSolver(new SolverNodeFactoryTrivial()); var command = new SolverCommand { Puzzle = puzzle.Clone(), Report = new XUnitOutput(outp), ExitConditions = exit, Inspector = inspector }; // act var result = solver.Init(command); solver.Solve(result); Console.WriteLine(result.ExitDescription); Console.WriteLine(SolverHelper.GenerateSummary(result)); result.ThrowErrors(); // assert Assert.NotNull(result); Assert.True(result.HasSolution); Assert.NotNull(result.Solutions); Assert.NotEmpty(result.Solutions); foreach (var sol in result.Solutions) { Console.WriteLine("Path: {0}", sol); string error = null; Assert.True(SolverHelper.CheckSolution(command.Puzzle, sol, out error), "Solution is INVALID! " + error); } return(result); }
private void PuzzleShouldHaveSolution(ISolver solver, Puzzle puzzle, ExitConditions exit = null, bool verbose = false) { if (exit == null) { exit = new ExitConditions { Duration = TimeSpan.FromSeconds(60), StopOnSolution = true, TotalNodes = int.MaxValue, TotalDead = int.MaxValue } } ; var command = new SolverCommand { Puzzle = puzzle, Report = new XUnitOutput(outp), ExitConditions = exit }; // act var result = solver.Init(command); solver.Solve(result); Console.WriteLine(result.ExitDescription); Console.WriteLine(SolverHelper.GenerateSummary(result)); result.ThrowErrors(); // assert Assert.NotNull(result); Assert.NotNull(result.Solutions); Assert.True(result.HasSolution); foreach (var sol in result.Solutions) { string error = null; Assert.True(SolverHelper.CheckSolution(command.Puzzle, sol, out error), "Solution is INVALID! " + error); } }