@@ -172,7 +172,32 @@ def test_play(self):
172172 match = axelrod .Match (players , 3 , deterministic_cache = cache )
173173 self .assertEqual (match .play (), expected_result [:3 ])
174174
175- def test_long_cache (self ):
175+ def test_cache_grows (self ):
176+ """
177+ We want to make sure that if we try to use the cache for more turns than
178+ what is stored, then it will instead regenerate the result and overwrite
179+ the cache.
180+ """
181+ cache = DeterministicCache ()
182+ players = (axelrod .Cooperator (), axelrod .Defector ())
183+ match = axelrod .Match (players , 3 , deterministic_cache = cache )
184+ expected_result_5_turn = [(C , D ), (C , D ), (C , D ), (C , D ), (C , D )]
185+ expected_result_3_turn = [(C , D ), (C , D ), (C , D )]
186+ self .assertEqual (match .play (), expected_result_3_turn )
187+ match .turns = 5
188+ self .assertEqual (match .play (), expected_result_5_turn )
189+ # The cache should now hold the 5-turn result..
190+ self .assertEqual (
191+ cache [(axelrod .Cooperator (), axelrod .Defector ())],
192+ expected_result_5_turn
193+ )
194+
195+ def test_cache_doesnt_shrink (self ):
196+ """
197+ We want to make sure that when we access the cache looking for fewer
198+ turns than what is stored, then it will not overwrite the cache with the
199+ shorter result.
200+ """
176201 cache = DeterministicCache ()
177202 players = (axelrod .Cooperator (), axelrod .Defector ())
178203 match = axelrod .Match (players , 5 , deterministic_cache = cache )
0 commit comments