56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from sqlmodel import Session, select
|
|
|
|
from in_game.gameplay_models import Game, Lineup, ManagerAi, Play
|
|
from tests.factory import session_fixture
|
|
from in_game.managerai_responses import JumpResponse
|
|
|
|
|
|
def test_create_ai(session: Session):
|
|
all_ai = session.exec(select(ManagerAi)).all()
|
|
|
|
assert len(all_ai) == 3
|
|
assert ManagerAi.create_ai(session) == True
|
|
|
|
all_ai = session.exec(select(ManagerAi)).all()
|
|
|
|
assert len(all_ai) == 3
|
|
|
|
|
|
def test_check_jump(session: Session):
|
|
balanced_ai = session.exec(select(ManagerAi).where(ManagerAi.name == 'Balanced')).one()
|
|
aggressive_ai = session.exec(select(ManagerAi).where(ManagerAi.name == 'Yolo')).one()
|
|
|
|
this_game = session.get(Game, 1)
|
|
runner = session.get(Lineup, 5)
|
|
this_play = session.get(Play, 2)
|
|
|
|
this_play.on_first = runner
|
|
|
|
assert this_play.starting_outs == 1
|
|
assert balanced_ai.check_jump(session, this_game, to_base=2) == JumpResponse(min_safe=16)
|
|
assert aggressive_ai.check_jump(session, this_game, to_base=2) == JumpResponse(min_safe=13, run_if_auto_jump=True)
|
|
|
|
this_play.on_third = runner
|
|
|
|
assert balanced_ai.check_jump(session, this_game, to_base=4) == JumpResponse(min_safe=None)
|
|
assert aggressive_ai.check_jump(session, this_game, to_base=4) == JumpResponse(min_safe=5)
|
|
|
|
|
|
def test_tag_from_second(session: Session):
|
|
balanced_ai = session.exec(select(ManagerAi).where(ManagerAi.name == 'Balanced')).one()
|
|
aggressive_ai = session.exec(select(ManagerAi).where(ManagerAi.name == 'Yolo')).one()
|
|
|
|
this_game = session.get(Game, 1)
|
|
runner = session.get(Lineup, 5)
|
|
this_play = session.get(Play, 2)
|
|
this_play.on_second = runner
|
|
|
|
assert this_play.starting_outs == 1
|
|
|
|
balanced_resp = balanced_ai.tag_from_second(session, this_game)
|
|
aggressive_resp = aggressive_ai.tag_from_second(session, this_game)
|
|
|
|
assert balanced_resp.min_safe == 5
|
|
assert aggressive_resp.min_safe == 2
|
|
|
|
|