paper-dynasty-discord/tests/command_logic/test_logic_gameplay.py
2024-11-06 02:17:28 -06:00

48 lines
1.6 KiB
Python

import pytest
from sqlmodel import Session
from command_logic.logic_gameplay import advance_runners, get_obc, get_re24, get_wpa
from tests.factory import session_fixture, Game
def test_advance_runners(session: Session):
this_game = session.get(Game, 3)
play_1 = this_game.initialize_play(session)
assert play_1.starting_outs == 0
assert play_1.on_first_id is None
assert play_1.on_second_id is None
assert play_1.on_third_id is None
# TODO: Test advance runners once "advance play" function is ready
def test_get_obc():
assert get_obc() == 0
assert get_obc(on_first=True) == 1
assert get_obc(on_second=True) == 2
assert get_obc(on_third=True) == 3
assert get_obc(on_first=True, on_second=True) == 4
assert get_obc(on_first=True, on_third=True) == 5
assert get_obc(on_second=True, on_third=True) == 6
assert get_obc(on_first=True, on_second=True, on_third=True) == 7
def test_get_re24(session: Session):
game_1 = session.get(Game, 1)
this_play = game_1.current_play_or_none(session)
assert this_play is not None
assert get_re24(this_play, runs_scored=0, new_obc=0, new_starting_outs=2) == -.154
assert get_re24(this_play, runs_scored=1, new_obc=0, new_starting_outs=1) == 1
assert get_re24(this_play, runs_scored=0, new_obc=2, new_starting_outs=1) == 0.365
assert get_re24(this_play, runs_scored=0, new_obc=6, new_starting_outs=2) == 0.217
def test_get_re24(session: Session):
game_1 = session.get(Game, 1)
this_play = game_1.current_play_or_none(session)
old_play = game_1.plays[0]
assert old_play.id != this_play