Skip to content

Commit c4f685d

Browse files
alajaramarcharper
authored andcommitted
Update test_stalker.py (#943)
* Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py * Update test_stalker.py unittest on my machine is giving me different results from the results here. * Update test_stalker.py * Update test_stalker.py change the results back to the way Appveyor test results show * Update test_stalker.py * Update test_stalker.py line 34 test, the test error is showing that stalker will cooperate until the last round, the Mock Player cooperates. I am changing it to the way tests outcomes show. But as previous builds, the current average score > very good score tests does not get tested. * Add a test for average_score > good score. This requires tricking the player to defect before the end of the game. * Fix the broken import.
1 parent 6888db2 commit c4f685d

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed
Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Tests for the Stalker strategy."""
22

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

7-
C, D = axelrod.Actions.C, axelrod.Actions.D
7+
C, D = axl.Actions.C, axl.Actions.D
88

99
class TestStalker(TestPlayer):
1010

1111
name = "Stalker: D"
12-
player = axelrod.Stalker
12+
player = axl.Stalker
1313
expected_classifier = {
1414
'memory_depth': float('inf'),
1515
'stochastic': True,
@@ -21,26 +21,53 @@ class TestStalker(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24+
2425
# Start with cooperation
2526
self.first_play_test(C)
2627

27-
# current_average_score > very_good_score
28-
self.responses_test([D], [C] * 2 + [D] * 4, [D] * 2 + [C] * 4)
29-
self.responses_test([D], [D] * 2 + [C] * 4, [C] * 6)
28+
29+
actions = [(C, D)] * 2 + [(C, C), (D, C), (C, C), (C, C), (D, D)]
30+
self.versus_test(opponent=axl.MockPlayer([D] * 2 + [C] * 4),
31+
expected_actions=actions)
32+
33+
actions = [(C, C)] * 3 + [(D, C)]
34+
self.versus_test(opponent=axl.Cooperator(), expected_actions=actions)
3035

3136
# wish_score < current_average_score < very_good_score
32-
self.responses_test([C], [C] * 7 + [D] * 2, [C] * 7 + [D] * 2)
33-
self.responses_test([C], [C] * 7 + [C], [C] * 7 + [D])
37+
actions = [(C, C)] * 7 + [(C, D), (C, D), (C, C), (C, C), (D, C)]
38+
self.versus_test(opponent=axl.MockPlayer(actions=[C] * 7 + [D] * 2),
39+
expected_actions=actions)
40+
41+
actions = [(C, C)] * 7 + [(C, D), (C, C), (D, C)]
42+
self.versus_test(opponent=axl.MockPlayer(actions=[C] * 7 + [D]),
43+
expected_actions=actions)
3444

3545
# current_average_score > 2
36-
self.responses_test([C], [C] * 10, [C] * 10)
46+
actions = [(C, C)] * 9 + [(D, C)]
47+
self.versus_test(axl.Cooperator(), expected_actions=actions)
3748

3849
# 1 < current_average_score < 2
39-
self.responses_test([D], [C] * 7 + [C] * 5, [C] * 7 + [D] * 5)
50+
actions = [(C, C)] * 7 + [(C, D)] * 4 + [(D, D)]
51+
self.versus_test(opponent=axl.MockPlayer(actions=[C] * 7 + [D] * 5),
52+
expected_actions=actions)
4053

4154
# current_average_score < 1
42-
self.responses_test([D], [D] * 7 + [C] * 5, [D] * 7 + [D] * 5, seed = 6)
43-
self.responses_test([C], [D] * 7 + [C] * 5, [D] * 7 + [D] * 5, seed = 7)
55+
actions = [(C, D)] + [(D, D)] * 2 + [(C, D)] * 3 + [(D, D),
56+
(C, D), (D, D), (C, D), (D, D), (C, D), (D, D)]
57+
self.versus_test(axl.Defector(), expected_actions=actions, seed=6)
58+
59+
actions = [(C, D)] * 3 + [(D, D), (C, D), (D, D), (C, D),
60+
(C, D), (D, D), (C, D), (C, D), (C, D), (D, D)]
61+
self.versus_test(axl.Defector(), expected_actions=actions, seed=7)
4462

4563
# defect in last round
46-
self.responses_test([C, D], [C] * 198, [C] * 198, length=200)
64+
actions = [(C, C)] * 199 + [(D, C)]
65+
self.versus_test(axl.Cooperator(), expected_actions=actions,
66+
match_attributes={"length": 200})
67+
68+
# Force a defection before the end of the actual match which ensures
69+
# that current_average_score > very_good_score
70+
actions = [(C, C)] * 3 + [(D, C)] * 3
71+
self.versus_test(opponent=axl.Cooperator(),
72+
expected_actions=actions,
73+
match_attributes={"length": 4})

0 commit comments

Comments
 (0)