@@ -185,34 +185,49 @@ def test_equality_for_numpy_array(self):
185
185
self .assertNotEqual (p1 , p2 )
186
186
187
187
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"""
189
190
p1 = axelrod .Cooperator ()
190
191
p2 = axelrod .Cooperator ()
191
- # Check that the generator is still the same
192
+
193
+ # Check that players are equal with generator
192
194
p1 .generator = (i for i in range (10 ))
193
195
p2 .generator = (i for i in range (10 ))
194
196
self .assertEqual (p1 , p2 )
195
197
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)
197
203
self .assertNotEqual (p1 , p2 )
198
204
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.
200
207
self .assertEqual (list (p1 .generator ), list (range (10 )))
201
208
self .assertEqual (list (p2 .generator ), list (range (1 , 10 )))
202
209
203
210
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"""
204
213
# Check cycle attribute (a special case)
205
214
p1 = axelrod .Cooperator ()
206
215
p2 = axelrod .Cooperator ()
207
- # Check that the cycle is still the same
216
+
217
+ # Check that players are equal with cycle
208
218
p1 .cycle = itertools .cycle (range (10 ))
209
219
p2 .cycle = itertools .cycle (range (10 ))
210
220
self .assertEqual (p1 , p2 )
211
221
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)
213
227
self .assertNotEqual (p1 , p2 )
214
228
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.
216
231
self .assertEqual (next (p1 .cycle ), 0 )
217
232
self .assertEqual (next (p2 .cycle ), 1 )
218
233
0 commit comments