Skip to content

Commit fd58895

Browse files
committed
Remove unneeded tests
Remove first_play_test and second_play_test with a view to have all strategies tested via matches. Have also adjusted the docs. Closes #1038
1 parent 8896e66 commit fd58895

Some content is hidden

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

47 files changed

+199
-551
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: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,3 @@ def strategy(self, opponent: Player) -> Action:
4040
return action
4141
except StopIteration:
4242
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class TestAlternator(TestPlayer):
2121
}
2222

2323
def test_strategy(self):
24-
# Starts by cooperating.
25-
self.first_play_test(C)
2624

2725
actions = [(C, C), (D, C)] * 5
2826
self.versus_test(axelrod.Cooperator(), expected_actions=actions)

axelrod/tests/strategies/test_ann.py

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

3535
def test_strategy(self):
36-
# Test initial play sequence
37-
self.first_play_test(C)
3836

3937
actions = [(C, C)] * 5
4038
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -61,8 +59,6 @@ class TestEvolvedANN5(TestPlayer):
6159
}
6260

6361
def test_strategy(self):
64-
# Test initial play sequence
65-
self.first_play_test(C)
6662

6763
actions = [(C, C)] * 5
6864
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -86,8 +82,6 @@ class TestEvolvedANNNoise05(TestPlayer):
8682
}
8783

8884
def test_strategy(self):
89-
# Test initial play sequence
90-
self.first_play_test(C)
9185

9286
actions = [(C, C)] * 5
9387
self.versus_test(axelrod.Cooperator(), expected_actions=actions)

axelrod/tests/strategies/test_apavlov.py

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

2323
def test_strategy(self):
24-
self.first_play_test(C)
2524

2625
actions = [(C, C)] * 7
2726
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
@@ -80,7 +79,6 @@ class TestAPavlov2011(TestPlayer):
8079
}
8180

8281
def test_strategy(self):
83-
self.first_play_test(C)
8482

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

axelrod/tests/strategies/test_appeaser.py

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

2323
def test_strategy(self):
24-
# Starts by cooperating.
25-
self.first_play_test(C)
2624

2725
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
2826
self.versus_test(axelrod.Cooperator(), expected_actions=actions)

axelrod/tests/strategies/test_averagecopier.py

Lines changed: 0 additions & 7 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,9 +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)
8780

8881
# Tests that if opponent has played all C then player chooses C.
8982
actions = [(C, C)] * 10

axelrod/tests/strategies/test_axelrod_first.py

Lines changed: 0 additions & 16 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,7 +59,6 @@ class TestRevisedDowning(TestPlayer):
6059
}
6160

6261
def test_strategy(self):
63-
self.first_play_test(C)
6462

6563
actions = [(C, C), (C, C), (C, C)]
6664
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -136,7 +134,6 @@ def test_decay(self):
136134
player._end_coop_prob)
137135

138136
def test_strategy(self):
139-
self.first_play_test(C)
140137

141138
actions = [(C, C)] * 41 + [(D, C)]
142139
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
@@ -165,7 +162,6 @@ class TestGrofman(TestPlayer):
165162
}
166163

167164
def test_strategy(self):
168-
self.first_play_test(C)
169165

170166
actions = [(C, C)] * 7
171167
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -201,7 +197,6 @@ def test_four_vector(self):
201197
test_four_vector(self, expected_dictionary)
202198

203199
def test_strategy(self):
204-
self.first_play_test(C)
205200

206201
actions = [(C, C), (C, C), (C, C), (C, C)]
207202
self.versus_test(axelrod.Cooperator(), expected_actions=actions, seed=1)
@@ -251,8 +246,6 @@ def test_score_history(self):
251246

252247
def test_strategy(self):
253248
# Test TFT-type initial play
254-
self.first_play_test(C)
255-
256249
# Test trailing post-round 3 play
257250

258251
actions = [(C, C)] * 9
@@ -287,11 +280,6 @@ class TestShubik(TestPlayer):
287280
}
288281

289282
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-
295283
actions = [(C, C), (C, C), (C, C)]
296284
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
297285

@@ -332,7 +320,6 @@ class TestTullock(TestPlayer):
332320

333321
def test_strategy(self):
334322
"""Cooperates for first ten rounds"""
335-
self.first_play_test(C)
336323

337324
actions = [(C, C), (C, D)] * 5
338325
self.versus_test(axelrod.Alternator(), expected_actions=actions)
@@ -377,7 +364,6 @@ class TestUnnamedStrategy(TestPlayer):
377364
}
378365

379366
def test_strategy(self):
380-
self.first_play_test(C)
381367

382368
actions = [(D, C), (C, C), (C, C), (D, C), (C, C), (C, C)]
383369
self.versus_test(axelrod.Cooperator(), expected_actions=actions, seed=1)
@@ -411,7 +397,6 @@ def test_init(self):
411397
self.assertIsNone(player.opponent_is_random)
412398

413399
def test_strategy(self):
414-
self.first_play_test(C)
415400

416401
# Our Player (SteinAndRapoport) vs Cooperator
417402
# After 15th round (pvalue < alpha) still plays titfortat
@@ -461,4 +446,3 @@ def test_strategy(self):
461446
self.versus_test(opponent, expected_actions=actions,
462447
match_attributes={"length": -1},
463448
attrs={"opponent_is_random": False})
464-

axelrod/tests/strategies/test_axelrod_second.py

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

2424
def test_strategy(self):
25-
# Initially cooperates
26-
self.first_play_test(C)
2725

2826
# Cooperates for num_rounds / 20 (10 by default)
2927

@@ -66,8 +64,6 @@ class TestEatherley(TestPlayer):
6664
}
6765

6866
def test_strategy(self):
69-
# Initially cooperates
70-
self.first_play_test(C)
7167
# Test cooperate after opponent cooperates
7268
actions = [(C, C)] * 5
7369
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
@@ -107,9 +103,6 @@ class TestTester(TestPlayer):
107103
}
108104

109105
def test_strategy(self):
110-
"""Starts by defecting."""
111-
self.first_play_test(D)
112-
113106

114107
# Alternate after 3rd round if opponent only cooperates
115108
actions = [(D, C)] + [(C, C), (C, C)] + [(D, C), (C, C)] * 4

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)