-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_exp_eval.py
50 lines (37 loc) · 1.38 KB
/
test_exp_eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest
from exp_eval import exp_eval
import operator
class TestExpressionEvaluator(unittest.TestCase):
def setUp(self):
self.ops = { "+": operator.add, "-": operator.sub }
def tearDown(self):
self.ops = None
def test_plus_one_two(self):
s = "+ 1 2"
self.assertEqual(exp_eval(self.ops,s), 3)
def test_minus_one_two(self):
s = "- 1 2"
self.assertEqual(exp_eval(self.ops,s), -1)
def test_plus_neg_one_neg_two(self):
s = "+ -1 -2"
self.assertEqual(exp_eval(self.ops,s), -3)
def test_plus_one_plus_two_three(self):
s = "+ 1 + 2 3"
self.assertEqual(exp_eval(self.ops,s), 6)
def test_plus_one_plus_two_minus_two_three(self):
s = "+ 1 + 2 - 2 3"
self.assertEqual(exp_eval(self.ops,s), 2)
def test_plus_plus_two_three_two(self):
s = "+ + 2 3 2"
self.assertEqual(exp_eval(self.ops,s), 7)
def test_plus_plus_plus_two_three_two(self):
s = "+ + + 2 3 2 2"
self.assertEqual(exp_eval(self.ops,s), 9)
def test_plus_plus_plus_two_three_two(self):
s = "+ + + 2 3 2 - 2 3"
self.assertEqual(exp_eval(self.ops,s), 6)
def test_plus_one_plus_two_minus_three_plus_four_five(self):
s = "+ 1 + 2 - 3 + 4 5"
self.assertEqual(exp_eval(self.ops,s), -3)
if __name__ == '__main__':
unittest.main()