-
Notifications
You must be signed in to change notification settings - Fork 1
/
testExpr.py
43 lines (37 loc) · 1.19 KB
/
testExpr.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
# testExpr.py -- Unit tests for Expr
from expr import *
import unittest
class TestExpr(unittest.TestCase):
def test_str(self):
e1 = Equation(
Plus(
Number(2),
Times(Number(3), Number(4))),
Times(
Plus(
Number(1),
Number(5)),
Number(6)))
self.assertEqual(str(e1), '2 + 3 * 4 = (1 + 5) * 6')
e2 = Equation(
Plus(
Times(Number(3), Number(4)),
Number(2)),
Number(24))
self.assertEqual(str(e2), '3 * 4 + 2 = 24')
e3 = Equation(
Minus(
Times(
Number(3),
Number(4)),
Plus(
Number(1),
Number(5))),
Minus(
Plus(
Number(11),
Number(8)),
Times(
Number(2),
Number(7))))
self.assertEqual(str(e3), '3 * 4 - (1 + 5) = (11 + 8) - 2 * 7')