Skip to content

Commit 5188f9d

Browse files
authored
Merge pull request #1039 from Axelrod-Python/1038
Remove unneeded tests
2 parents 8896e66 + 741b300 commit 5188f9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+237
-653
lines changed

axelrod/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .player import (
1414
get_state_distribution_from_history, is_basic, obey_axelrod,
1515
update_history, update_state_distribution, Player)
16-
from .mock_player import MockPlayer, simulate_play
16+
from .mock_player import MockPlayer
1717
from .match import Match
1818
from .moran import MoranProcess, MoranProcessGraph, ApproximateMoranProcess
1919
from .strategies import *

axelrod/mock_player.py

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,14 @@
1010

1111

1212
class MockPlayer(Player):
13-
"""Creates a mock player that copies a history and state distribution to
14-
simulate a history of play, and then plays a given sequence of actions. If
15-
no actions are given, plays like Cooperator.
13+
"""Creates a mock player that plays a given sequence of actions. If
14+
no actions are given, plays like Cooperator. Used for testing.
1615
"""
1716

1817
name = "Mock Player"
1918

20-
def __init__(self, actions: List[Action] =None, history: List[Action] =None, state_dist: defaultdict =None) -> None:
21-
# Need to retain history for opponents that examine opponents history
22-
# Do a deep copy just to be safe
19+
def __init__(self, actions: List[Action] = None) -> None:
2320
super().__init__()
24-
if history:
25-
# Make sure we both copy the history and get the right counts
26-
# for cooperations and defections.
27-
for action in history:
28-
update_history(self, action)
29-
if state_dist:
30-
self.state_distribution = dict(state_dist)
3121
if actions:
3222
self.actions = cycle(actions)
3323
else:
@@ -40,40 +30,3 @@ def strategy(self, opponent: Player) -> Action:
4030
return action
4131
except StopIteration:
4232
return C
43-
44-
45-
def simulate_play(player1: Player, player2: Player, action1: Action =None, action2: Action =None) -> Tuple[Action, Action]:
46-
"""
47-
Simulates play with or without forced history. If action1 and action2 are given, these
48-
actions are enforced in the players strategy. This generally should not be
49-
necessary, but various tests may force impossible or unlikely histories.
50-
"""
51-
52-
if action1 and action2:
53-
mock_player1 = MockPlayer(actions=[action1], history=player1.history)
54-
mock_player2 = MockPlayer(actions=[action2], history=player2.history)
55-
# Force plays
56-
s1 = player1.strategy(mock_player2)
57-
s2 = player2.strategy(mock_player1)
58-
if (s1 != action1) or (s2 != action2):
59-
warnings.warn(
60-
"Simulated play mismatch with expected history: Round was "
61-
"({}, {}) but ({}, {}) was expected for player: {}".format(
62-
s1, s2, action1, action2, str(player1))
63-
)
64-
# Record intended history
65-
# Update Cooperation / Defection counts
66-
update_history(player1, action1)
67-
update_history(player2, action2)
68-
update_state_distribution(player1, action1, action2)
69-
update_state_distribution(player2, action2, action1)
70-
return (s1, s2)
71-
else:
72-
s1 = player1.strategy(player2)
73-
s2 = player2.strategy(player1)
74-
# Record history
75-
update_history(player1, s1)
76-
update_history(player2, s2)
77-
update_state_distribution(player1, s1, s2)
78-
update_state_distribution(player2, s2, s1)
79-
return (s1, s2)

axelrod/tests/strategies/test_alternator.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class TestAlternator(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24-
# Starts by cooperating.
25-
self.first_play_test(C)
26-
2724
actions = [(C, C), (D, C)] * 5
2825
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
2926

axelrod/tests/strategies/test_ann.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class TestEvolvedANN(TestPlayer):
3333
}
3434

3535
def test_strategy(self):
36-
# Test initial play sequence
37-
self.first_play_test(C)
38-
3936
actions = [(C, C)] * 5
4037
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
4138

@@ -61,9 +58,6 @@ class TestEvolvedANN5(TestPlayer):
6158
}
6259

6360
def test_strategy(self):
64-
# Test initial play sequence
65-
self.first_play_test(C)
66-
6761
actions = [(C, C)] * 5
6862
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
6963

@@ -86,9 +80,6 @@ class TestEvolvedANNNoise05(TestPlayer):
8680
}
8781

8882
def test_strategy(self):
89-
# Test initial play sequence
90-
self.first_play_test(C)
91-
9283
actions = [(C, C)] * 5
9384
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
9485

axelrod/tests/strategies/test_apavlov.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class TestAPavlov2006(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24-
self.first_play_test(C)
25-
2624
actions = [(C, C)] * 7
2725
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
2826
attrs={"opponent_class": "Cooperative"})
@@ -80,7 +78,6 @@ class TestAPavlov2011(TestPlayer):
8078
}
8179

8280
def test_strategy(self):
83-
self.first_play_test(C)
8481

8582
actions = [(C, C)] * 8
8683
self.versus_test(axelrod.Cooperator(), expected_actions=actions,

axelrod/tests/strategies/test_appeaser.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class TestAppeaser(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24-
# Starts by cooperating.
25-
self.first_play_test(C)
26-
2724
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
2825
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
2926

axelrod/tests/strategies/test_averagecopier.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ class TestAverageCopier(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24-
# Test that the first strategy is picked randomly.
25-
self.first_play_test(C, seed=1)
26-
self.first_play_test(D, seed=2)
27-
2824
# Tests that if opponent has played all C then player chooses C.
2925
actions = [(C, C)] * 10
3026
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
@@ -81,10 +77,6 @@ class TestNiceAverageCopier(TestPlayer):
8177
}
8278

8379
def test_strategy(self):
84-
# Cooperates initially (not stochastic)
85-
self.first_play_test(C, seed=1)
86-
self.first_play_test(C, seed=2)
87-
8880
# Tests that if opponent has played all C then player chooses C.
8981
actions = [(C, C)] * 10
9082
self.versus_test(axelrod.Cooperator(), expected_actions=actions,

axelrod/tests/strategies/test_axelrod_first.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class TestDavis(TestPlayer):
2323
}
2424

2525
def test_strategy(self):
26-
self.first_play_test(C)
2726
# Cooperates for the first ten rounds
2827
actions = [(C, C)] * 10
2928
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -60,8 +59,6 @@ class TestRevisedDowning(TestPlayer):
6059
}
6160

6261
def test_strategy(self):
63-
self.first_play_test(C)
64-
6562
actions = [(C, C), (C, C), (C, C)]
6663
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
6764

@@ -136,8 +133,6 @@ def test_decay(self):
136133
player._end_coop_prob)
137134

138135
def test_strategy(self):
139-
self.first_play_test(C)
140-
141136
actions = [(C, C)] * 41 + [(D, C)]
142137
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
143138
seed=1)
@@ -165,8 +160,6 @@ class TestGrofman(TestPlayer):
165160
}
166161

167162
def test_strategy(self):
168-
self.first_play_test(C)
169-
170163
actions = [(C, C)] * 7
171164
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
172165

@@ -201,8 +194,6 @@ def test_four_vector(self):
201194
test_four_vector(self, expected_dictionary)
202195

203196
def test_strategy(self):
204-
self.first_play_test(C)
205-
206197
actions = [(C, C), (C, C), (C, C), (C, C)]
207198
self.versus_test(axelrod.Cooperator(), expected_actions=actions, seed=1)
208199

@@ -251,8 +242,6 @@ def test_score_history(self):
251242

252243
def test_strategy(self):
253244
# Test TFT-type initial play
254-
self.first_play_test(C)
255-
256245
# Test trailing post-round 3 play
257246

258247
actions = [(C, C)] * 9
@@ -287,11 +276,6 @@ class TestShubik(TestPlayer):
287276
}
288277

289278
def test_strategy(self):
290-
# Starts by Cooperating
291-
self.first_play_test(C)
292-
# Looks like Tit-For-Tat at first
293-
self.second_play_test(C, D, C, D)
294-
295279
actions = [(C, C), (C, C), (C, C)]
296280
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
297281

@@ -332,8 +316,6 @@ class TestTullock(TestPlayer):
332316

333317
def test_strategy(self):
334318
"""Cooperates for first ten rounds"""
335-
self.first_play_test(C)
336-
337319
actions = [(C, C), (C, D)] * 5
338320
self.versus_test(axelrod.Alternator(), expected_actions=actions)
339321

@@ -377,8 +359,6 @@ class TestUnnamedStrategy(TestPlayer):
377359
}
378360

379361
def test_strategy(self):
380-
self.first_play_test(C)
381-
382362
actions = [(D, C), (C, C), (C, C), (D, C), (C, C), (C, C)]
383363
self.versus_test(axelrod.Cooperator(), expected_actions=actions, seed=1)
384364

@@ -411,8 +391,6 @@ def test_init(self):
411391
self.assertIsNone(player.opponent_is_random)
412392

413393
def test_strategy(self):
414-
self.first_play_test(C)
415-
416394
# Our Player (SteinAndRapoport) vs Cooperator
417395
# After 15th round (pvalue < alpha) still plays titfortat
418396
# Note it always defects on the last two rounds
@@ -461,4 +439,3 @@ def test_strategy(self):
461439
self.versus_test(opponent, expected_actions=actions,
462440
match_attributes={"length": -1},
463441
attrs={"opponent_is_random": False})
464-

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class TestChampion(TestPlayer):
2222
}
2323

2424
def test_strategy(self):
25-
# Initially cooperates
26-
self.first_play_test(C)
27-
2825
# Cooperates for num_rounds / 20 (10 by default)
2926

3027
actions = [(C, C), (C, D)] * 5 # Cooperate for ten rounds
@@ -66,8 +63,6 @@ class TestEatherley(TestPlayer):
6663
}
6764

6865
def test_strategy(self):
69-
# Initially cooperates
70-
self.first_play_test(C)
7166
# Test cooperate after opponent cooperates
7267
actions = [(C, C)] * 5
7368
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -107,10 +102,6 @@ class TestTester(TestPlayer):
107102
}
108103

109104
def test_strategy(self):
110-
"""Starts by defecting."""
111-
self.first_play_test(D)
112-
113-
114105
# Alternate after 3rd round if opponent only cooperates
115106
actions = [(D, C)] + [(C, C), (C, C)] + [(D, C), (C, C)] * 4
116107
self.versus_test(axelrod.Cooperator(), expected_actions=actions,

axelrod/tests/strategies/test_backstabber.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class TestBackStabber(TestPlayer):
2424
}
2525

2626
def test_defects_after_four_defections(self):
27-
self.first_play_test(C)
2827
# Forgives three defections
2928
defector_actions = [(C, D), (C, D), (C, D), (C, D), (D, D), (D, D)]
3029
self.versus_test(axelrod.Defector(), expected_actions=defector_actions, match_attributes={"length": 200})

0 commit comments

Comments
 (0)