Skip to content

Commit 2fad16a

Browse files
committed
Fix TricklyLevelPunisher tests
1 parent 398052a commit 2fad16a

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

axelrod/strategies/punisher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ class LevelPunisher(Player):
133133
def strategy(self, opponent: Player) -> Action:
134134
if len(opponent.history) < 10:
135135
return C
136-
elif (len(opponent.history) - opponent.cooperations) / len(
137-
opponent.history
138-
) > 0.2:
136+
elif opponent.defections / len(opponent.history) > 0.2:
139137
return D
140138
else:
141139
return C

axelrod/tests/strategies/test_player.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class TestPlayerClass(unittest.TestCase):
5959

6060
def test_seed_warning(self):
6161
"""Test that the user is warned if a null seed is given."""
62-
player = self.Player()
62+
player = self.player()
6363
with warnings.catch_warnings():
6464
player._set_seed(seed=None)
6565

@@ -646,10 +646,10 @@ def versus_test(
646646
match.play()
647647

648648
# Test expected sequence of plays from the match is as expected.
649-
for (play, expected_play) in zip(player1.history, expected_actions1):
650-
self.assertEqual(play, expected_play)
651-
for (play, expected_play) in zip(player2.history, expected_actions2):
652-
self.assertEqual(play, expected_play)
649+
for i, (play, expected_play) in enumerate(zip(player1.history, expected_actions1)):
650+
self.assertEqual((i, play), (i, expected_play))
651+
for i, (play, expected_play) in enumerate(zip(player2.history, expected_actions2)):
652+
self.assertEqual((i, play), (i, expected_play))
653653

654654
# Test final player attributes are as expected
655655
if attrs:

axelrod/tests/strategies/test_punisher.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_strategy(self):
154154

155155
class TestTrickyLevelPunisher(TestPlayer):
156156

157-
name = "Level Punisher"
157+
name = "Tricky Level Punisher"
158158
player = axl.TrickyLevelPunisher
159159
expected_classifier = {
160160
"memory_depth": float("inf"), # Long memory
@@ -171,25 +171,20 @@ def test_strategy(self):
171171
actions = [(C, C)] * 9
172172
self.versus_test(opponent=axl.Cooperator(), expected_actions=actions)
173173

174-
# After 10 rounds
175174
# Check if number of defections by opponent is greater than 20%
176-
opponent = axl.MockPlayer([C] * 4 + [D] * 2 + [C] * 3 + [D])
177-
actions = [(C, C)] * 4 + [(C, D)] * 2 + [(C, C)] * 3 + [(C, D), (D, C)]
175+
op_actions = [C] * 6 + [D] * 4
176+
opponent = axl.MockPlayer(op_actions)
177+
actions = list(zip([C] * 7 + [D] * 3, op_actions))
178178
self.versus_test(opponent=opponent, expected_actions=actions)
179179

180180
# Check if number of defections by opponent is greater than 10%
181-
opponent = axl.MockPlayer([C] * 4 + [D] + [C] * 4 + [D])
182-
actions = [(C, C)] * 4 + [(C, D)] + [(C, C)] * 4 + [(C, D), (C, C)]
181+
op_actions = [C] * 8 + [D, C]
182+
opponent = axl.MockPlayer(op_actions)
183+
actions = list(zip([C] * 9 + [D], op_actions))
183184
self.versus_test(opponent=opponent, expected_actions=actions)
184185

185-
# After 10 rounds
186186
# Check if number of defections by opponent is greater than 5%
187-
opponent = axl.MockPlayer([C] * 4 + [D] + [C] * 5)
188-
actions = [(C, C)] * 4 + [(C, D)] + [(C, C)] * 5
187+
op_actions = [C] * 18 + [D, C]
188+
opponent = axl.MockPlayer(op_actions)
189+
actions = list(zip([C] * 19 + [D], op_actions))
189190
self.versus_test(opponent=opponent, expected_actions=actions)
190-
191-
# Check if number of defections by opponent is less than 5%
192-
opponent = axl.MockPlayer([C] * 10)
193-
actions = [(C, C)] * 5
194-
self.versus_test(opponent=opponent, expected_actions=actions)
195-

0 commit comments

Comments
 (0)