Skip to content

Commit defcc38

Browse files
committed
Add tests for noise.
1 parent 70aad20 commit defcc38

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

axelrod/tests/unit/test_match_generator.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,29 @@ def setUpClass(cls):
245245
cls.players = [s() for s in test_strategies]
246246

247247
@given(repetitions=integers(min_value=1, max_value=test_repetitions),
248-
prob_end=floats(min_value=.2, max_value=.7))
249-
@example(repetitions=test_repetitions, prob_end=.5)
250-
def test_build_match_chunks(self, repetitions, prob_end):
248+
prob_end=floats(min_value=.2, max_value=.7),
249+
noise=floats(min_value=0, max_value=1))
250+
@example(repetitions=test_repetitions, prob_end=.5, noise=0)
251+
def test_build_match_chunks(self, repetitions, prob_end, noise):
251252
edges = [(0, 1), (1, 2), (3, 4)]
252-
noise = 0
253253
pesp = axelrod.ProbEndSpatialMatches(
254254
self.players, prob_end, test_game, repetitions, noise, edges)
255255
chunks = list(pesp.build_match_chunks())
256-
match_definitions = [tuple(list(index_pair) + [repetitions])
257-
for (index_pair, match_params, repetitions) in chunks]
258-
expected_match_definitions = [(edge[0], edge[1], repetitions)
259-
for edge in edges]
260256

261-
self.assertEqual(sorted(match_definitions),
262-
sorted(expected_match_definitions))
257+
match_definitions = set()
258+
259+
cache = None
260+
attributes = {'game': test_game, 'length': float('inf'), 'noise': noise}
261+
expected_params_without_turns = (test_game, cache, noise, attributes)
262+
263+
for index_pair, match_params, repetitions in chunks:
264+
match_definitions.add(tuple(list(index_pair) + [repetitions]))
265+
self.assertEqual(match_params[1:], expected_params_without_turns)
266+
267+
expected_match_definitions = set((edge[0], edge[1], repetitions)
268+
for edge in edges)
269+
270+
self.assertEqual(match_definitions, expected_match_definitions)
263271

264272
def test_len(self):
265273
edges = [(0, 1), (1, 2), (3, 4)]
@@ -297,8 +305,7 @@ def test_build_matches_different_length(self, prob_end):
297305
chunks = pesp.build_match_chunks()
298306
match_lengths = [match_params[0]
299307
for (index_pair, match_params, repetitions) in chunks]
300-
self.assertNotEqual(min(match_lengths), max(match_lengths),
301-
msg=str(match_lengths))
308+
self.assertNotEqual(min(match_lengths), max(match_lengths))
302309

303310
@given(noise=floats(min_value=0, max_value=1),
304311
prob_end=floats(min_value=0, max_value=1))

axelrod/tests/unit/test_tournament.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ def test_init(self):
663663
self.assertTrue(tournament._with_morality)
664664
self.assertIsInstance(tournament._logger, logging.Logger)
665665
self.assertEqual(tournament.noise, 0.2)
666+
self.assertEqual(tournament.match_generator.noise, 0.2)
666667
self.assertEqual(tournament.prob_end, self.test_prob_end)
667668
anonymous_tournament = axelrod.Tournament(players=self.players)
668669
self.assertEqual(anonymous_tournament.name, 'axelrod')

0 commit comments

Comments
 (0)