public void ApplyValidSingleStepSolutionTest() { var sudoku = (int[, ])_sudoku.Clone(); sudoku[4, 7] = 0; var sudokuPuzzle = new SudokuPuzzle(sudoku); var strategyWhichFindsNothing = new NakedTriple(); var strategyWhichReducesCandidates = new BasicElimination(); var strategyWhichFindsResult = new HiddenSingle(); sudokuPuzzle.ApplySingleStepSolution(strategyWhichFindsNothing.SolveSingleStep(sudokuPuzzle)); Assert.That(sudokuPuzzle.Steps, Is.Empty); Assert.That(sudokuPuzzle.NumberOfSteps, Is.Zero); sudokuPuzzle.ApplySingleStepSolution(strategyWhichReducesCandidates.SolveSingleStep(sudokuPuzzle)); Assert.That(sudokuPuzzle.Steps.Count, Is.EqualTo(1)); Assert.That(sudokuPuzzle.NumberOfSteps, Is.EqualTo(1)); Assert.That(sudokuPuzzle.Steps.Last().Strategy, Is.EqualTo(strategyWhichReducesCandidates.StrategyName)); Assert.That(sudokuPuzzle.Steps.Last().SolutionDescription, Is.Not.Empty); sudokuPuzzle.ApplySingleStepSolution(strategyWhichFindsResult.SolveSingleStep(sudokuPuzzle)); Assert.That(sudokuPuzzle.Steps.Count, Is.EqualTo(2)); Assert.That(sudokuPuzzle.NumberOfSteps, Is.EqualTo(2)); Assert.That(sudokuPuzzle.Steps.Last().Strategy, Is.EqualTo(strategyWhichFindsResult.StrategyName)); Assert.That(sudokuPuzzle.Cells[4, 7].Value, Is.EqualTo(5)); Assert.That(sudokuPuzzle.Steps.Last().SolutionDescription, Is.Not.Empty); }
public void UndoSingleStepSolutionsWhichReturnsEliminations_UndoesEliminations_Test() { var sudoku = (int[, ])_sudoku.Clone(); sudoku[4, 7] = 0; var sudokuPuzzle = new SudokuPuzzle(sudoku); var strategyWhichReducesCandidates = new BasicElimination(); sudokuPuzzle.ApplySingleStepSolution(strategyWhichReducesCandidates.SolveSingleStep(sudokuPuzzle)); Assert.That(sudokuPuzzle.Cells[4, 7].CanBe.Single(), Is.EqualTo(5)); var step = sudokuPuzzle.UndoLastSingleStepSolution(); Assert.That(step.Eliminations, Is.Not.Empty); Assert.That(step.Result, Is.Null); Assert.That(step.Strategy, Is.EqualTo(strategyWhichReducesCandidates.StrategyName)); Assert.That(step.SolutionDescription, Is.Not.Empty); CollectionAssert.AreEqual(sudokuPuzzle.Cells[4, 7].CanBe, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); }