Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pieces to test #50

Merged
merged 1 commit into from
Oct 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions tests/TestPieces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from src.Board import Board
from src.Coordinate import Coordinate
from src.Knight import Knight
from src.Pawn import Pawn
from src.Rook import Rook


@pytest.mark.parametrize(
Expand All @@ -23,3 +25,60 @@ def testKnight(coord, expected):
poss.append(Coordinate(*i.newPos[:2]) + Coordinate(*i.newPos[2:]))

assert poss == expected

@pytest.mark.parametrize(
["coord", "expected"],
[
[(2, 2), [(2, 1), (2, 0)]],
[(3, 3), [(3, 2), (3, 1)]]
],
)
def testPawn(coord, expected):
board = Board()

pawn = Pawn(board, False, coord)

poss = []
for i in pawn.getPossibleMoves():
assert i.oldPos == coord
poss.append(Coordinate(*i.newPos[:2]) + Coordinate(*i.newPos[2:]))

assert poss == expected

@pytest.mark.parametrize(
["coord", "expected"],
[
[(2, 2), [(2, 1)]],
[(3, 3), [(3, 2)]]
],
)
def testMovedPawn(coord, expected):
#Moved pawn can move only one.
board = Board()

pawn = Pawn(board, False, coord)
pawn.movesMade = 1
poss = []
for i in pawn.getPossibleMoves():
assert i.oldPos == coord
poss.append(Coordinate(*i.newPos[:2]) + Coordinate(*i.newPos[2:]))

assert poss == expected

@pytest.mark.parametrize(
["coord", "expected"],
[
[(4, 4), []]
],
)
def testRook(coord, expected):
board = Board()

rook = Rook(board, False, coord)

poss = []
for i in rook.getPossibleMoves():
assert i.oldPos == coord
newcoord = Coordinate(*i.newPos[:2]) + Coordinate(*i.newPos[2:])
assert newcoord.rank == 4 or newcoord.file == 4 #left/right/up/down