Skip to content

Commit b898304

Browse files
eric-s-smarcharper
authored andcommitted
test_gradualkiller now uses self.versus_test
1 parent 3806862 commit b898304

File tree

1 file changed

+44
-65
lines changed

1 file changed

+44
-65
lines changed
Lines changed: 44 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Tests for the Gradual Killer strategy."""
22

3-
import axelrod
3+
import axelrod as axl
44
from .test_player import TestPlayer
55

6-
C, D = axelrod.Actions.C, axelrod.Actions.D
6+
C, D = axl.Actions.C, axl.Actions.D
77

88

99
class TestGradualKiller(TestPlayer):
1010

1111
name = "Gradual Killer: ('D', 'D', 'D', 'D', 'D', 'C', 'C')"
12-
player = axelrod.GradualKiller
12+
player = axl.GradualKiller
1313
expected_classifier = {
1414
'memory_depth': float('Inf'),
1515
'stochastic': False,
@@ -19,78 +19,57 @@ class TestGradualKiller(TestPlayer):
1919
'manipulates_state': False
2020
}
2121

22-
def test_strategy(self):
23-
# Starts by defecting.
24-
self.first_play_test(D)
25-
self.second_play_test(D, D, D, D)
26-
# First seven moves.
27-
self.responses_test([D, D, D, D, D, C, C])
22+
first_seven = [D, D, D, D, D, C, C]
23+
24+
def test_first_seven_moves_always_the_same(self):
25+
opponent = axl.Cooperator()
26+
actions = list(zip(self.first_seven, [C] * 7))
27+
self.versus_test(opponent, expected_actions=actions)
28+
29+
opponent = axl.Defector()
30+
actions = list(zip(self.first_seven, [D] * 7))
31+
self.versus_test(opponent, expected_actions=actions)
32+
33+
opponent = axl.Alternator()
34+
actions = list(zip(self.first_seven, [C, D] * 4))
35+
self.versus_test(opponent, expected_actions=actions)
2836

2937
def test_effect_of_strategy_with_history_CC(self):
3038
"""Continues with C if opponent played CC on 6 and 7."""
31-
P1 = axelrod.GradualKiller()
32-
P2 = axelrod.Player()
33-
P1.history = [D, D, D, D, D, C, C]
34-
P2.history = [C, C, C, C, C, C, C]
35-
self.assertEqual(P1.strategy(P2), 'C')
36-
P1.history = [D, D, D, D, D, C, C, C]
37-
P2.history = [C, C, C, C, C, C, C, C]
38-
self.assertEqual(P1.strategy(P2), 'C')
39-
P1.history = [D, D, D, D, D, C, C, C, C]
40-
P2.history = [C, C, C, C, C, C, C, C, C]
41-
self.assertEqual(P1.strategy(P2), 'C')
42-
P1.history = [D, D, D, D, D, C, C, C, C, C]
43-
P2.history = [C, C, C, C, C, C, C, C, C, C]
44-
self.assertEqual(P1.strategy(P2), 'C')
39+
opponent_actions = [D] * 5 + [C, C] + [D, C] * 20
40+
opponent = axl.MockPlayer(actions=opponent_actions)
41+
42+
start = list(zip(self.first_seven, opponent_actions[:7]))
43+
actions = start + [(C, D), (C, C)] * 20
44+
45+
self.versus_test(opponent, expected_actions=actions)
4546

4647
def test_effect_of_strategy_with_history_CD(self):
4748
"""Continues with C if opponent played CD on 6 and 7."""
48-
P1 = axelrod.GradualKiller()
49-
P2 = axelrod.Player()
50-
P1.history = [D, D, D, D, D, C, C]
51-
P2.history = [C, C, C, C, C, C, D]
52-
self.assertEqual(P1.strategy(P2), 'C')
53-
P1.history = [D, D, D, D, D, C, C, C]
54-
P2.history = [C, C, C, C, C, C, D, D]
55-
self.assertEqual(P1.strategy(P2), 'C')
56-
P1.history = [D, D, D, D, D, C, C, C, C]
57-
P2.history = [C, C, C, C, C, C, D, D, C]
58-
self.assertEqual(P1.strategy(P2), 'C')
59-
P1.history = [D, D, D, D, D, C, C, C, C, C]
60-
P2.history = [C, C, C, C, C, C, D, D, C, C]
61-
self.assertEqual(P1.strategy(P2), 'C')
49+
opponent_actions = [D] * 5 + [C, D] + [D, C] * 20
50+
opponent = axl.MockPlayer(actions=opponent_actions)
51+
52+
start = list(zip(self.first_seven, opponent_actions[:7]))
53+
actions = start + [(C, D), (C, C)] * 20
54+
55+
self.versus_test(opponent, expected_actions=actions)
6256

6357
def test_effect_of_strategy_with_history_DC(self):
6458
"""Continues with C if opponent played DC on 6 and 7."""
65-
P1 = axelrod.GradualKiller()
66-
P2 = axelrod.Player()
67-
P1.history = [D, D, D, D, D, C, C]
68-
P2.history = [C, C, C, C, C, D, C]
69-
self.assertEqual(P1.strategy(P2), 'C')
70-
P1.history = [D, D, D, D, D, C, C, C]
71-
P2.history = [C, C, C, C, C, D, C, C]
72-
self.assertEqual(P1.strategy(P2), 'C')
73-
P1.history = [D, D, D, D, D, C, C, C, C]
74-
P2.history = [C, C, C, C, C, D, C, C, D]
75-
self.assertEqual(P1.strategy(P2), 'C')
76-
P1.history = [D, D, D, D, D, C, C, C, C, C]
77-
P2.history = [C, C, C, C, C, D, C, C, D, C]
78-
self.assertEqual(P1.strategy(P2), 'C')
59+
opponent_actions = [D] * 5 + [D, C] + [D, C] * 20
60+
opponent = axl.MockPlayer(actions=opponent_actions)
61+
62+
start = list(zip(self.first_seven, opponent_actions[:7]))
63+
actions = start + [(C, D), (C, C)] * 20
64+
65+
self.versus_test(opponent, expected_actions=actions)
7966

8067
def test_effect_of_strategy_with_history_DD(self):
8168
"""Continues with D if opponent played DD on 6 and 7."""
82-
P1 = axelrod.GradualKiller()
83-
P2 = axelrod.Player()
84-
P1.history = [D, D, D, D, D, C, C]
85-
P2.history = [C, C, C, C, C, D, D]
86-
self.assertEqual(P1.strategy(P2), 'D')
87-
P1.history = [D, D, D, D, D, C, C, D]
88-
P2.history = [C, C, C, C, C, D, D, C]
89-
self.assertEqual(P1.strategy(P2), 'D')
90-
P1.history = [D, D, D, D, D, C, C, D, D]
91-
P2.history = [C, C, C, C, C, D, D, C, C]
92-
self.assertEqual(P1.strategy(P2), 'D')
93-
P1.history = [D, D, D, D, D, C, C, D, D, D]
94-
P2.history = [C, C, C, C, C, D, D, C, C, D]
95-
self.assertEqual(P1.strategy(P2), 'D')
69+
opponent_actions = [C] * 5 + [D, D] + [D, C] * 20
70+
opponent = axl.MockPlayer(actions=opponent_actions)
71+
72+
start = list(zip(self.first_seven, opponent_actions[:7]))
73+
actions = start + [(D, D), (D, C)] * 20
9674

75+
self.versus_test(opponent, expected_actions=actions)

0 commit comments

Comments
 (0)