Skip to content

Commit 1151f2c

Browse files
committed
Revert "remove __repr__ override in GoByMajority (#802)"
This reverts commit 180e28c.
1 parent 66ac41f commit 1151f2c

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

axelrod/strategies/gobymajority.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ def __init__(self, memory_depth: int = float('inf'), soft: bool = True) -> None:
5151
self.memory = self.classifier['memory_depth']
5252
else:
5353
self.memory = 0
54+
self.name = (
55+
'Go By Majority' + (self.memory > 0) * (": %i" % self.memory))
56+
if self.soft:
57+
self.name = "Soft " + self.name
58+
else:
59+
self.name = "Hard " + self.name
60+
61+
def __repr__(self):
62+
return self.name
5463

5564
def strategy(self, opponent: Player) -> Action:
5665
"""This is affected by the history of the opponent.
@@ -77,7 +86,7 @@ class GoByMajority40(GoByMajority):
7786
"""
7887
GoByMajority player with a memory of 40.
7988
"""
80-
name = 'Soft Go By Majority 40'
89+
name = 'Go By Majority 40'
8190
classifier = copy.copy(GoByMajority.classifier)
8291
classifier['memory_depth'] = 40
8392

@@ -89,7 +98,7 @@ class GoByMajority20(GoByMajority):
8998
"""
9099
GoByMajority player with a memory of 20.
91100
"""
92-
name = 'Soft Go By Majority 20'
101+
name = 'Go By Majority 20'
93102
classifier = copy.copy(GoByMajority.classifier)
94103
classifier['memory_depth'] = 20
95104

@@ -101,7 +110,7 @@ class GoByMajority10(GoByMajority):
101110
"""
102111
GoByMajority player with a memory of 10.
103112
"""
104-
name = 'Soft Go By Majority 10'
113+
name = 'Go By Majority 10'
105114
classifier = copy.copy(GoByMajority.classifier)
106115
classifier['memory_depth'] = 10
107116

@@ -113,7 +122,7 @@ class GoByMajority5(GoByMajority):
113122
"""
114123
GoByMajority player with a memory of 5.
115124
"""
116-
name = 'Soft Go By Majority 5'
125+
name = 'Go By Majority 5'
117126
classifier = copy.copy(GoByMajority.classifier)
118127
classifier['memory_depth'] = 5
119128

axelrod/tests/strategies/test_gobymajority.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class TestHardGoByMajority(TestPlayer):
1010

11-
name = "Hard Go By Majority: inf"
11+
name = "Hard Go By Majority"
1212
player = axelrod.HardGoByMajority
1313
default_soft = False
1414
eq_play = D
@@ -43,7 +43,7 @@ def test_default_soft(self):
4343

4444
class TestGoByMajority(TestHardGoByMajority):
4545

46-
name = "Go By Majority: inf, True"
46+
name = "Soft Go By Majority"
4747
player = axelrod.GoByMajority
4848
default_soft = True
4949
eq_play = C
@@ -63,6 +63,20 @@ def test_soft(self):
6363
player = self.player(soft=False)
6464
self.assertFalse(player.soft)
6565

66+
def test_name(self):
67+
player = self.player(soft=True)
68+
self.assertEqual(player.name, "Soft Go By Majority")
69+
player = self.player(soft=False)
70+
self.assertEqual(player.name, "Hard Go By Majority")
71+
72+
def test_repr(self):
73+
player = self.player(soft=True)
74+
name = str(player)
75+
self.assertEqual(name, "Soft Go By Majority")
76+
player = self.player(soft=False)
77+
name = str(player)
78+
self.assertEqual(name, "Hard Go By Majority")
79+
6680

6781
def factory_TestGoByRecentMajority(L, soft=True):
6882

@@ -74,7 +88,7 @@ def factory_TestGoByRecentMajority(L, soft=True):
7488

7589
class TestGoByRecentMajority(TestPlayer):
7690

77-
name = "{} Go By Majority {}".format(prefix, L)
91+
name = "{} Go By Majority: {}".format(prefix, L)
7892
player = getattr(axelrod, "{}GoByMajority{}".format(prefix2, L))
7993

8094
expected_classifier = {

0 commit comments

Comments
 (0)