public void TrySolve_WithInvalidPuzzle_ReturnsFalse(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); Assert.False(solver.TrySolve(puzzle)); }
public void HasUniqueSolution_WithUniqueSolution_ReturnsTrue(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); Assert.True(solver.HasUniqueSolution(puzzle)); }
public void Solve_WithInvalidPuzzle_Throws(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); Assert.Throws <ArgumentException>(() => solver.Solve(puzzle)); }
public bool SudokuSpice(PuzzleSample puzzle) { var p = new PuzzleWithPossibleValues(puzzle.NullableJaggedMatrix); var solver = StandardPuzzles.CreateSolver(); var result = solver.Solve(p, randomizeGuesses: true); return(result.NumEmptySquares == 0); }
public void Generate_WithShortTimeout_ThrowsTimeoutException() { var generator = new PuzzleGenerator <PuzzleWithPossibleValues>( size => new PuzzleWithPossibleValues(size), StandardPuzzles.CreateSolver()); Assert.Throws <TimeoutException>( () => generator.Generate(16, 150, TimeSpan.FromMilliseconds(1))); }
public void CreateSolver_CanSolveStandardPuzzles(int?[][] matrix) { var solver = StandardPuzzles.CreateSolver(); var solved = solver.Solve(new Puzzle(matrix)); PuzzleTestUtils.AssertStandardPuzzleSolved(solved); }
public void TrySolve_ValidPuzzle_SolvesPuzzleInPlace(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); Assert.True(solver.TrySolve(puzzle)); PuzzleTestUtils.AssertStandardPuzzleSolved(puzzle); }
public void HasUniqueSolution_WithCanceledToken_Throws() { var solver = StandardPuzzles.CreateSolver(); var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.Throws <OperationCanceledException>(() => solver.HasUniqueSolution(new PuzzleWithPossibleValues(9), cancellationSource.Token)); }
public void Solve_ValidPuzzle_SolvesPuzzleCopy(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); var solved = solver.Solve(puzzle); PuzzleTestUtils.AssertStandardPuzzleSolved(solved); }
public void SolveRandomly_ValidPuzzle_SolvesPuzzleInPlace(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); var solved = solver.Solve(puzzle, randomizeGuesses: true); PuzzleTestUtils.AssertStandardPuzzleSolved(solved); }
public void ComputeStatsForAllSolutions_WithInvalidPuzzle_ReturnsNoSolutions(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var solver = StandardPuzzles.CreateSolver(); var stats = solver.ComputeStatsForAllSolutions(puzzle); Assert.Equal(0, stats.NumSolutionsFound); }
public void Generate_CreatesPuzzleWithUniqueSolution(int size, int numToSet) { var generator = new StandardPuzzleGenerator(); PuzzleWithPossibleValues puzzle = generator.Generate(size, numToSet, TimeSpan.FromSeconds(60)); Assert.Equal(size * size - numToSet, puzzle.NumEmptySquares); var solver = StandardPuzzles.CreateSolver(); SolveStats stats = solver.ComputeStatsForAllSolutions(puzzle); Assert.Equal(1, stats.NumSolutionsFound); }
public void Solve_LeavesPuzzleUnchanged() { var puzzle = new PuzzleWithPossibleValues(9); var solver = StandardPuzzles.CreateSolver(); var solved = solver.Solve(puzzle); for (int row = 0; row < puzzle.Size; ++row) { for (int col = 0; col < puzzle.Size; ++col) { Assert.False(puzzle[row, col].HasValue); Assert.True(solved[row, col].HasValue); } } }
public void HasUniqueSolution_LeavesPuzzleUnchanged(int?[][] matrix) { var puzzle = new PuzzleWithPossibleValues(matrix); var puzzleCopy = new PuzzleWithPossibleValues(puzzle); var solver = StandardPuzzles.CreateSolver(); solver.HasUniqueSolution(puzzle); for (int row = 0; row < puzzleCopy.Size; ++row) { for (int col = 0; col < puzzleCopy.Size; ++col) { Assert.Equal(puzzleCopy[row, col], puzzle[row, col]); } } }
public void Constructor_WithValidArgs_Works() { var generator = new PuzzleGenerator <PuzzleWithPossibleValues>( size => new PuzzleWithPossibleValues(size), StandardPuzzles.CreateSolver()); }