-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a50873a
commit f0f6812
Showing
4 changed files
with
94 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
"""Test board logic and representation.""" | ||
|
||
import pytest | ||
|
||
from royal_game._exceptions import InvalidNumberofPieces | ||
from royal_game.modules.board import Board | ||
from royal_game.modules.grid_status import GridStatus | ||
|
||
|
||
def test_reject_invalid_board(): | ||
with pytest.raises(InvalidNumberofPieces, match=r"(white|black).*0"): | ||
_ = Board(0) | ||
with pytest.raises(InvalidNumberofPieces, match=r"white.*8"): | ||
_ = Board(481040535615) | ||
with pytest.raises(InvalidNumberofPieces, match=r"black.*6"): | ||
_ = Board(155055118456) | ||
with pytest.raises(InvalidNumberofPieces, match=r"black.*8"): | ||
_ = Board(292865706639) | ||
|
||
|
||
def test_init(): | ||
board = Board(174518804524) | ||
assert board.board["W4"].status == GridStatus.white | ||
assert board.board["8"].status == GridStatus.empty | ||
assert board.board["B14"].status == GridStatus.empty | ||
assert int(board.board["WS"]) == 2 | ||
assert int(board.board["BE"]) == 1 | ||
|
||
|
||
def test_check_endstate(): | ||
assert Board(966988398624).is_end_state() | ||
assert not Board(829549445216).is_end_state() | ||
assert Board(599282155520).is_end_state() | ||
assert not Board(597403107328).is_end_state() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
"""Test grid logic and representation.""" | ||
|
||
import pytest | ||
|
||
from royal_game._constants import black_piece, rosette, white_piece | ||
from royal_game._exceptions import InvalidNumPieces | ||
from royal_game.modules.grid import Grid, StartEndGrid | ||
from royal_game.modules.grid_status import GridStatus | ||
|
||
|
||
def test_reject_invalid_grid(): | ||
with pytest.raises(InvalidNumPieces) as e: | ||
_ = StartEndGrid(num_pieces=-1, name="") | ||
|
||
with pytest.raises(InvalidNumPieces) as e: | ||
_ = StartEndGrid(num_pieces=10, name="") | ||
|
||
|
||
def test_int_conversion(): | ||
assert int(Grid("", False, GridStatus.empty)) == 0 | ||
assert int(StartEndGrid(5, "")) == 5 | ||
|
||
|
||
def test_repr(): | ||
test_end = StartEndGrid(3, "end") | ||
assert str(test_end) == " \n 3 \n \n" | ||
|
||
test_grid = Grid("test", False, GridStatus.empty) | ||
assert str(test_grid) == "---\n| |\n---\n" | ||
|
||
test_grid.is_rosette = True | ||
assert str(test_grid) == f"---\n|{rosette}|\n---\n" | ||
|
||
test_grid.status = GridStatus.white | ||
assert str(test_grid) == f"---\n|{white_piece}|\n---\n" | ||
|
||
test_grid.status = GridStatus.black | ||
assert str(test_grid) == f"---\n|{black_piece}|\n---\n" |