Skip to content

Commit

Permalink
test both cross and circle for BetterEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeegan committed Jul 16, 2024
1 parent 91fb3b1 commit e43e346
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/effective_software_testing/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def make_move(self) -> bool:
class BetterEngine(Engine):
"""A slightly better tic-tac-toe engine that plays in the centre if possible"""

def __init__(self, player: Player, board: Board, seed: Optional[int] = None):
super().__init__(player, board, seed)

def make_move(self) -> bool:
"""Play in the centre if possible, otherwise make a random valid move and return True."""
if self._board.make_move(self._board.n // 2, self._board.n // 2, self._player):
Expand Down
8 changes: 5 additions & 3 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def test_two_engines_finish_game(
assert engine_circle.make_move() is False


def test_better_engine_first_move_in_centre() -> None:
@pytest.mark.parametrize("player", players)
def test_better_engine_first_move_in_centre(player: Player) -> None:
board = Board(3)
engine = BetterEngine(Player.CROSS, board)
engine = BetterEngine(player, board)
assert board.square(1, 1) is None
assert engine.make_move() is True
assert board.square(1, 1) == Player.CROSS
assert board.square(1, 1) == player

0 comments on commit e43e346

Please sign in to comment.