Skip to content

Commit 308741e

Browse files
committed
Add inline comments and docstring.
1 parent caf2783 commit 308741e

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

axelrod/tests/strategies/test_player.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,34 +185,49 @@ def test_equality_for_numpy_array(self):
185185
self.assertNotEqual(p1, p2)
186186

187187
def test_equality_for_generator(self):
188-
# Check generator attribute (a special case)
188+
"""Test equality works with generator attribute and that the generator
189+
attribute is not altered during checking of equality"""
189190
p1 = axelrod.Cooperator()
190191
p2 = axelrod.Cooperator()
191-
# Check that the generator is still the same
192+
193+
# Check that players are equal with generator
192194
p1.generator = (i for i in range(10))
193195
p2.generator = (i for i in range(10))
194196
self.assertEqual(p1, p2)
195197

196-
_ = next(p2.generator)
198+
# Check state of one generator (ensure it hasn't changed)
199+
n = next(p2.generator)
200+
self.assertEqual(n, 0)
201+
202+
# Players are no longer equal (one generator has changed)
197203
self.assertNotEqual(p1, p2)
198204

199-
# Check that internal generator object has not been changed
205+
# Check that internal generator object has not been changed for either
206+
# player after latest equal check.
200207
self.assertEqual(list(p1.generator), list(range(10)))
201208
self.assertEqual(list(p2.generator), list(range(1, 10)))
202209

203210
def test_equality_for_cycle(self):
211+
"""Test equality works with cycle attribute and that the cycle attribute
212+
is not altered during checking of equality"""
204213
# Check cycle attribute (a special case)
205214
p1 = axelrod.Cooperator()
206215
p2 = axelrod.Cooperator()
207-
# Check that the cycle is still the same
216+
217+
# Check that players are equal with cycle
208218
p1.cycle = itertools.cycle(range(10))
209219
p2.cycle = itertools.cycle(range(10))
210220
self.assertEqual(p1, p2)
211221

212-
_ = next(p2.cycle)
222+
# Check state of one generator (ensure it hasn't changed)
223+
n = next(p2.cycle)
224+
self.assertEqual(n, 0)
225+
226+
# Players are no longer equal (one generator has changed)
213227
self.assertNotEqual(p1, p2)
214228

215-
# Check that internal generator object has not been changed
229+
# Check that internal cycle object has not been changed for either
230+
# player after latest not equal check.
216231
self.assertEqual(next(p1.cycle), 0)
217232
self.assertEqual(next(p2.cycle), 1)
218233

0 commit comments

Comments
 (0)