Skip to content

Commit 0fdac5f

Browse files
authored
Merge pull request #1034 from Axelrod-Python/884-player
Refactor tests for player.
2 parents 131f965 + dafc391 commit 0fdac5f

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

axelrod/player.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ def __eq__(self, other):
161161
setattr(other, attribute,
162162
itertools.cycle(original_other_value))
163163

164-
if not (all(next(generator) == next(other_generator)
165-
for _ in range(200))):
166-
return False
164+
for _ in range(200):
165+
try:
166+
if next(generator) != next(other_generator):
167+
return False
168+
except StopIteration:
169+
break
167170

168171
# Code for a strange edge case where each strategy points at each
169172
# other

axelrod/tests/strategies/test_player.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ def cooperate(*args):
2424
def defect(*args):
2525
return D
2626

27-
28-
def randomize(*args):
29-
return random.choice([C, D])
30-
3127
# Test classifier used to create tests players
3228
_test_classifier = {
3329
'memory_depth': 0,
@@ -98,13 +94,10 @@ def test_play(self):
9894
self.assertEqual(player2.state_distribution, {(D, C): 2})
9995

10096
def test_state_distribution(self):
101-
player1, player2 = self.player(), self.player()
102-
player1.strategy = randomize
103-
player2.strategy = randomize
104-
history_1 = [C, C, D, D, C]
105-
history_2 = [C, D, C, D, D]
106-
for h1, h2 in zip(history_1, history_2):
107-
simulate_play(player1, player2, h1, h2)
97+
player1 = axelrod.MockPlayer([C, C, D, D, C])
98+
player2 = axelrod.MockPlayer([C, D, C, D, D])
99+
match = axelrod.Match((player1, player2), turns=5)
100+
_ = match.play()
108101
self.assertEqual(player1.state_distribution,
109102
{(C, C): 1, (C, D): 2, (D, C): 1, (D, D): 1})
110103
self.assertEqual(player2.state_distribution,

0 commit comments

Comments
 (0)