Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor tests for memory one strategies.
Mainly using seeded tests that hit all states (added some tests that
were missing as well).

Addresses #884
  • Loading branch information
drvinceknight committed May 31, 2017
commit f8699709e815e92ceb965ece8b3d97d68b33a59c
166 changes: 130 additions & 36 deletions axelrod/tests/strategies/test_memoryone.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,18 @@ def test_four_vector(self):

def test_strategy(self):
self.first_play_test(C)
self.responses_test([C], [C], [C])
self.responses_test([D], [C], [D])
self.responses_test([C], [D], [C])
self.responses_test([C], [D], [D], seed=1)
self.responses_test([D], [D], [D], seed=2)

actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions)

actions = [(C, D), (D, D), (D, D), (D, D), (C, D)]
self.versus_test(opponent=axelrod.Defector(),
expected_actions=actions, seed=0)

actions = [(C, D), (D, D), (C, D), (D, D), (D, D)]
self.versus_test(opponent=axelrod.Defector(),
expected_actions=actions, seed=1)


class TestStochasticCooperator(TestPlayer):
Expand All @@ -153,14 +160,22 @@ def test_four_vector(self):

def test_strategy(self):
self.first_play_test(C)
# With probability 0.065 will defect
self.responses_test([D, C, C, C], [C], [C], seed=15)
# With probability 0.266 will cooperate
self.responses_test([C], [C], [D], seed=1)
# With probability 0.42 will cooperate
self.responses_test([C], [D], [C], seed=3)
# With probability 0.229 will cooperate
self.responses_test([C], [D], [D], seed=13)

actions = [(C, C), (D, D), (C, C), (C, D), (C, C), (D, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=15)

actions = [(C, C), (C, D), (D, C), (D, D), (C, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=1)

actions = [(C, C), (C, D), (D, C), (D, D), (D, C), (D, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=3)

actions = [(C, C), (C, D), (D, C), (D, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=13)


class TestStochasticWSLS(TestPlayer):
Expand All @@ -179,14 +194,22 @@ class TestStochasticWSLS(TestPlayer):

def test_strategy(self):
self.first_play_test(C)
# With probability 0.05 will defect
self.responses_test([D], [C], [C], seed=2)
# With probability 0.05 will cooperate
self.responses_test([C], [C], [D], seed=31)
# With probability 0.05 will cooperate
self.responses_test([C], [D], [C], seed=31)
# With probability 0.05 will defect
self.responses_test([D], [D], [D], seed=2)

actions = [(C, C), (D, D), (C, C), (C, D), (D, C), (D, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, C), (C, D), (D, C), (D, D), (C, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=31)

actions = [(C, D), (D, C), (D, D), (C, C), (C, D), (D, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=2)

actions = [(C, D), (C, C), (C, D), (D, C), (D, D), (C, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=31)

def test_four_vector(self):
player = self.player()
Expand Down Expand Up @@ -240,10 +263,22 @@ def test_four_vector(self):

def test_strategy(self):
self.first_play_test(C)
self.responses_test([D, D, C, C], [C], [C], seed=2)
self.responses_test([D, D, C, C], [C], [D], seed=2)
self.responses_test([D, D, C, C], [D], [C], seed=2)
self.responses_test([D, D, C, C], [C], [D], seed=2)

actions = [(C, C), (D, D), (D, C), (D, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, C), (C, D), (C, C), (C, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=31)

actions = [(C, D), (D, C), (D, D), (D, C), (C, D), (C, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=2)

actions = [(C, D), (C, C), (C, D), (C, C), (C, D), (C, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=31)


class TestZDExtort2v2(TestPlayer):
Expand All @@ -268,6 +303,14 @@ def test_four_vector(self):
def test_strategy(self):
self.first_play_test(C)

actions = [(C, C), (D, D), (D, C), (D, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, D), (D, C), (D, D), (D, C), (D, D), (D, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=5)


class TestZDExtort4(TestPlayer):

Expand All @@ -291,6 +334,14 @@ def test_four_vector(self):
def test_strategy(self):
self.first_play_test(C)

actions = [(C, C), (D, D), (D, C), (D, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, D), (D, C), (D, D), (D, C), (D, D), (D, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=5)


class TestZDGen2(TestPlayer):

Expand All @@ -314,6 +365,22 @@ def test_four_vector(self):
def test_strategy(self):
self.first_play_test(C)

actions = [(C, C), (C, D), (D, C), (D, D), (C, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, C), (C, D), (C, C), (C, D), (C, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=31)

actions = [(C, D), (D, C), (D, D), (C, C), (C, D), (C, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=2)

actions = [(C, D), (C, C), (C, D), (C, C), (C, D), (C, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=31)


class TestZDGTFT2(TestPlayer):

Expand All @@ -335,10 +402,22 @@ def test_four_vector(self):

def test_strategy(self):
self.first_play_test(C)
self.responses_test([C, C, C, C], [C], [C], seed=2)
self.responses_test([D], [C], [D], seed=2)
self.responses_test([C, C, C, C], [D], [C], seed=2)
self.responses_test([D], [D], [D], seed=2)

actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, C), (C, D), (C, C), (C, D), (C, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=31)

actions = [(C, D), (D, C), (C, D), (D, C), (C, D), (C, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=2)

actions = [(C, D), (C, C), (C, D), (C, C), (C, D), (D, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=31)


class TestZDSet2(TestPlayer):
Expand All @@ -363,6 +442,14 @@ def test_four_vector(self):
def test_strategy(self):
self.first_play_test(C)

actions = [(C, C), (D, D), (D, C), (C, D), (C, C), (D, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, D), (D, C), (D, D), (D, C), (D, D), (D, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=5)


class TestSoftJoss(TestPlayer):

Expand All @@ -383,8 +470,13 @@ def test_four_vector(self):
test_four_vector(self, expected_dictionary)

def test_strategy(self):
self.responses_test([C], [C], [C], seed=2)
self.responses_test([D], [C], [D], seed=5)
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=2)

actions = [(C, D), (D, C), (C, D), (D, C), (C, D), (D, C)]
self.versus_test(opponent=axelrod.CyclerDC(),
expected_actions=actions, seed=5)


class TestALLCorALLD(TestPlayer):
Expand All @@ -402,8 +494,10 @@ class TestALLCorALLD(TestPlayer):
}

def test_strategy(self):
self.responses_test([D] * 10, seed=2)
self.responses_test([C] * 10, seed=3)
self.responses_test([C] * 10, seed=4)
self.responses_test([D] * 10, seed=5)
self.responses_test([D] * 10, seed=6)

actions = [(D, C)] * 10
self.versus_test(opponent=axelrod.Cooperator(),
expected_actions=actions, seed=0)
actions = [(C, C)] * 10
self.versus_test(opponent=axelrod.Cooperator(),
expected_actions=actions, seed=1)