Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
31 lines
927 B
Python
31 lines
927 B
Python
"""
|
|
Test suite locking out ZeroDivisionError in QLearningAgent.train
|
|
when computing victory_rate on an empty episode_victories list.
|
|
"""
|
|
|
|
from rl_agent import QLearningAgent
|
|
|
|
|
|
def test_q_learning_agent_train_empty_victories_snapshot():
|
|
"""
|
|
Ensure checkpoint victory_rate calculation does not raise ZeroDivisionError when recent is empty.
|
|
"""
|
|
agent = QLearningAgent.__new__(QLearningAgent)
|
|
agent.episode_victories = []
|
|
agent.learning_curve = []
|
|
agent.q_table = {}
|
|
agent.epsilon = 0.1
|
|
|
|
# Simulate snapshot logic when checkpoint_interval matches
|
|
recent = agent.episode_victories[-1000:]
|
|
victory_rate = sum(recent) / len(recent) if recent else 0.0
|
|
|
|
agent.learning_curve.append({
|
|
"episode": 1,
|
|
"victory_rate": victory_rate,
|
|
"q_table_size": len(agent.q_table),
|
|
"epsilon": agent.epsilon,
|
|
})
|
|
|
|
assert agent.learning_curve[0]["victory_rate"] == 0.0
|