File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -149,10 +149,17 @@ def __eq__(self, other):
149
149
generator , original_value = itertools .tee (value )
150
150
other_generator , original_other_value = itertools .tee (other_value )
151
151
152
- setattr (self , attribute ,
153
- (ele for ele in original_value ))
154
- setattr (other , attribute ,
155
- (ele for ele in original_other_value ))
152
+
153
+ if isinstance (value , types .GeneratorType ):
154
+ setattr (self , attribute ,
155
+ (ele for ele in original_value ))
156
+ setattr (other , attribute ,
157
+ (ele for ele in original_other_value ))
158
+ else :
159
+ setattr (self , attribute ,
160
+ itertools .cycle (original_value ))
161
+ setattr (other , attribute ,
162
+ itertools .cycle (original_other_value ))
156
163
157
164
if not (all (next (generator ) == next (other_generator )
158
165
for _ in range (200 ))):
Original file line number Diff line number Diff line change @@ -207,6 +207,9 @@ def test_equality_for_generator(self):
207
207
self .assertEqual (list (p1 .generator ), list (range (10 )))
208
208
self .assertEqual (list (p2 .generator ), list (range (1 , 10 )))
209
209
210
+ # Check that type is generator
211
+ self .assertIsInstance (p2 .generator , types .GeneratorType )
212
+
210
213
def test_equality_for_cycle (self ):
211
214
"""Test equality works with cycle attribute and that the cycle attribute
212
215
is not altered during checking of equality"""
@@ -231,11 +234,15 @@ def test_equality_for_cycle(self):
231
234
self .assertEqual (next (p1 .cycle ), 0 )
232
235
self .assertEqual (next (p2 .cycle ), 1 )
233
236
237
+ # Check that type is cycle
238
+ self .assertIsInstance (p2 .cycle , itertools .cycle )
239
+
234
240
def test_equaity_on_init (self ):
235
241
"""Test all instances of a strategy are equal on init"""
236
242
for s in axelrod .strategies :
237
243
p1 , p2 = s (), s ()
238
- # Check twice (so testing equality doesn't change anything)
244
+ # Check three times (so testing equality doesn't change anything)
245
+ self .assertEqual (p1 , p2 )
239
246
self .assertEqual (p1 , p2 )
240
247
self .assertEqual (p1 , p2 )
241
248
You can’t perform that action at this time.
0 commit comments