This commit is contained in:
cutsweettea
2025-10-29 10:36:33 -04:00
parent 45d60d1657
commit bbd55f48a0
10 changed files with 147 additions and 32 deletions

View File

@@ -1,11 +1,16 @@
from chess_piece import ChessPiece
from pytest import fixture, mark
from pytest import fixture
from player import Player
from move import StaticMoveSet, Move, DynamicMoveSet, valid_range
from move import StaticMoveSet, Move, DynamicMoveSet, valid_range, pawn_valid_move_sets
from random import randint, choice
from pawn import Pawn
from chess_model import DEFAULT_BOARD
# chess piece tests
# general piece
@fixture
def valid_piece():
return ChessPiece(Player.WHITE)
@@ -19,11 +24,29 @@ def test_update_player(valid_piece: ChessPiece):
def test_repr_str(valid_piece: ChessPiece):
rep = str(valid_piece)
assert 'player='
assert 'player=' in rep
# pawn piece
_INIT_PAWN_ORIGINAL_VAL = (4, 1)
@fixture
def valid_board():
# ask how to define the board
pass
@fixture
def valid_black_pawn():
return Pawn(Player.BLACK)
def test_valid_move_black_pawn_1(valid_black_pawn: Pawn):
# try all valid pawn moves
for ms in pawn_valid_move_sets:
assert valid_black_pawn.is_valid_move(Move(_INIT_PAWN_ORIGINAL_VAL[0], _INIT_PAWN_ORIGINAL_VAL[1], _INIT_PAWN_ORIGINAL_VAL[0]+ms[1], _INIT_PAWN_ORIGINAL_VAL[1]+ms[0]), DEFAULT_BOARD)
# move set testing (kinda separate from main project)
_init_val = 4
_INIT_MOVE_ORIGIN_VAL = 4
# static move sets
@@ -37,13 +60,14 @@ def valid_static_move_set():
def test_valid_static_moves(valid_static_move_set: StaticMoveSet):
for ms in _static_move_sets:
assert valid_static_move_set.is_valid_move(Move(_init_val, _init_val, _init_val+ms[0], _init_val+ms[1]))
print(ms)
assert valid_static_move_set.is_valid_move(Move(_INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL+ms[0], _INIT_MOVE_ORIGIN_VAL+ms[1]))
# test invalid
def test_invalid_static_moves(valid_static_move_set: StaticMoveSet):
for ms in _static_move_sets:
assert not valid_static_move_set.is_valid_move(Move(_init_val, _init_val, _init_val+ms[0]+(-1 if ms[0] < 0 else 1), _init_val+ms[1]+(-1 if ms[1] < 0 else 1)))
assert not valid_static_move_set.is_valid_move(Move(_INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL+ms[0]+(-1 if ms[0] < 0 else 1), _INIT_MOVE_ORIGIN_VAL+ms[1]+(-1 if ms[1] < 0 else 1)))
# dynamic move sets
@@ -75,7 +99,7 @@ def test_valid_dynamic_moves(valid_dynamic_move_set: DynamicMoveSet):
rnd_col = choice(valid_range_col)
# test dat thing
assert valid_dynamic_move_set.is_valid_move(Move(_init_val, _init_val, _init_val+rnd_row, _init_val+rnd_col))
assert valid_dynamic_move_set.is_valid_move(Move(_INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL+rnd_row, _INIT_MOVE_ORIGIN_VAL+rnd_col))
_RND_MIN = 10
_RND_MAX = 20
@@ -101,4 +125,4 @@ def test_invalid_dynamic_moves(valid_dynamic_move_set: DynamicMoveSet):
col_rnd_add = col + (rnd if col > 0 else -rnd)
#print(f'{ms}, ({_init_val}+{row_rnd_add}, {_init_val}+{col_rnd_add}) = ({_init_val+row_rnd_add}, {_init_val+col_rnd_add})')
assert not valid_dynamic_move_set.is_valid_move(Move(_init_val, _init_val, _init_val+row_rnd_add, _init_val+col_rnd_add))
assert not valid_dynamic_move_set.is_valid_move(Move(_INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL, _INIT_MOVE_ORIGIN_VAL+row_rnd_add, _INIT_MOVE_ORIGIN_VAL+col_rnd_add))