-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_solver.py
28 lines (22 loc) · 865 Bytes
/
test_solver.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
import unittest
import solver
from solver import Node, evaluate
class TestSolver(unittest.TestCase):
def test_evaluate(self):
# Single sum: (15 + 5)
root = Node(solver.PLUS, Node(15), Node(5))
self.assertEqual(evaluate(root), 20)
# Single subtraction: (15 - 5)
root = Node(solver.MINUS, Node(15), Node(5))
self.assertEqual(evaluate(root), 10)
# Single multiplication: (15 * 5)
root = Node(solver.TIMES, Node(15), Node(5))
self.assertEqual(evaluate(root), 75)
# Single division: (15 / 5)
root = Node(solver.DIVIDE, Node(15), Node(5))
self.assertEqual(evaluate(root), 3)
# Chained operations: (3 + 2) * (4 + 5)
root = Node(solver.TIMES, Node(solver.PLUS, Node(3), Node(2)), Node(solver.PLUS, Node(4), Node(5)))
self.assertEqual(evaluate(root), 45)
if __name__ == "__main__":
unittest.main()