sudoku-solver/tests.py

45 lines
1,007 B
Python

"""All tests for the Sudoku Solver."""
import unittest
from board import Board
from square import Square
class TestBoard(unittest.TestCase):
"""TestCase for Board"""
class TestSquare(unittest.TestCase):
"""TestCase for Square"""
def setUp(self):
content = '.'
self.board = [
Square(line, column, content)
for line in range(9)
for column in range(9)
]
self.assertEqual(len(self.board), 81)
def test_grid_is_correctly_computed(self):
"""Square.grid is correctly computed for all values."""
correct_grids = (
"000111222"
"000111222"
"000111222"
"333444555"
"333444555"
"333444555"
"666777888"
"666777888"
"666777888"
)
for i, square in enumerate(self.board):
self.assertEqual(square.grid_id, int(correct_grids[i]))
if __name__ == '__main__':
unittest.main()