Skip to content

Commit

Permalink
Merge d651f54 into 6cd8d34
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenajorloo committed Sep 10, 2020
2 parents 6cd8d34 + d651f54 commit 4d4e20d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions sunrise/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, operator, a, b):
self.operator = {
'Add': '+',
'Sub': '-',
'Div': '/',
}[operator] if operator not in self.operators else operator
self.numbers = [a, b]

Expand All @@ -34,6 +35,18 @@ def execute(self):
),
Calculator
),
(
re.compile(
r'(?P<operator>Div)\s*(?P<b>\d+)\s*(into)\s*(?P<a>\d+)'
),
Calculator
),
(
re.compile(
r'(?P<operator>Div)\s*(?P<a>\d+)\s*(by)\s*(?P<b>\d+)'
),
Calculator
),
]


Expand Down
5 changes: 3 additions & 2 deletions tests/test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
def test_parser():
assert '6' == do('2 + 4')
assert '6' == do('Add 2 by 4')


assert '2.0' == do('4 / 2')
assert '2.0' == do('Div 4 by 2')
assert '2.0' == do('Div 2 into 4')

0 comments on commit 4d4e20d

Please sign in to comment.