Skip to content

Commit 08bb03e

Browse files
eric-s-sdrvinceknight
authored andcommitted
branch switch
1 parent ec8bb2a commit 08bb03e

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

axelrod/my_t.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
C, D = axl.Action.C, axl.Action.D
55

6+
67
@st.FlipTransformer()
78
@st.FlipTransformer()
89
class TestFlip(axl.Cooperator):
@@ -13,6 +14,7 @@ class TestFlip(axl.Cooperator):
1314
class Apology(axl.Cooperator):
1415
pass
1516

17+
1618
@st.DeadlockBreakingTransformer(name_prefix=None)
1719
class DeadlockBreaking(axl.Cooperator):
1820
pass

axelrod/strategy_transformers.py

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def reducer(self_):
147147
class_module = __import__(self_.__module__)
148148
if self_.__class__.__name__ in dir(class_module):
149149
return self_.__class__, (), self_.__dict__
150+
151+
150152
else:
151153
print('oops {} {}'.format(
152154
self_.__class__.__name__, self_.original_class.__name__

axelrod/test_pickling.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99

1010

1111
class TestPickle(unittest.TestCase):
12+
13+
def assert_original_acts_same_as_pickled(self, player, turns=100):
14+
copy = pickle.loads(pickle.dumps(player))
15+
opponent_1 = axl.CyclerCCCDCD()
16+
opponent_2 = axl.CyclerCCCDCD()
17+
axl.seed(0)
18+
match_1 = axl.Match((player, opponent_1), turns=turns)
19+
result_1 = match_1.play()
20+
21+
axl.seed(0)
22+
match_2 = axl.Match((copy, opponent_2), turns=turns)
23+
result_2 = match_2.play()
24+
25+
self.assertEqual(result_1, result_2)
26+
1227
def test_parameterized_player(self):
1328
p1 = axl.Cooperator()
1429
p2 = axl.Cycler('DDCCDD')
@@ -37,21 +52,11 @@ def test_final_transformer_called(self):
3752
results = match.play()
3853
self.assertEqual(results, [(C, C), (C, C), (D, D)])
3954

55+
self.assert_original_acts_same_as_pickled(axl.Alexei(), turns=10)
56+
4057
def test_nice_transformer_called(self):
4158
player = axl.NMWEDeterministic()
42-
copy = pickle.loads(pickle.dumps(player))
43-
opponent_1 = axl.CyclerCCCDCD()
44-
opponent_2 = axl.CyclerCCCDCD()
45-
axl.seed(0)
46-
match_1 = axl.Match((player, opponent_1), turns=100)
47-
result_1 = match_1.play()
48-
49-
axl.seed(0)
50-
match_2 = axl.Match((copy, opponent_2), turns=100)
51-
result_2 = match_2.play()
52-
53-
54-
self.assertEqual(result_1, result_2)
59+
self.assert_original_acts_same_as_pickled(player, turns=10)
5560

5661
def test_all(self):
5762
for s in axl.strategies:

0 commit comments

Comments
 (0)