Skip to content

Commit

Permalink
Change action sort order to match character sort order and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcharper committed Feb 10, 2019
1 parent 8dc883a commit f51c4a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions axelrod/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def __init__(self, *args):
@total_ordering
class Action(Enum):
"""Core actions in the Prisoner's Dilemma.
There are only two possible actions, namely Cooperate or Defect,
which are called C and D for convenience.
"""

C = 1 # Cooperate
D = 0 # Defect
C = 0 # Cooperate
D = 1 # Defect

def __lt__(self, other):
return self.value < other.value
Expand All @@ -36,7 +36,7 @@ def __repr__(self):
return self.name

def __str__(self):
return repr(self)
return self.name

def flip(self):
"""Returns the opposite Action."""
Expand All @@ -48,7 +48,7 @@ def flip(self):
@classmethod
def from_char(cls, character):
"""Converts a single character into an Action.
Parameters
----------
character: a string of length one
Expand Down Expand Up @@ -91,7 +91,7 @@ def actions_to_str(actions: Iterable[Action]) -> str:
Example: (D, D, C) would be converted to 'DDC'
Paramteters
Parameters
-----------
actions: iterable of Action
Expand All @@ -100,4 +100,4 @@ def actions_to_str(actions: Iterable[Action]) -> str:
str
A string of 'C's and 'D's.
"""
return "".join(map(repr, actions))
return "".join(map(str, actions))
2 changes: 1 addition & 1 deletion axelrod/tests/unit/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestAction(unittest.TestCase):
def test_lt(self):
self.assertLess(D, C)
self.assertLess(C, D)

def test_repr(self):
self.assertEqual(repr(C), "C")
Expand Down

0 comments on commit f51c4a9

Please sign in to comment.