Ejemplo n.º 1
0
 def test_two_players_with_mutation(self):
     p1, p2 = axelrod.Cooperator(), axelrod.Defector()
     random.seed(5)
     mp = MoranProcess((p1, p2), mutation_rate=0.2)
     self.assertDictEqual(mp.mutation_targets,
                          {str(p1): [p2], str(p2): [p1]})
     # Test that mutation causes the population to alternate between
     # fixations
     counters = [
         Counter({'Cooperator': 2}),
         Counter({'Defector': 2}),
         Counter({'Cooperator': 2}),
         Counter({'Defector': 2})
     ]
     for counter in counters:
         for _ in itertools.takewhile(lambda x: x.population_distribution() != counter, mp):
             pass
         self.assertEqual(mp.population_distribution(), counter)
Ejemplo n.º 2
0
 def test_three_players_with_mutation(self):
     p1 = axelrod.Cooperator()
     p2 = axelrod.Random()
     p3 = axelrod.Defector()
     players = [p1, p2, p3]
     mp = MoranProcess(players, mutation_rate=0.2)
     self.assertDictEqual(mp.mutation_targets, {
         str(p1): [p3, p2], str(p2): [p1, p3], str(p3): [p1, p2]})
     # Test that mutation causes the population to alternate between
     # fixations
     counters = [
         Counter({'Cooperator': 3}),
         Counter({'Defector': 3}),
     ]
     for counter in counters:
         for _ in itertools.takewhile(lambda x: x.population_distribution() != counter, mp):
             pass
         self.assertEqual(mp.population_distribution(), counter)
Ejemplo n.º 3
0
 def test_three_players_with_mutation(self):
     p1 = axelrod.Cooperator()
     p2 = axelrod.Random()
     p3 = axelrod.Defector()
     players = [p1, p2, p3]
     mp = MoranProcess(players, mutation_rate=0.2)
     self.assertDictEqual(
         mp.mutation_targets,
         {str(p1): [p3, p2], str(p2): [p1, p3], str(p3): [p1, p2]},
     )
     # Test that mutation causes the population to alternate between
     # fixations
     counters = [Counter({"Cooperator": 3}), Counter({"Defector": 3})]
     for counter in counters:
         for _ in itertools.takewhile(
             lambda x: x.population_distribution() != counter, mp
         ):
             pass
         self.assertEqual(mp.population_distribution(), counter)
Ejemplo n.º 4
0
 def test_two_players_with_mutation(self):
     p1, p2 = axelrod.Cooperator(), axelrod.Defector()
     axelrod.seed(5)
     mp = MoranProcess((p1, p2), mutation_rate=0.2)
     self.assertDictEqual(mp.mutation_targets, {str(p1): [p2], str(p2): [p1]})
     # Test that mutation causes the population to alternate between
     # fixations
     counters = [
         Counter({"Cooperator": 2}),
         Counter({"Defector": 2}),
         Counter({"Cooperator": 2}),
         Counter({"Defector": 2}),
     ]
     for counter in counters:
         for _ in itertools.takewhile(
             lambda x: x.population_distribution() != counter, mp
         ):
             pass
         self.assertEqual(mp.population_distribution(), counter)