Example #1
0
 def test_len(self):
     turns = 5
     repetitions = 10
     rr = axelrod.RoundRobinMatches(self.players,
                                    turns=turns,
                                    game=None,
                                    repetitions=repetitions)
     self.assertEqual(len(rr), len(list(rr.build_match_chunks())))
     self.assertEqual(rr.estimated_size(), len(rr) * turns * repetitions)
Example #2
0
    def test_build_match_chunks(self, repetitions):
        rr = axelrod.RoundRobinMatches(self.players, test_turns, 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))
Example #3
0
    def test_build_single_match_params(self):
        rr = axelrod.RoundRobinMatches(self.players, test_turns, test_game,
                                       test_repetitions)
        match_params = rr.build_single_match_params()
        self.assertIsInstance(match_params, tuple)
        self.assertEqual(match_params[0], rr.turns)
        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.assertEqual(len(match), test_turns)

        # Testing with noise
        rr = axelrod.RoundRobinMatches(self.players,
                                       test_turns,
                                       test_game,
                                       test_repetitions,
                                       noise=0.5)
        match_params = rr.build_single_match_params()
        self.assertIsInstance(match_params, tuple)
        self.assertEqual(match_params[0], rr.turns)
        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.assertEqual(len(match), test_turns)