From 198a899b5cc99931194028a9bcddd132298ded6b Mon Sep 17 00:00:00 2001 From: Chadys Date: Mon, 20 Mar 2017 23:07:29 +0100 Subject: [PATCH 1/3] Delete parameters from GoByMajority variants (#921) --- axelrod/strategies/gobymajority.py | 36 +++++++++---------- axelrod/tests/strategies/test_gobymajority.py | 13 ++++--- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/axelrod/strategies/gobymajority.py b/axelrod/strategies/gobymajority.py index 64f11eb3f..af5920fc2 100644 --- a/axelrod/strategies/gobymajority.py +++ b/axelrod/strategies/gobymajority.py @@ -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): @@ -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): @@ -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): @@ -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): @@ -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: float = float('inf')) -> None: + super().__init__(memory_depth=memory_depth, soft=False) class HardGoByMajority40(HardGoByMajority): @@ -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): @@ -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): @@ -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): @@ -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) diff --git a/axelrod/tests/strategies/test_gobymajority.py b/axelrod/tests/strategies/test_gobymajority.py index 6a24f8e28..8f4f3c169 100644 --- a/axelrod/tests/strategies/test_gobymajority.py +++ b/axelrod/tests/strategies/test_gobymajority.py @@ -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 + + 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): From ec4a15b910e7ca032d8322d5d0dd16f315d39464 Mon Sep 17 00:00:00 2001 From: Chadys Date: Mon, 20 Mar 2017 23:13:53 +0100 Subject: [PATCH 2/3] Corrected memory_depth type hint from float to int --- axelrod/strategies/gobymajority.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/gobymajority.py b/axelrod/strategies/gobymajority.py index af5920fc2..c58460450 100644 --- a/axelrod/strategies/gobymajority.py +++ b/axelrod/strategies/gobymajority.py @@ -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 ---------- @@ -138,7 +138,7 @@ class HardGoByMajority(GoByMajority): """ name = 'Hard Go By Majority' - def __init__(self, memory_depth: float = float('inf')) -> None: + def __init__(self, memory_depth: int = float('inf')) -> None: super().__init__(memory_depth=memory_depth, soft=False) From 743e6630bc40ae4b3e7e35575af37fecef0570c8 Mon Sep 17 00:00:00 2001 From: Chadys Date: Tue, 21 Mar 2017 23:02:10 +0100 Subject: [PATCH 3/3] reorganization of TestGoByMajority inheritance (#922) --- axelrod/tests/strategies/test_gobymajority.py | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/axelrod/tests/strategies/test_gobymajority.py b/axelrod/tests/strategies/test_gobymajority.py index 8f4f3c169..07c515b60 100644 --- a/axelrod/tests/strategies/test_gobymajority.py +++ b/axelrod/tests/strategies/test_gobymajority.py @@ -6,11 +6,12 @@ C, D = axelrod.Actions.C, axelrod.Actions.D -class TestGoByMajority(TestPlayer): +class TestHardGoByMajority(TestPlayer): - name = "Soft Go By Majority" - player = axelrod.GoByMajority - default_soft = True + name = "Hard Go By Majority" + player = axelrod.HardGoByMajority + default_soft = False + eq_play = D expected_classifier = { 'stochastic': False, @@ -23,22 +24,39 @@ class TestGoByMajority(TestPlayer): } def test_strategy(self): - # Starts by cooperating """ - self.first_play_test(C) + # Starts by defecting. + self.first_play_test(self.eq_play) # If opponent cooperates at least as often as they defect then the - # player cooperates. - self.responses_test([C], [C, D, D, D], [D, D, C, C]) + # player defects. + self.responses_test([self.eq_play], [C, D, D, D], [D, D, C, C]) + # If opponent defects strictly more often than they defect then the + # player defects. self.responses_test([D], [C, C, D, D, C], [D, D, C, C, D]) + # If opponent cooperates strictly more often than they defect then the + # player cooperates. + self.responses_test([C], [C, C, D, D, C], [D, C, C, C, D]) + + def test_default_soft(self): + player = self.player() + self.assertEqual(player.soft, self.default_soft) + + +class TestGoByMajority(TestHardGoByMajority): + + name = "Soft Go By Majority" + player = axelrod.GoByMajority + default_soft = True + eq_play = C + + def test_strategy(self): + # In case of equality (including first play), cooperates. + super().test_strategy() # Test tie break rule for soft=False player = self.player(soft=False) opponent = axelrod.Cooperator() self.assertEqual('D', player.strategy(opponent)) - def test_default_soft(self): - player = self.player() - self.assertEqual(player.soft, self.default_soft) - def test_soft(self): player = self.player(soft=True) self.assertTrue(player.soft) @@ -60,31 +78,6 @@ def test_repr(self): self.assertEqual(name, "Hard Go By Majority") -class TestHardGoByMajority(TestGoByMajority): - - name = "Hard Go By Majority" - player = axelrod.HardGoByMajority - default_soft = False - - def test_strategy(self): - # Starts by defecting. - self.first_play_test(D) - # If opponent cooperates strictly more often as they defect then the - # player cooperates. - 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]) - - def test_soft(self): - pass - - 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): prefix = "Hard"