public void ComputeStatsForAllSolutions_WithInvalidPuzzles_ReturnsNoSolutions(int?[][] matrix) { var puzzle = new Puzzle(matrix); var solver = new PuzzleSolver <Puzzle>( new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() }); Assert.Equal(0, solver.ComputeStatsForAllSolutions(puzzle).NumSolutionsFound); }
public void ComputeStatsForAllSolutions_ReturnsExpectedNumSolutions(int?[][] matrix, SolveStats expectedStats) { var solver = new PuzzleSolver <Puzzle>( new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() }); Assert.Equal( expectedStats.NumSolutionsFound, solver.ComputeStatsForAllSolutions(new Puzzle(matrix)).NumSolutionsFound); }
public void ComputeStatsForAllSolutions_WithoutHeuristics_ReturnsExpectedResults( int?[][] matrix, SolveStats expectedStats) { // Skip heuristics so the stats are easy to fully define. var ruleKeeper = new StandardRuleKeeper(); var solver = new PuzzleSolver <PuzzleWithPossibleValues>(ruleKeeper); Assert.Equal(expectedStats, solver.ComputeStatsForAllSolutions(new PuzzleWithPossibleValues(matrix))); }
public void ComputeStatsForAllSolutions_WithHeuristics_ReturnsExpectedNumSolutions( int?[][] matrix, SolveStats expectedStats) { var ruleKeeper = new StandardRuleKeeper(); IRule rule = ruleKeeper.GetRules()[0]; var heuristics = new StandardHeuristic( (IMissingRowValuesTracker)rule, (IMissingColumnValuesTracker)rule, (IMissingBoxValuesTracker)rule); var solver = new PuzzleSolver <PuzzleWithPossibleValues>(ruleKeeper, heuristics); Assert.Equal( expectedStats.NumSolutionsFound, solver.ComputeStatsForAllSolutions(new PuzzleWithPossibleValues(matrix)).NumSolutionsFound); }