def test_search_scrambled(self): board = PuzzleBoard(size=3) board.scramble() problem = PuzzleProblem(board) graph_search = GraphSearch() solution = graph_search.search(problem) self.__assert_successful_actions(board, solution)
class PuzzleGame(Game): def __init__(self, size, player, scramble=True): self.board = PuzzleBoard(size) self.size = size if player == "user": self.player = PuzzlePlayerManual() else: self.player = PuzzlePlayerAgent() if scramble: self.board.scramble() def print_turn(self): print(str(self.board)) def take_turn(self): action = self.player.get_action(self.board) self.board.move(action) def is_finished(self): return self.board.is_finished()
def test_scramble_called_twice_when_first_is_finished(self): board = PuzzleBoard(size=2) mock_is_finished = mock.Mock(side_effect=[True, False]) board.is_finished = mock_is_finished board.scramble() self.assertEqual(mock_is_finished.call_count, 2)
def test_scramble(self): board = PuzzleBoard(size=2) board.scramble() self.assertFalse(board.is_finished())