def test_check_square_only_accepts_correct_squares(self): game = sudoku.SudokuGame(self.boards_file) game.start(2) for row in xrange(3): for column in xrange(3): self.assertEqual(game._SudokuGame__check_square(row, column), column != 2)
def test_it_resets_the_game(self): boards_file = ("012345678\n" * 9).strip().split('\n') game = sudoku.SudokuGame(boards_file) game.game_over = True game.answer = [range(1, 10)] * 9 game.start(-1) game.set_answer_to_puzzle() self.assertFalse(game.game_over) self.assertEqual(game.puzzle, game.answer)
def test_it_doesnt_start_game_with_wrong_board_number(self): for wrong_board_number in [-2, 3, 9]: game = sudoku.SudokuGame(self.boards_file) self.assertRaises(sudoku.SudokuError, game.start, wrong_board_number)
def test_it_starts_game_with_random_board_number(self): game = sudoku.SudokuGame(self.boards_file) game.start(-1) self.assertEqual(len(game.puzzle), 9)
def test_it_starts_game_with_specific_board_number(self): game = sudoku.SudokuGame(self.boards_file) game.start(0) self.assertEqual(game.puzzle, [range(0, 9)] * 9) game.start(1) self.assertEqual(game.puzzle, [range(1, 10)] * 9)
def test_it_creates_multiple_boards_from_file(self): boards_file = ("012345678\n" * 18).strip().split('\n') game = sudoku.SudokuGame(boards_file) self.assertEqual(game.boards, [[range(0, 9)] * 9] * 2)
def test_it_creates_board_from_file(self): boards_file = ("123456789\n" * 9).strip().split('\n') game = sudoku.SudokuGame(boards_file) self.assertEqual(game.boards, [[range(1, 10)] * 9])
def test_check_column_only_accepts_correct_columns(self): game = sudoku.SudokuGame(self.boards_file) game.start(1) for column in xrange(9): self.assertEqual(game._SudokuGame__check_column(column), column % 2 != 0)
def test_check_row_only_accepts_correct_rows(self): game = sudoku.SudokuGame(self.boards_file) game.start(0) for row in xrange(9): self.assertEqual(game._SudokuGame__check_row(row), row % 2 != 0)
def test_check_block_doesnt_accept_incorrect_sequences(self): game = sudoku.SudokuGame(self.boards_file) game.start(-1) for p in [xrange(0, 9), reversed(xrange(0, 9))]: self.assertFalse(game._SudokuGame__check_block(p))
def test_check_block_accepts_correct_sequences(self): game = sudoku.SudokuGame(self.boards_file) game.start(-1) for p in [xrange(1, 10), reversed(xrange(1, 10))]: self.assertTrue(game._SudokuGame__check_block(p))