Skip to content

Commit

Permalink
Add a constant fitness test.
Browse files Browse the repository at this point in the history
  • Loading branch information
drvinceknight committed Jun 11, 2017
1 parent 5c26eee commit b3960ca
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions axelrod/tests/unit/test_moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from hypothesis import given, example, settings

import axelrod
from axelrod import (Match, MoranProcess,
ApproximateMoranProcess, Pdf)
from axelrod import Match, MoranProcess, ApproximateMoranProcess, Pdf
from axelrod.moran import fitness_proportionate_selection
from axelrod.tests.property import strategy_lists

C, D = axelrod.Actions.C, axelrod.Actions.D


class TestMoranProcess(unittest.TestCase):

Expand Down Expand Up @@ -298,6 +299,21 @@ def test_reset(self):
for player, initial_player in zip(mp.players, mp.initial_players):
self.assertEqual(str(player), str(initial_player))

def test_constant_fitness_case(self):
# Scores between an Alternator and Defector will be: (1, 6)
axelrod.seed(0)
players = (axelrod.Alternator(), axelrod.Alternator(),
axelrod.Defector(), axelrod.Defector())
mp = MoranProcess(players, turns=2)
winners = []
for _ in range(100):
mp.play()
winners.append(mp.winning_strategy_name)
mp.reset()
winners = Counter(winners)
self.assertEqual(winners["Defector"], 88)


def test_cache(self):
p1, p2 = axelrod.Cooperator(), axelrod.Defector()
mp = MoranProcess((p1, p2))
Expand Down

0 comments on commit b3960ca

Please sign in to comment.