コード例 #1
0
        public void GetStatsForAllSolutions_ReturnsExpectedNumSolutions(Puzzle puzzle, SolveStats expectedStats)
        {
            var solver = new PuzzleSolver <Puzzle>(
                new List <IConstraint> {
                new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint()
            });

            Assert.Equal(expectedStats.NumSolutionsFound, solver.GetStatsForAllSolutions(puzzle).NumSolutionsFound);
        }
コード例 #2
0
        public void GetStatsForAllSolutions_WithoutHeuristics_ReturnsExpectedResults(Puzzle puzzle, SolveStats expectedStats)
        {
            // Skip heuristics so the stats are easy to fully define.
            var possibleValues = new PossibleValues(puzzle);
            var ruleKeeper     = new StandardRuleKeeper(puzzle, possibleValues);
            var solver         = new PuzzleSolver(puzzle, possibleValues, ruleKeeper);

            Assert.Equal(expectedStats, solver.GetStatsForAllSolutions());
        }
コード例 #3
0
        public void GetStatsForAllSolutions_WithHeuristics_ReturnsExpectedNumSolutions(Puzzle puzzle, SolveStats expectedStats)
        {
            var         possibleValues = new PossibleValues(puzzle);
            var         ruleKeeper     = new StandardRuleKeeper(puzzle, possibleValues);
            ISudokuRule rule           = ruleKeeper.GetRules()[0];
            var         heuristics     = new StandardHeuristic(
                puzzle, possibleValues, (IMissingRowValuesTracker)rule,
                (IMissingColumnValuesTracker)rule, (IMissingBoxValuesTracker)rule);
            var solver = new PuzzleSolver(puzzle, possibleValues, ruleKeeper, heuristics);

            Assert.Equal(expectedStats.NumSolutionsFound, solver.GetStatsForAllSolutions().NumSolutionsFound);
        }
コード例 #4
0
        public void Generate_CreatesPuzzleWithUniqueSolution(int size, int numToSet)
        {
            var generator = new StandardPuzzleGenerator(size);

            Puzzle puzzle = generator.Generate(numToSet, TimeSpan.FromSeconds(60));

            Assert.Equal(size * size - numToSet, puzzle.NumEmptySquares);
            var        solver = new PuzzleSolver(puzzle);
            SolveStats stats  = solver.GetStatsForAllSolutions();

            Assert.Equal(1, stats.NumSolutionsFound);
        }
コード例 #5
0
        public void Generate_CreatesPuzzleWithUniqueSolution(int size, int numToSet)
        {
            var generator = new PuzzleGenerator <Puzzle>(
                () => new Puzzle(size),
                new List <IConstraint> {
                new RowUniquenessConstraint(),
                new ColumnUniquenessConstraint(),
                new BoxUniquenessConstraint()
            });

            Puzzle puzzle = generator.Generate(numToSet, TimeSpan.FromSeconds(60));

            Assert.Equal(size * size - numToSet, puzzle.NumEmptySquares);
            var        solver = new PuzzleSolver(puzzle);
            SolveStats stats  = solver.GetStatsForAllSolutions();

            Assert.Equal(1, stats.NumSolutionsFound);
        }