@@ -172,6 +172,20 @@ def test_equality(self):
172
172
p2 .test = "29"
173
173
self .assertNotEqual (p1 , p2 )
174
174
175
+ p1 .test = "29"
176
+ self .assertEqual (p1 , p2 )
177
+
178
+ # Check that attributes of both players are tested.
179
+ p1 .another_attribute = [1 , 2 , 3 ]
180
+ self .assertNotEqual (p1 , p2 )
181
+ p2 .another_attribute = [1 , 2 , 3 ]
182
+ self .assertEqual (p1 , p2 )
183
+
184
+ p2 .another_attribute_2 = {1 : 2 }
185
+ self .assertNotEqual (p1 , p2 )
186
+ p1 .another_attribute_2 = {1 : 2 }
187
+ self .assertEqual (p1 , p2 )
188
+
175
189
def test_equality_for_numpy_array (self ):
176
190
# Check numpy array attribute (a special case)
177
191
p1 = axelrod .Cooperator ()
@@ -246,6 +260,40 @@ def test_equaity_on_init(self):
246
260
self .assertEqual (p1 , p2 )
247
261
self .assertEqual (p1 , p2 )
248
262
263
+ def test_equaity_on_with_player_attributes (self ):
264
+ """Test for a strange edge case where players have pointers to each
265
+ other"""
266
+ p1 = axelrod .Cooperator ()
267
+ p2 = axelrod .Cooperator ()
268
+
269
+ # If pointing at each other
270
+ p1 .player = p2
271
+ p2 .player = p1
272
+ self .assertEqual (p1 , p2 )
273
+
274
+ # Still checking other attributes.
275
+ p1 .test_attribute = "29"
276
+ self .assertNotEqual (p1 , p2 )
277
+
278
+ # If pointing at same strategy instances
279
+ p1 .player = axelrod .Cooperator ()
280
+ p2 .player = axelrod .Cooperator ()
281
+ p2 .test_attribute = "29"
282
+ self .assertEqual (p1 , p2 )
283
+
284
+
285
+ # If pointing at different strategy instances
286
+ p1 .player = axelrod .Cooperator ()
287
+ p2 .player = axelrod .Defector ()
288
+ self .assertNotEqual (p1 , p2 )
289
+
290
+ # If different strategies pointing at same strategy instances
291
+ p3 = axelrod .Defector ()
292
+ p1 .player = axelrod .Cooperator ()
293
+ p3 .player = axelrod .Cooperator ()
294
+ self .assertNotEqual (p1 , p3 )
295
+
296
+
249
297
def test_init_params (self ):
250
298
"""Tests player correct parameters signature detection."""
251
299
self .assertEqual (self .player .init_params (), {})
0 commit comments