Skip to content

Commit 2436797

Browse files
committed
Add test where the opponent defects but we forgive because their overall cooperation rate is high enough
1 parent 15a8656 commit 2436797

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

axelrod/tests/strategies/test_bayesian_forgiver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ def test_vs_random(self):
7676
actions = [(C, C), (C, C), (C, C), (C, C), (C, D)]
7777
self.versus_test(axl.Random(), expected_actions=actions, seed=3)
7878

79+
def test_forgiveness_high_cooperation(self):
80+
"""Test that forgiveness occurs when opponent has high cooperation rate."""
81+
# Opponent cooperates many times, then defects - should forgive
82+
# This tests the forgiveness path (mean_cooperation >= threshold)
83+
opponent = axl.MockPlayer(actions=[C, C, C, C, C, C, C, C, D, C])
84+
actions = [
85+
(C, C), # alpha=2, beta=1
86+
(C, C), # alpha=3, beta=1
87+
(C, C), # alpha=4, beta=1
88+
(C, C), # alpha=5, beta=1
89+
(C, C), # alpha=6, beta=1
90+
(C, C), # alpha=7, beta=1
91+
(C, C), # alpha=8, beta=1
92+
(C, C), # alpha=9, beta=1
93+
(C, D), # Opponent defects: alpha=9, beta=2, mean=9/11=0.818
94+
(C, C), # mean >= threshold → FORGIVE! Return C
95+
]
96+
self.versus_test(opponent, expected_actions=actions)
97+
7998
def test_vs_mock_single_defection(self):
8099
"""Test response to a single defection."""
81100
# Opponent cooperates then defects once then cooperates

0 commit comments

Comments
 (0)