| 123456789101112131415161718192021222324252627282930313233343536 |
- import unittest
- from node import Node, Leaf
- from line import generate_line
- class TestLine(unittest.TestCase):
- def setUp(self):
- pass
- def tearDown(self):
- pass
- def test_simple(self):
- l0, l1 = Leaf(1), Leaf(2)
- plus = Node('+', l0, l1)
- assert generate_line(plus) == '1 + 2'
- def test_parentheses(self):
- l0, l1 = Leaf(1), Leaf(2)
- plus = Node('+', l0, l1)
- times = Node('*', plus, plus)
- assert generate_line(times) == '(1 + 2) * (1 + 2)'
- def test_function(self):
- exp = Leaf('x')
- inf = Leaf('oo')
- minus_inf = Node('-', inf)
- integral = Node('int', exp, minus_inf, inf)
- assert generate_line(integral) == 'int(x, -oo, oo)'
- def test_mod(self):
- l0, l1 = Leaf(1), Leaf(2)
- mod = Node('mod', l1, l0)
- assert generate_line(mod) == '2 mod 1'
|