<filename>tests/test_solve.py
import solver.sudoku_solver as solver

def test_load_puzzle():
  grid = solver.load_puzzle("./puzzles/puzzle-3-solution.txt")

  expected_grid = [[1,2,3,4,5,6,7,8,9],
                   [4,5,6,7,8,9,1,2,3],
                   [7,8,9,1,2,3,4,5,6],
                   [2,1,4,3,6,5,8,9,7],
                   [3,6,5,8,9,7,2,1,4],
                   [8,9,7,2,1,4,3,6,5],
                   [5,3,1,6,4,2,9,7,8],
                   [6,4,2,9,7,8,5,3,1],
                   [9,7,8,5,3,1,6,4,2]]

  assert grid == expected_grid

def test_solve_puzzle():
  grid_to_solve = [[1,2,3,4,5,6,7,8,9],
                   [4,5,6,7,8,9,1,2,3],
                   [7,8,9,1,2,3,4,5,6],
                   [2,1,4,3,6,5,8,9,7],
                   [3,6,5,8,9,7,2,1,4],
                   [8,9,7,2,1,4,3,6,5],
                   [5,3,1,6,4,2,9,7,8],
                   [6,4,2,9,7,8,5,3,1],
                   [9,7,8,5,3,1,6,4,0]]

  expected_grid = [[1,2,3,4,5,6,7,8,9],
                   [4,5,6,7,8,9,1,2,3],
                   [7,8,9,1,2,3,4,5,6],
                   [2,1,4,3,6,5,8,9,7],
                   [3,6,5,8,9,7,2,1,4],
                   [8,9,7,2,1,4,3,6,5],
                   [5,3,1,6,4,2,9,7,8],
                   [6,4,2,9,7,8,5,3,1],
                   [9,7,8,5,3,1,6,4,2]]

  result = solver.solve_grid(grid_to_solve)

  assert grid_to_solve == expected_grid

def test_valid_solution():
  test_grid = [[1,2,3,4,5,6,7,8,9],
               [4,5,6,7,8,9,1,2,3],
               [7,8,9,1,2,3,4,5,6],
               [2,1,4,3,6,5,8,9,7],
               [3,6,5,8,9,7,2,1,4],
               [8,9,7,2,1,4,3,6,5],
               [5,3,1,6,4,2,9,7,8],
               [6,4,2,9,7,8,5,3,1],
               [9,7,8,5,3,1,6,4,0]]
  result = solver.is_valid_solution(test_grid,8,8,2)
  assert result

def test_invalid_solution():
  test_grid = [[1,2,3,4,5,6,7,8,9],
               [4,5,6,7,8,9,1,2,3],
               [7,8,9,1,2,3,4,5,6],
               [2,1,4,3,6,5,8,9,7],
               [3,6,5,8,9,7,2,1,4],
               [8,9,7,2,1,4,3,6,5],
               [5,3,1,6,4,2,9,7,8],
               [6,4,2,9,7,8,5,3,1],
               [9,7,8,5,3,1,6,4,0]]

  for invalid_value in [1,3,4,5,6,7,8,9]:
    result = solver.is_valid_solution(test_grid,8,8,invalid_value)
    assert not result

<filename>tests/test_solve.py
import solver.sudoku_solver as solver

def test_load_puzzle():
  grid = solver.load_puzzle("./puzzles/puzzle-3-solution.txt")

  expected_grid = [[1,2,3,4,5,6,7,8,9],
                   [4,5,6,7,8,9,1,2,3],
                   [7,8,9,1,2,3,4,5,6],
                   [2,1,4,3,6,5,8,9,7],
                   [3,6,5,8,9,7,2,1,4],
                   [8,9,7,2,1,4,3,6,5],
                   [5,3,1,6,4,2,9,7,8],
                   [6,4,2,9,7,8,5,3,1],
                   [9,7,8,5,3,1,6,4,2]]

  assert grid == expected_grid

def test_solve_puzzle():
  grid_to_solve = [[1,2,3,4,5,6,7,8,9],
                   [4,5,6,7,8,9,1,2,3],
                   [7,8,9,1,2,3,4,5,6],
                   [2,1,4,3,6,5,8,9,7],
                   [3,6,5,8,9,7,2,1,4],
                   [8,9,7,2,1,4,3,6,5],
                   [5,3,1,6,4,2,9,7,8],
                   [6,4,2,9,7,8,5,3,1],
                   [9,7,8,5,3,1,6,4,0]]

  expected_grid = [[1,2,3,4,5,6,7,8,9],
                   [4,5,6,7,8,9,1,2,3],
                   [7,8,9,1,2,3,4,5,6],
                   [2,1,4,3,6,5,8,9,7],
                   [3,6,5,8,9,7,2,1,4],
                   [8,9,7,2,1,4,3,6,5],
                   [5,3,1,6,4,2,9,7,8],
                   [6,4,2,9,7,8,5,3,1],
                   [9,7,8,5,3,1,6,4,2]]

  result = solver.solve_grid(grid_to_solve)

  assert grid_to_solve == expected_grid

def test_valid_solution():
  test_grid = [[1,2,3,4,5,6,7,8,9],
               [4,5,6,7,8,9,1,2,3],
               [7,8,9,1,2,3,4,5,6],
               [2,1,4,3,6,5,8,9,7],
               [3,6,5,8,9,7,2,1,4],
               [8,9,7,2,1,4,3,6,5],
               [5,3,1,6,4,2,9,7,8],
               [6,4,2,9,7,8,5,3,1],
               [9,7,8,5,3,1,6,4,0]]
  result = solver.is_valid_solution(test_grid,8,8,2)
  assert result

def test_invalid_solution():
  test_grid = [[1,2,3,4,5,6,7,8,9],
               [4,5,6,7,8,9,1,2,3],
               [7,8,9,1,2,3,4,5,6],
               [2,1,4,3,6,5,8,9,7],
               [3,6,5,8,9,7,2,1,4],
               [8,9,7,2,1,4,3,6,5],
               [5,3,1,6,4,2,9,7,8],
               [6,4,2,9,7,8,5,3,1],
               [9,7,8,5,3,1,6,4,0]]

  for invalid_value in [1,3,4,5,6,7,8,9]:
    result = solver.is_valid_solution(test_grid,8,8,invalid_value)
    assert not result
