fix: stochastic failure in test_autonomous_goals.py
This commit is contained in:
@@ -344,30 +344,30 @@ class TestActionMasking:
|
||||
|
||||
def test_action_masked_after_max_retries(self):
|
||||
"""After 2 failures, the action must be excluded from available_actions."""
|
||||
action_failures = {"tap reels tab": 2}
|
||||
action_failures = {(ScreenType.HOME_FEED, "tap reels tab"): 2}
|
||||
original_actions = ["tap home tab", "tap reels tab", "tap profile tab"]
|
||||
MAX_RETRIES = 2
|
||||
|
||||
masked = [a for a in original_actions if action_failures.get(a, 0) < MAX_RETRIES]
|
||||
masked = [a for a in original_actions if action_failures.get((ScreenType.HOME_FEED, a), 0) < MAX_RETRIES]
|
||||
assert "tap reels tab" not in masked
|
||||
assert "tap home tab" in masked
|
||||
assert "tap profile tab" in masked
|
||||
|
||||
def test_action_not_masked_under_threshold(self):
|
||||
"""1 failure is not enough to mask."""
|
||||
action_failures = {"tap reels tab": 1}
|
||||
action_failures = {(ScreenType.HOME_FEED, "tap reels tab"): 1}
|
||||
original_actions = ["tap reels tab", "tap profile tab"]
|
||||
MAX_RETRIES = 2
|
||||
|
||||
masked = [a for a in original_actions if action_failures.get(a, 0) < MAX_RETRIES]
|
||||
masked = [a for a in original_actions if action_failures.get((ScreenType.HOME_FEED, a), 0) < MAX_RETRIES]
|
||||
assert "tap reels tab" in masked
|
||||
|
||||
def test_success_resets_failure_count(self):
|
||||
"""A successful execution must reset the failure counter."""
|
||||
action_failures = {"tap reels tab": 1}
|
||||
action_failures = {(ScreenType.HOME_FEED, "tap reels tab"): 1}
|
||||
# Simulate success
|
||||
action_failures["tap reels tab"] = 0
|
||||
assert action_failures["tap reels tab"] == 0
|
||||
action_failures[(ScreenType.HOME_FEED, "tap reels tab")] = 0
|
||||
assert action_failures[(ScreenType.HOME_FEED, "tap reels tab")] == 0
|
||||
|
||||
def test_hd_map_unreachable_with_masked_actions(self):
|
||||
"""
|
||||
|
||||
@@ -30,15 +30,15 @@ def test_autonomous_goal_weighting():
|
||||
available_goals = ["goal_A", "goal_B", "goal_C"]
|
||||
|
||||
# Simulate that goal_B has been incredibly successful, goal_A moderately, goal_C not at all.
|
||||
success_rates = {"goal_A": 2, "goal_B": 100, "goal_C": 0}
|
||||
success_rates = {"goal_A": 50, "goal_B": 500, "goal_C": 0}
|
||||
|
||||
# If weighting works, running this many times should result in goal_B being chosen overwhelmingly
|
||||
choices = {"goal_A": 0, "goal_B": 0, "goal_C": 0}
|
||||
for _ in range(100):
|
||||
for _ in range(1000):
|
||||
# We pass success_rates to get_current_goal
|
||||
choice = brain.get_current_goal(dopamine, available_goals, success_rates=success_rates)
|
||||
choices[choice] += 1
|
||||
|
||||
assert choices["goal_B"] > 80, "Goal B should be chosen heavily due to high success rate weighting."
|
||||
assert choices["goal_A"] < 20, "Goal A should be chosen rarely."
|
||||
assert choices["goal_A"] >= choices["goal_C"], "Goal A should be chosen at least as often as C."
|
||||
assert choices["goal_B"] > 800, f"Goal B should be chosen heavily: {choices['goal_B']}"
|
||||
assert choices["goal_A"] > 50, f"Goal A should be chosen sometimes: {choices['goal_A']}"
|
||||
assert choices["goal_C"] < 50, f"Goal C should be chosen rarely: {choices['goal_C']}"
|
||||
|
||||
Reference in New Issue
Block a user