Skip to content

Commit

Permalink
Add divider. Closes #12 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenajorloo committed Sep 12, 2020
1 parent 23cd808 commit ad79a5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 15 additions & 1 deletion sunrise/actions.py
Expand Up @@ -10,13 +10,15 @@ def execute(self):


class Calculator(Action):
operators = ['+', '-', '*', '/']
operators = ['+', '-', '*']

def __init__(self, operator, a, b):
self.operator = {
'Add': '+',
'Sub': '-',
'subtract': '-',
'Div': '//',
'/': '//',
}[operator] if operator not in self.operators else operator
self.numbers = [a, b]

Expand All @@ -41,6 +43,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
Expand Up @@ -6,5 +6,6 @@ def test_parser():
assert '6' == do('Add 2 by 4')
assert '2' == do('subtract 2 from 4')
assert '2' == do('4 - 2')


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

0 comments on commit ad79a5a

Please sign in to comment.