def test_sample_length(self, prob_end, rm): rr = axelrod.ProbEndRoundRobinMatches(self.players, prob_end, test_game, test_repetitions) self.assertGreaterEqual(rr.sample_length(prob_end), 1) try: self.assertIsInstance(rr.sample_length(prob_end), int) except AssertionError: self.assertEqual(rr.sample_length(prob_end), float("inf"))
def test_len(self, prob_end): repetitions = 10 rr = axelrod.ProbEndRoundRobinMatches(self.players, prob_end, game=None, repetitions=repetitions) self.assertEqual(len(rr), len(list(rr.build_match_chunks()))) self.assertAlmostEqual(rr.estimated_size(), len(rr) * 1. / prob_end * repetitions)
def test_build_single_match_params(self, prob_end): rr = axelrod.ProbEndRoundRobinMatches(self.players, prob_end, test_game, test_repetitions) match_params = rr.build_single_match_params() self.assertIsInstance(match_params, tuple) self.assertIsInstance(match_params[0], int) self.assertLess(match_params[0], float('inf')) self.assertGreater(match_params[0], 0) self.assertEqual(match_params[1], rr.game) self.assertEqual(match_params[2], None) self.assertEqual(match_params[3], 0) # Check that can build a match players = [axelrod.Cooperator(), axelrod.Defector()] match_params = [players] + list(match_params) match = axelrod.Match(*match_params) self.assertIsInstance(match, axelrod.Match) self.assertLess(len(match), float('inf')) self.assertGreater(len(match), 0) self.assertEqual(match.players[0].match_attributes['length'], float('inf')) # Testing with noise rr = axelrod.ProbEndRoundRobinMatches(self.players, prob_end, test_game, test_repetitions, noise=0.5) match_params = rr.build_single_match_params() self.assertIsInstance(match_params, tuple) self.assertLess(match_params[0], float('inf')) self.assertGreater(match_params[0], 0) self.assertEqual(match_params[1], rr.game) self.assertEqual(match_params[2], None) self.assertEqual(match_params[3], .5) # Check that can build a match players = [axelrod.Cooperator(), axelrod.Defector()] match_params = [players] + list(match_params) match = axelrod.Match(*match_params) self.assertIsInstance(match, axelrod.Match) self.assertLess(len(match), float('inf')) self.assertGreater(len(match), 0)
def test_build_match_chunks(self, repetitions, prob_end): rr = axelrod.ProbEndRoundRobinMatches(self.players, prob_end, test_game, repetitions) chunks = list(rr.build_match_chunks()) match_definitions = [ tuple(list(index_pair) + [repetitions]) for (index_pair, match_params, repetitions) in chunks ] expected_match_definitions = [(i, j, repetitions) for i in range(5) for j in range(i, 5)] self.assertEqual(sorted(match_definitions), sorted(expected_match_definitions))
def test_build_matches_different_length(self, prob_end): """ If prob end is not 0 or 1 then the matches should all have different length Theoretically, this test could fail as it's probabilistically possible to sample all games with same length. """ rr = axelrod.ProbEndRoundRobinMatches(self.players, prob_end, test_game, test_repetitions) chunks = rr.build_match_chunks() match_lengths = [ match_params[0] for (index_pair, match_params, repetitions) in chunks ] self.assertNotEqual(min(match_lengths), max(match_lengths))