Skip to content

Commit

Permalink
Multiplication edited according to comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kianooshkarimi committed Sep 13, 2020
1 parent 123c7d3 commit 95e1edd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions sunrise/actions.py
Expand Up @@ -15,7 +15,7 @@ class Calculator(Action):
def __init__(self, operator, a, b):
self.operator = {
'Add': '+',
'subtract': '-',
'Subtract': '-',
'Divide': '//',
'/': '//',
'Multiplication of': '*',
Expand All @@ -31,32 +31,32 @@ def execute(self):

patterns = [
(
re.compile(r'(?P<a>\d+)\s*(?P<operator>[-+/*])\s*(?P<b>\d+)'),
re.compile(r'(?P<a>\d+)\s*(?P<operator>[-+/*x])\s*(?P<b>\d+)'),
Calculator
),
(
re.compile(
r'(?P<operator>Add)\s*(?P<a>\d+)\s*(with|by)\s*(?P<b>\d+)'
),
),
Calculator
),
(
re.compile(
r'(?P<operator>subtract)\s*(?P<b>\d+)\s*(from)\s*(?P<a>\d+)'
),
r'(?P<operator>Subtract)\s*(?P<b>\d+)\s*(from)\s*(?P<a>\d+)'
),
Calculator
),
(
re.compile(
r'(?P<operator>Multiply)\s*(?P<a>\d+)\s*(with|by)\s*(?P<b>\d+)'
),
),
Calculator
),
(
re.compile(
r'(?P<operator>(Multiplication(\s)of))\s*(?P<a>\d+)\s*'
r'(and)\s*(?P<b>\d+)'
),
),
Calculator
),
(
Expand All @@ -66,13 +66,13 @@ def execute(self):
(
re.compile(
r'(?P<operator>Divide)\s*(?P<b>\d+)\s*(into)\s*(?P<a>\d+)'
),
),
Calculator
),
(
re.compile(
r'(?P<operator>Divide)\s*(?P<a>\d+)\s*(by)\s*(?P<b>\d+)'
),
),
Calculator
),
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_calculator.py
Expand Up @@ -4,7 +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('Subtract 2 from 4')
assert '2' == do('4 - 2')
assert '12' == do('3 * 4')
assert '10' == do('Multiply 2 by 5')
Expand Down

0 comments on commit 95e1edd

Please sign in to comment.