Skip to content

Commit

Permalink
test: add additional tests for Game class
Browse files Browse the repository at this point in the history
  • Loading branch information
alxdrcirilo committed Aug 7, 2023
1 parent 1581487 commit 6095b0c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from checkers.exceptions.moves import NoMoves
from checkers.logic.board import Board
from checkers.logic.game import Game
from checkers.logic.piece import Player
from checkers.logic.piece import Player, Piece


@pytest.fixture
Expand Down Expand Up @@ -31,9 +31,33 @@ def test_winner(self, game: Game) -> None:
def test_stats(self, game: Game) -> None:
assert game.stats == "self.winner=None\nself._turn=1"

def test_turn(self, game: Game) -> None:
assert game.turn is 1

@pytest.mark.parametrize("player", [Player.BLACK, Player.WHITE])
def test_no_moves_exception(self, player: Player) -> None:
with pytest.raises(NoMoves) as exc_info:
raise NoMoves(player)

assert str(exc_info.value) == f"{player} ran out of moves"

def test_random_move(self, game: Game) -> None:
move = game.get_random_move(player=Player.BLACK)
assert type(move) is list and len(move[0]) == 2

def test_ai_move(self, game: Game) -> None:
move = game.get_ai_move(player=Player.BLACK, depth=1)
assert type(move) is list and len(move[0]) == 2

def test_game_over(self, game: Game) -> None:
# Game is not over
assert game.is_game_over() is False

# Remove all WHITE pieces
for position, piece in game.board.state.items():
if type(piece) is Piece:
if piece.player is Player.WHITE:
game.board.remove(position)

# Game is over
assert game.is_game_over() is True

0 comments on commit 6095b0c

Please sign in to comment.