Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve our test for reset and fix some test bugs. #1098

Merged
merged 7 commits into from
Jul 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion axelrod/tests/strategies/test_darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_against_geller_and_mindreader(self):

self.versus_test(axelrod.MindReader(), expected_actions=[(C, D)] * 2, attrs={'genome': [D, C]})

def test_reset_only_resets_first_move_of_genome(self):
def test_reset_history_and_attributes(self):
# Overwrite this method because Darwin does not reset
self.versus_test(axelrod.Defector(), expected_actions=[(C, D)] + [(D, D)] * 4)

p1 = self.player()
Expand Down
6 changes: 5 additions & 1 deletion axelrod/tests/strategies/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,13 @@ class TestMetaMajorityLongMemory(TestMetaPlayer):
}

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

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


class TestMetaWinnerMemoryOne(TestMetaPlayer):
Expand Down
17 changes: 9 additions & 8 deletions axelrod/tests/strategies/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,17 @@ def test_match_attributes(self):

def test_reset_history_and_attributes(self):
"""Make sure resetting works correctly."""
player = self.player()
clone = player.clone()
opponent = axelrod.Random()
for opponent in [axelrod.Defector(), axelrod.Random(),
axelrod.Alternator(), axelrod.Cooperator()]:

for seed in range(10):
axelrod.seed(seed)
player.play(opponent)
player = self.player()
clone = player.clone()
for seed in range(10):
axelrod.seed(seed)
player.play(opponent)

player.reset()
self.assertEqual(player, clone)
player.reset()
self.assertEqual(player, clone)

def test_reset_clone(self):
"""Make sure history resetting with cloning works correctly, regardless
Expand Down
31 changes: 17 additions & 14 deletions axelrod/tests/strategies/test_selfsteem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ class TestSelfSteem(TestPlayer):
def test_strategy(self):

# Check for f > 0.95, defect
actions = [(C, C), (C, C), (D, C), (D, C)]
self.versus_test(axelrod.Cooperator(), expected_actions=actions)

actions = [(C, C), (C, C), (D, C),
(D, C), (C, C), (D, C)] + [(C, C)] * 6 + [(D, C)]
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
(D, C), (C, C), (D, C)] + [(C, C)] * 4 + [(D, C)]
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
seed=1)

# Check for f < -0.95, cooperate
actions = [(D, C), (C, C), (D, C),(D, C),
actions = [(D, C), (C, C), (D, C), (D, C),
(C, C), (D, C), (C, C), (C, C)]
self.versus_test(opponent=axelrod.MockPlayer(actions=[C]), expected_actions=actions)
self.versus_test(opponent=axelrod.Cooperator(),
expected_actions=actions, seed=0)

actions = [(C, D)] + [(D, D)] * 6 + [(C, D),
(C, D)] + [(D, D)] * 6 + [(C, D)]
self.versus_test(opponent=axelrod.MockPlayer(actions=[D]), expected_actions=actions)
actions = [(D, D)] + [(D, D)] * 5 + [(D, D), (C, D), (C, D)]
self.versus_test(opponent=axelrod.Defector(),
expected_actions=actions, seed=0)

# Check for -0.3 < f < 0.3, random
actions = [(D, C), (C, C), (D, C), (D, C),
(C, C), (D, C)] + [(C, C)] * 6 + [(D, C),(D, C)] + [(C, C)] * 7
self.versus_test(opponent=axelrod.MockPlayer(actions=[C]), expected_actions=actions, seed=6)
self.versus_test(opponent=axelrod.Cooperator(),
expected_actions=actions, seed=6)

actions = [(D, D)] * 7 + [(C, D), (C, D)] + [(D, D)] * 8 + [(C, D),
(C, D), (D, D), (D, D), (D, D)]
self.versus_test(opponent=axelrod.MockPlayer(actions=[D]), expected_actions=actions, seed=5)
self.versus_test(opponent=axelrod.Defector(),
expected_actions=actions, seed=5)

# Check for 0.95 > abs(f) > 0.3, follows TitForTat
actions = [(D, D)] * 5 + [(C, D), (D, D), (C, D),
(C, D), (D, D), (C, D)] + [(D, D)] * 5
self.versus_test(opponent=axelrod.MockPlayer(actions=[D]), expected_actions=actions)
self.versus_test(opponent=axelrod.Defector(),
expected_actions=actions)

actions = [(D, C), (C, C), (D, C), (D, C),
(C, C), (D, C), (C, C), (C, C), (C, C), (C, C)]
self.versus_test(opponent=axelrod.MockPlayer(actions=[C]), expected_actions=actions)
self.versus_test(opponent=axelrod.Cooperator(),
expected_actions=actions)
4 changes: 0 additions & 4 deletions axelrod/tests/strategies/test_stalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class TestStalker(TestPlayer):
}

def test_strategy(self):
actions = [(C, D)] * 2 + [(C, C), (D, C), (C, C), (C, C), (D, D)]
self.versus_test(opponent=axl.MockPlayer([D] * 2 + [C] * 4),
expected_actions=actions)

actions = [(C, C)] * 3 + [(D, C)]
self.versus_test(opponent=axl.Cooperator(), expected_actions=actions)

Expand Down