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

Fix coverage of meta.py #910

Merged
merged 8 commits into from
Mar 16, 2017
Merged
2 changes: 1 addition & 1 deletion axelrod/strategies/hunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def strategy(self, opponent: Player) -> Action:

def is_alternator(history: List[Action]) -> bool:
for i in range(len(history) - 1):
if history[i] == history[i + 1]:
if history[i] == history[i + 1] or history[i] not in (C, D):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can get rid of this modification now?

return False
return True

Expand Down
10 changes: 9 additions & 1 deletion axelrod/tests/strategies/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,15 @@ def test_strategy(self):
self.responses_test([D], [C, C, C, C], [C, C, C, C])

# After long histories tit-for-tat should come into play.
self.responses_test([D], [C] * 101, [C] * 100 + [D])
# We generate a 'junk' history of length 101 in order to avoid the
# hunters triggering a defection as that overrides the tit-for-tat
# action.
# A genuine history (based on C or D only) which does not trigger any
# of the hunters is extremely difficult to identify. None of the
# strategies as at 14-Mar-2017 avoids doing so.
letters = 'ABEFGHIJKLMNOPQRSTUVWXYZ'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a (short) comment explaining the need for the junk history. Just want it as a pointer for when we eventually get to refactoring this test file.

junk_history = [random.choice(letters) for _ in range(101)]
self.responses_test([D], junk_history, junk_history[:100] + [D])

# All these others, however, should trigger a defection for the hunter.
self.responses_test([D], [C] * 4, [D] * 4)
Expand Down