예제 #1
0
 def test_seeding_inequality(self, repetitions=10):
     rr1 = axl.MatchGenerator(players=self.players,
                              turns=test_turns,
                              game=test_game,
                              repetitions=repetitions,
                              seed=0)
     chunks1 = list(rr1.build_match_chunks())
     rr2 = axl.MatchGenerator(players=self.players,
                              turns=test_turns,
                              game=test_game,
                              repetitions=repetitions,
                              seed=1)
     chunks2 = list(rr2.build_match_chunks())
     self.assertNotEqual(chunks1, chunks2)
예제 #2
0
 def test_len(self):
     turns = 5
     repetitions = 10
     rr = axelrod.MatchGenerator(players=self.players,
                                 turns=test_turns,
                                 game=test_game,
                                 repetitions=test_repetitions)
     self.assertEqual(len(rr), len(list(rr.build_match_chunks())))
예제 #3
0
 def test_init_with_graph_edges_not_including_all_players(self):
     edges = [(0, 1), (1, 2)]
     with self.assertRaises(ValueError):
         axelrod.MatchGenerator(players=self.players,
                                repetitions=3,
                                game=test_game,
                                turns=5,
                                edges=edges,
                                noise=0)
예제 #4
0
 def test_init_with_clone(self):
     tt = axelrod.MatchGenerator(self.players, test_turns, test_game,
                                 test_repetitions)
     self.assertEqual(tt.turns, test_turns)
     player = tt.players[0]
     opponent = tt.opponents[0]
     self.assertEqual(player, opponent)
     # Check that the two player instances are wholly independent
     opponent.name = 'John Nash'
     self.assertNotEqual(player.name, opponent.name)
예제 #5
0
    def test_build_match_chunks(self, repetitions):
        rr = axelrod.MatchGenerator(players=self.players,
                                    turns=test_turns,
                                    game=test_game,
                                    repetitions=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))
예제 #6
0
    def test_spatial_build_match_chunks(self, repetitions):
        cycle = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 1)]
        rr = axelrod.MatchGenerator(players=self.players,
                                    turns=test_turns,
                                    game=test_game,
                                    edges=cycle,
                                    repetitions=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, j in cycle]

        self.assertEqual(sorted(match_definitions),
                         sorted(expected_match_definitions))
예제 #7
0
    def test_build_single_match_params(self):
        rr = axelrod.MatchGenerator(players=self.players,
                                    turns=test_turns,
                                    game=test_game,
                                    repetitions=test_repetitions)
        match_params = rr.build_single_match_params()
        self.assertIsInstance(match_params, dict)
        self.assertEqual(match_params["turns"], test_turns)
        self.assertEqual(match_params["game"], test_game)
        self.assertEqual(match_params["noise"], 0)
        self.assertIsNone(match_params["prob_end"])

        # Check that can build a match
        players = [axelrod.Cooperator(), axelrod.Defector()]
        match_params["players"] = players
        match = axelrod.Match(**match_params)
        self.assertIsInstance(match, axelrod.Match)
        self.assertEqual(len(match), test_turns)
예제 #8
0
    def test_build_single_match_params_with_prob_end_and_noise(self):
        rr = axelrod.MatchGenerator(players=self.players,
                                    game=test_game,
                                    repetitions=test_repetitions,
                                    noise=0.5,
                                    prob_end=0.5)
        match_params = rr.build_single_match_params()
        self.assertIsInstance(match_params, dict)
        self.assertIsNone(match_params["turns"])
        self.assertEqual(match_params["game"], rr.game)
        self.assertEqual(match_params["prob_end"], .5)
        self.assertEqual(match_params["noise"], .5)

        # Check that can build a match
        players = [axelrod.Cooperator(), axelrod.Defector()]
        match_params["players"] = players
        match = axelrod.Match(**match_params)
        self.assertIsInstance(match, axelrod.Match)
        with self.assertRaises(TypeError):
            len(match)
예제 #9
0
    def test_build_single_match_params_with_prob_end_and_turns(self):
        rr = axelrod.MatchGenerator(players=self.players,
                                    game=test_game,
                                    repetitions=test_repetitions,
                                    turns=5,
                                    prob_end=0.5)
        match_params = rr.build_single_match_params()
        self.assertIsInstance(match_params, dict)
        self.assertEqual(match_params["turns"], 5)
        self.assertEqual(match_params["game"], test_game)
        self.assertEqual(match_params["prob_end"], .5)
        self.assertEqual(match_params["noise"], 0)

        # Check that can build a match
        players = [axelrod.Cooperator(), axelrod.Defector()]
        match_params["players"] = players
        match = axelrod.Match(**match_params)
        self.assertIsInstance(match, axelrod.Match)
        self.assertIsInstance(len(match), int)
        self.assertGreater(len(match), 0)
        self.assertLessEqual(len(match), 10)
예제 #10
0
    def test_build_single_match_params_with_fixed_length_unknown(self):
        rr = axelrod.MatchGenerator(players=self.players,
                                    game=test_game,
                                    repetitions=test_repetitions,
                                    turns=5,
                                    match_attributes={"length": float('inf')})
        match_params = rr.build_single_match_params()
        self.assertIsInstance(match_params, dict)
        self.assertEqual(match_params["turns"], 5)
        self.assertEqual(match_params["game"], test_game)
        self.assertEqual(match_params["prob_end"], None)
        self.assertEqual(match_params["noise"], 0)
        self.assertEqual(match_params["match_attributes"],
                         {"length": float('inf')})

        # Check that can build a match
        players = [axelrod.Cooperator(), axelrod.Defector()]
        match_params["players"] = players
        match = axelrod.Match(**match_params)
        self.assertIsInstance(match, axelrod.Match)
        self.assertEqual(len(match), 5)
        self.assertEqual(match.match_attributes, {"length": float('inf')})
예제 #11
0
 def test_single_match_params(self):
     tt = axelrod.MatchGenerator(self.players, test_turns, test_game,
                                 test_repetitions)
     with self.assertRaises(NotImplementedError):
         tt.build_single_match_params()
예제 #12
0
 def test_len(self):
     tt = axelrod.MatchGenerator(self.players, test_turns, test_game,
                                 test_repetitions)
     with self.assertRaises(NotImplementedError):
         len(tt)