Skip to content

Commit

Permalink
Review - add parser test
Browse files Browse the repository at this point in the history
  • Loading branch information
quozl committed Feb 21, 2020
1 parent 6658664 commit 4dca761
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions parse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python3
from gi.repository import Gtk
import locale
import ast
Expand Down Expand Up @@ -67,3 +68,28 @@ def invalid_value_alert(activity):
alert.connect('response', lambda a, r: activity.remove_alert(a))
activity.add_alert(alert)
alert.show()


if __name__ == "__main__":
tests = [
['0', 0.0],
['0.55', 0.55],
['1', 1.0],
['2', 2.0],
['-2', -2.0],
['2+2', 4.0],
['4-2', 2.0],
['4*2', 8.0],
['4/2', 2.0],
# ['4*-4', -4.0], # TypeError:
['4/2-1', 1.0],
['1.5', 1.5],
['-1.7', -1.7],
]
for test in tests:
text, expected = test
observed = evaluate(text)
if observed != expected:
print('fail; %r -> %r instead of %r' % (text, observed, expected))
else:
print('pass; %r -> %r' % (text, observed))

0 comments on commit 4dca761

Please sign in to comment.