File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1
1
from collections import defaultdict
2
2
from functools import wraps
3
+ import types
3
4
import random
4
5
import copy
6
+ import numpy as np
5
7
6
8
from axelrod .actions import Actions , flip_action , Action
7
9
from .game import DefaultGame
@@ -189,3 +191,21 @@ def reset(self):
189
191
self .cooperations = 0
190
192
self .defections = 0
191
193
self .state_distribution = defaultdict (int )
194
+
195
+ def __eq__ (self , other ):
196
+ """
197
+ Test if two players are equal.
198
+ """
199
+ check = self .__repr__ () == other .__repr__ ()
200
+ for attribute , value in self .__dict__ .items ():
201
+ other_value = getattr (other , attribute )
202
+
203
+ if isinstance (value , np .ndarray ):
204
+ check = check and np .array_equal (value , other_value )
205
+
206
+ elif isinstance (value , types .GeneratorType ):
207
+ check = check and all (next (value ) == next (other_value )
208
+ for _ in range (10 ))
209
+ else :
210
+ check = check and value == other_value
211
+ return check
Original file line number Diff line number Diff line change @@ -32,11 +32,11 @@ def test_init_with_clone(self):
32
32
self .assertEqual (tt .turns , test_turns )
33
33
player = tt .players [0 ]
34
34
opponent = tt .opponents [0 ]
35
- self .assertEqual (player . name , opponent . name )
36
- self .assertNotEqual (player , opponent )
35
+ self .assertEqual (player , opponent )
36
+ self .assertIsNot (player , opponent )
37
37
# Check that the two player instances are wholly independent
38
38
opponent .name = 'Test'
39
- self .assertNotEqual (player . name , opponent . name )
39
+ self .assertNotEqual (player , opponent )
40
40
41
41
def test_len (self ):
42
42
tt = axelrod .MatchGenerator (
You can’t perform that action at this time.
0 commit comments