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);
        }
예제 #2
0
        public void ForwardReverseSingle()
        {
            var solverCommand = new SolverCommand()
            {
                Puzzle         = Puzzle.Builder.DefaultTestPuzzle(),
                ExitConditions = ExitConditions.Default3Min(),
            };
            var solver      = new SingleThreadedForwardReverseSolver(new SolverNodeFactoryTrivial());
            var solverState = solver.Init(solverCommand);

            solver.Solve(solverState);
            if (!solverState.HasSolution)
            {
                throw new Exception();
            }
        }