@@ -89,12 +89,8 @@ def test_example_prob_end(self):
89
89
self .assertEqual (len (match .play ()), expected_length )
90
90
self .assertEqual (match .noise , 0 )
91
91
self .assertEqual (match .game .RPST (), (3 , 1 , 0 , 5 ))
92
- self .assertEqual (len (match ._cache ), 3 )
93
-
94
- for expected_length in expected_lengths :
95
- self .assertEqual (
96
- match ._cache [(p1 , p2 , expected_length )], [(C , C )] * expected_length
97
- )
92
+ self .assertEqual (len (match ._cache ), 1 )
93
+ self .assertEqual (match ._cache [(p1 , p2 )], [(C , C )] * 5 )
98
94
99
95
@given (turns = integers (min_value = 1 , max_value = 200 ), game = games ())
100
96
@example (turns = 5 , game = axelrod .DefaultGame )
@@ -167,14 +163,29 @@ def test_play(self):
167
163
expected_result = [(C , D ), (C , D ), (C , D )]
168
164
self .assertEqual (match .play (), expected_result )
169
165
self .assertEqual (
170
- cache [(axelrod .Cooperator (), axelrod .Defector (), 3 )], expected_result
166
+ cache [(axelrod .Cooperator (), axelrod .Defector ())], expected_result
171
167
)
172
168
173
169
# a deliberately incorrect result so we can tell it came from the cache
174
- expected_result = [(C , C ), (D , D ), (D , C )]
175
- cache [(axelrod .Cooperator (), axelrod .Defector (), 3 )] = expected_result
170
+ expected_result = [(C , C ), (D , D ), (D , C ), ( C , C ), ( C , D ) ]
171
+ cache [(axelrod .Cooperator (), axelrod .Defector ())] = expected_result
176
172
match = axelrod .Match (players , 3 , deterministic_cache = cache )
177
- self .assertEqual (match .play (), expected_result )
173
+ self .assertEqual (match .play (), expected_result [:3 ])
174
+
175
+ def test_long_cache (self ):
176
+ cache = DeterministicCache ()
177
+ players = (axelrod .Cooperator (), axelrod .Defector ())
178
+ match = axelrod .Match (players , 5 , deterministic_cache = cache )
179
+ expected_result_5_turn = [(C , D ), (C , D ), (C , D ), (C , D ), (C , D )]
180
+ expected_result_3_turn = [(C , D ), (C , D ), (C , D )]
181
+ self .assertEqual (match .play (), expected_result_5_turn )
182
+ match .turns = 3
183
+ self .assertEqual (match .play (), expected_result_3_turn )
184
+ # The cache should still hold the 5.
185
+ self .assertEqual (
186
+ cache [(axelrod .Cooperator (), axelrod .Defector ())],
187
+ expected_result_5_turn
188
+ )
178
189
179
190
def test_scores (self ):
180
191
player1 = axelrod .TitForTat ()
0 commit comments