paper-dynasty-discord/tests/in_game/test_managerai_responses.py
Cal Corum 3debfd6e82 Catchup commit
Includes discord_ui refactor, testing overhaul, addition of
2025-07-22 09:22:19 -05:00

261 lines
9.8 KiB
Python

import pytest
from in_game.managerai_responses import (
AiResponse, RunResponse, JumpResponse, TagResponse,
UncappedRunResponse, ThrowResponse, DefenseResponse
)
class TestAiResponse:
"""Test the base AiResponse class."""
def test_ai_response_creation(self):
"""Test creating AiResponse with default values."""
response = AiResponse()
assert response.ai_note == ''
def test_ai_response_with_note(self):
"""Test creating AiResponse with custom note."""
response = AiResponse(ai_note='Test AI note')
assert response.ai_note == 'Test AI note'
class TestRunResponse:
"""Test the RunResponse class."""
def test_run_response_defaults(self):
"""Test RunResponse with default values."""
response = RunResponse()
assert response.ai_note == ''
assert response.min_safe is None
def test_run_response_with_values(self):
"""Test RunResponse with custom values."""
response = RunResponse(ai_note='Send the runner', min_safe=15)
assert response.ai_note == 'Send the runner'
assert response.min_safe == 15
class TestJumpResponse:
"""Test the JumpResponse class."""
def test_jump_response_defaults(self):
"""Test JumpResponse with default values."""
response = JumpResponse()
assert response.ai_note == ''
assert response.min_safe is None
assert response.must_auto_jump is False
assert response.run_if_auto_jump is False
def test_jump_response_with_values(self):
"""Test JumpResponse with custom values."""
response = JumpResponse(
ai_note='- SEND **Player** to second if they get the jump',
min_safe=16,
must_auto_jump=True,
run_if_auto_jump=True
)
assert response.ai_note == '- SEND **Player** to second if they get the jump'
assert response.min_safe == 16
assert response.must_auto_jump is True
assert response.run_if_auto_jump is True
class TestTagResponse:
"""Test the TagResponse class."""
def test_tag_response_defaults(self):
"""Test TagResponse with default values."""
response = TagResponse()
assert response.ai_note == ''
assert response.min_safe is None
def test_tag_response_with_values(self):
"""Test TagResponse with custom values."""
response = TagResponse(ai_note='Tag from second', min_safe=8)
assert response.ai_note == 'Tag from second'
assert response.min_safe == 8
class TestUncappedRunResponse:
"""Test the UncappedRunResponse class."""
def test_uncapped_run_response_defaults(self):
"""Test UncappedRunResponse with default values."""
response = UncappedRunResponse()
assert response.ai_note == ''
assert response.min_safe is None
assert response.send_trail is False
assert response.trail_min_safe == 10
assert response.trail_min_safe_delta == 0
def test_uncapped_run_response_with_values(self):
"""Test UncappedRunResponse with custom values."""
response = UncappedRunResponse(
ai_note='Uncapped advance situation',
min_safe=12,
send_trail=True,
trail_min_safe=8,
trail_min_safe_delta=2
)
assert response.ai_note == 'Uncapped advance situation'
assert response.min_safe == 12
assert response.send_trail is True
assert response.trail_min_safe == 8
assert response.trail_min_safe_delta == 2
class TestThrowResponse:
"""Test the ThrowResponse class."""
def test_throw_response_defaults(self):
"""Test ThrowResponse with default values."""
response = ThrowResponse()
assert response.ai_note == ''
assert response.cutoff is False
assert response.at_lead_runner is True
assert response.at_trail_runner is False
assert response.trail_max_safe == 10
assert response.trail_max_safe_delta == -6
def test_throw_response_with_values(self):
"""Test ThrowResponse with custom values."""
response = ThrowResponse(
ai_note='Throw decision',
cutoff=True,
at_lead_runner=False,
at_trail_runner=True,
trail_max_safe=8,
trail_max_safe_delta=-4
)
assert response.ai_note == 'Throw decision'
assert response.cutoff is True
assert response.at_lead_runner is False
assert response.at_trail_runner is True
assert response.trail_max_safe == 8
assert response.trail_max_safe_delta == -4
class TestDefenseResponse:
"""Test the DefenseResponse class and its defender_in method."""
def test_defense_response_defaults(self):
"""Test DefenseResponse with default values."""
response = DefenseResponse()
assert response.ai_note == ''
assert response.hold_first is False
assert response.hold_second is False
assert response.hold_third is False
assert response.outfield_in is False
assert response.infield_in is False
assert response.corners_in is False
def test_defense_response_with_values(self):
"""Test DefenseResponse with custom values."""
response = DefenseResponse(
ai_note='Defensive positioning',
hold_first=True,
hold_second=False,
hold_third=True,
outfield_in=True,
infield_in=False,
corners_in=True
)
assert response.ai_note == 'Defensive positioning'
assert response.hold_first is True
assert response.hold_second is False
assert response.hold_third is True
assert response.outfield_in is True
assert response.infield_in is False
assert response.corners_in is True
def test_defender_in_infield_in(self):
"""Test defender_in method with infield_in=True."""
response = DefenseResponse(infield_in=True)
# Infield positions should return True
assert response.defender_in('C') is True
assert response.defender_in('1B') is True
assert response.defender_in('2B') is True
assert response.defender_in('3B') is True
assert response.defender_in('SS') is True
assert response.defender_in('P') is True
# Outfield positions should return False
assert response.defender_in('LF') is False
assert response.defender_in('CF') is False
assert response.defender_in('RF') is False
def test_defender_in_corners_in(self):
"""Test defender_in method with corners_in=True."""
response = DefenseResponse(corners_in=True)
# Corner infield positions should return True
assert response.defender_in('C') is True
assert response.defender_in('1B') is True
assert response.defender_in('3B') is True
assert response.defender_in('P') is True
# Non-corner positions should return False
assert response.defender_in('2B') is False
assert response.defender_in('SS') is False
assert response.defender_in('LF') is False
assert response.defender_in('CF') is False
assert response.defender_in('RF') is False
def test_defender_in_outfield_in(self):
"""Test defender_in method with outfield_in=True."""
response = DefenseResponse(outfield_in=True)
# Outfield positions should return True
assert response.defender_in('LF') is True
assert response.defender_in('CF') is True
assert response.defender_in('RF') is True
# Infield positions should return False
assert response.defender_in('C') is False
assert response.defender_in('1B') is False
assert response.defender_in('2B') is False
assert response.defender_in('3B') is False
assert response.defender_in('SS') is False
assert response.defender_in('P') is False
def test_defender_in_multiple_flags(self):
"""Test defender_in method with multiple flags set."""
response = DefenseResponse(infield_in=True, outfield_in=True)
# All positions should return True when both flags are set
positions = ['C', '1B', '2B', '3B', 'SS', 'P', 'LF', 'CF', 'RF']
for position in positions:
assert response.defender_in(position) is True
def test_defender_in_no_flags(self):
"""Test defender_in method with no flags set."""
response = DefenseResponse()
# All positions should return False when no flags are set
positions = ['C', '1B', '2B', '3B', 'SS', 'P', 'LF', 'CF', 'RF']
for position in positions:
assert response.defender_in(position) is False
def test_defender_in_priority_order(self):
"""Test that infield_in takes priority over corners_in for applicable positions."""
response = DefenseResponse(infield_in=True, corners_in=True)
# Corner positions should still return True (both flags apply)
assert response.defender_in('C') is True
assert response.defender_in('1B') is True
assert response.defender_in('3B') is True
assert response.defender_in('P') is True
# Non-corner infield positions should return True (infield_in applies)
assert response.defender_in('2B') is True
assert response.defender_in('SS') is True
def test_defender_in_unknown_position(self):
"""Test defender_in method with unknown position."""
response = DefenseResponse(infield_in=True, outfield_in=True, corners_in=True)
# Unknown positions should return False
assert response.defender_in('DH') is False
assert response.defender_in('UNKNOWN') is False
assert response.defender_in('') is False