Skip to content

Commit cff633b

Browse files
committed
Merge pull request #556 from Axelrod-Python/555
Prob End Tournament can now take a cache
2 parents e988854 + e1a18bb commit cff633b

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

axelrod/tests/unit/test_tournament.py

+9-21
Original file line numberDiff line numberDiff line change
@@ -568,30 +568,18 @@ def test_init(self):
568568
anonymous_tournament = axelrod.Tournament(players=self.players)
569569
self.assertEqual(anonymous_tournament.name, 'axelrod')
570570

571-
@given(s=lists(sampled_from(axelrod.strategies),
572-
min_size=2, # Errors are returned if less than 2 strategies
573-
max_size=5, unique=True),
574-
prob_end=floats(min_value=.1, max_value=.9),
575-
repetitions=integers(min_value=2, max_value=4),
576-
rm=random_module())
577-
@settings(max_examples=50, timeout=0)
578-
@example(s=test_strategies, prob_end=test_prob_end,
579-
repetitions=test_repetitions,
580-
rm=random.seed(0))
581-
def test_build_cache_never_required(self, s, prob_end, repetitions, rm):
582-
"""
583-
As the matches have a sampled length a cache is never required.
584-
"""
585-
players = [strat() for strat in s]
586-
571+
# Test init when passing a cache:
572+
cache = axelrod.DeterministicCache()
587573
tournament = axelrod.ProbEndTournament(
588574
name=self.test_name,
589-
players=players,
575+
players=self.players,
590576
game=self.game,
591-
prob_end=prob_end,
592-
repetitions=repetitions)
593-
self.assertFalse(tournament._build_cache_required())
594-
577+
prob_end=self.test_prob_end,
578+
processes=4,
579+
noise=0.2,
580+
deterministic_cache=cache)
581+
self.assertEqual(tournament.deterministic_cache, cache)
582+
self.assertTrue(tournament.prebuilt_cache)
595583

596584
@given(s=lists(sampled_from(axelrod.strategies),
597585
min_size=2, # Errors are returned if less than 2 strategies

axelrod/tournament.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ class ProbEndTournament(Tournament):
310310

311311
def __init__(self, players, match_generator=ProbEndRoundRobinMatches,
312312
name='axelrod', game=None, prob_end=.5, repetitions=10,
313-
processes=None, prebuilt_cache=False, noise=0,
314-
with_morality=True):
313+
processes=None, deterministic_cache=None, prebuilt_cache=False,
314+
noise=0, with_morality=True):
315315
"""
316316
Parameters
317317
----------
@@ -339,15 +339,10 @@ def __init__(self, players, match_generator=ProbEndRoundRobinMatches,
339339
super(ProbEndTournament, self).__init__(
340340
players, name=name, game=game, turns=float("inf"),
341341
repetitions=repetitions, processes=processes,
342+
deterministic_cache=deterministic_cache,
342343
prebuilt_cache=prebuilt_cache, noise=noise,
343344
with_morality=with_morality)
344345

345346
self.prob_end = prob_end
346347
self.match_generator = ProbEndRoundRobinMatches(
347348
players, prob_end, self.game, self.deterministic_cache)
348-
349-
def _build_cache_required(self):
350-
"""
351-
A cache is never required (as every Match length can be different)
352-
"""
353-
return False

0 commit comments

Comments
 (0)