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

921 #922

Merged
merged 4 commits into from
Mar 22, 2017
Merged

921 #922

Show file tree
Hide file tree
Changes from 3 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
38 changes: 19 additions & 19 deletions axelrod/strategies/gobymajority.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GoByMajority(Player):
'memory_depth': float('inf')
} # type: Dict[str, Any]

def __init__(self, memory_depth: float = float('inf'), soft: bool = True) -> None:
def __init__(self, memory_depth: int = float('inf'), soft: bool = True) -> None:
"""
Parameters
----------
Expand Down Expand Up @@ -88,8 +88,8 @@ class GoByMajority40(GoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 40

def __init__(self, memory_depth: float = 40, soft: bool = True) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=40)


class GoByMajority20(GoByMajority):
Expand All @@ -100,8 +100,8 @@ class GoByMajority20(GoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 20

def __init__(self, memory_depth: float = 20, soft: bool = True) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=20)


class GoByMajority10(GoByMajority):
Expand All @@ -112,8 +112,8 @@ class GoByMajority10(GoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 10

def __init__(self, memory_depth: float = 10, soft: bool = True) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=10)


class GoByMajority5(GoByMajority):
Expand All @@ -124,8 +124,8 @@ class GoByMajority5(GoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 5

def __init__(self, memory_depth: float = 5, soft: bool = True) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=5)


class HardGoByMajority(GoByMajority):
Expand All @@ -138,8 +138,8 @@ class HardGoByMajority(GoByMajority):
"""
name = 'Hard Go By Majority'

def __init__(self, memory_depth: float = float('inf'), soft: bool = False) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self, memory_depth: int = float('inf')) -> None:
super().__init__(memory_depth=memory_depth, soft=False)


class HardGoByMajority40(HardGoByMajority):
Expand All @@ -150,8 +150,8 @@ class HardGoByMajority40(HardGoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 40

def __init__(self, memory_depth: float = 40, soft: bool = False) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=40)


class HardGoByMajority20(HardGoByMajority):
Expand All @@ -162,8 +162,8 @@ class HardGoByMajority20(HardGoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 20

def __init__(self, memory_depth: float = 20, soft: bool = False) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=20)


class HardGoByMajority10(HardGoByMajority):
Expand All @@ -174,8 +174,8 @@ class HardGoByMajority10(HardGoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 10

def __init__(self, memory_depth: float = 10, soft: bool = False) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=10)


class HardGoByMajority5(HardGoByMajority):
Expand All @@ -186,5 +186,5 @@ class HardGoByMajority5(HardGoByMajority):
classifier = copy.copy(GoByMajority.classifier)
classifier['memory_depth'] = 5

def __init__(self, memory_depth: float = 5, soft: bool = False) -> None:
super().__init__(memory_depth=memory_depth, soft=soft)
def __init__(self) -> None:
super().__init__(memory_depth=5)
13 changes: 9 additions & 4 deletions axelrod/tests/strategies/test_gobymajority.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ def test_strategy(self):
self.responses_test([D], [C, D, D, D], [D, D, C, C])
self.responses_test([D], [C, C, D, D, C], [D, D, C, C, D])

# Test tie break rule for soft=True
player = self.player(soft=True)
opponent = axelrod.Cooperator()
self.assertEqual('C', player.strategy(opponent))
def test_soft(self):
pass
Copy link
Member

Choose a reason for hiding this comment

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

Why is this here? Does it need a test to be added?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's just to override the test from TestGoByMajority, that checks the soft argument works correctly. Since HardGoByMajority doesn't have a soft argument anymore, that test isn't needed and was causing an exception if I didn't override it to remove it. I thought about not making TestHardGoByMajority inherite from TestGoByMajority at all, but there are still enough common points between the two for it to be meaningful.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could have used delattr instead.

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 comment to explain the need for line 78? (I had to ask this again to keep github's review process happy).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will do tonight !


def test_name(self):
self.assertEqual(self.player().name, "Hard Go By Majority")

def test_repr(self):
name = str(self.player())
self.assertEqual(name, "Hard Go By Majority")


def factory_TestGoByRecentMajority(L, soft=True):
Expand Down