Skip to content

Commit

Permalink
Merge pull request #13 from Hhamid1991/master
Browse files Browse the repository at this point in the history
Add subtraction styles to calculator class. Closes #11
  • Loading branch information
pylover committed Sep 10, 2020
2 parents 6cd8d34 + bb01dd7 commit 23cd808
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sunrise/actions.py
Expand Up @@ -16,6 +16,7 @@ def __init__(self, operator, a, b):
self.operator = {
'Add': '+',
'Sub': '-',
'subtract': '-',
}[operator] if operator not in self.operators else operator
self.numbers = [a, b]

Expand All @@ -30,7 +31,13 @@ def execute(self):
),
(
re.compile(
r'(?P<operator>Add|Sub)\s*(?P<a>\d+)\s*(with|by)\s*(?P<b>\d+)'
r'(?P<operator>Add)\s*(?P<a>\d+)\s*(with|by)\s*(?P<b>\d+)'
),
Calculator
),
(
re.compile(
r'(?P<operator>Sub|subtract)\s*(?P<b>\d+)\s*(from)\s*(?P<a>\d+)'
),
Calculator
),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_calculator.py
Expand Up @@ -4,5 +4,7 @@
def test_parser():
assert '6' == do('2 + 4')
assert '6' == do('Add 2 by 4')
assert '2' == do('subtract 2 from 4')
assert '2' == do('4 - 2')


0 comments on commit 23cd808

Please sign in to comment.