test_line.py 914 B

123456789101112131415161718192021222324252627282930313233343536
  1. import unittest
  2. from node import Node, Leaf
  3. from line import generate_line
  4. class TestLine(unittest.TestCase):
  5. def setUp(self):
  6. pass
  7. def tearDown(self):
  8. pass
  9. def test_simple(self):
  10. l0, l1 = Leaf(1), Leaf(2)
  11. plus = Node('+', l0, l1)
  12. assert generate_line(plus, Node) == '1 + 2'
  13. def test_parentheses(self):
  14. l0, l1 = Leaf(1), Leaf(2)
  15. plus = Node('+', l0, l1)
  16. times = Node('*', plus, plus)
  17. assert generate_line(times, Node) == '(1 + 2) * (1 + 2)'
  18. def test_function(self):
  19. exp = Leaf('x')
  20. inf = Leaf('oo')
  21. minus_inf = Node('-', inf)
  22. integral = Node('int', exp, minus_inf, inf)
  23. assert generate_line(integral, Node) == 'int(x, -oo, oo)'
  24. def test_mod(self):
  25. l0, l1 = Leaf(1), Leaf(2)
  26. mod = Node('mod', l1, l0)
  27. assert generate_line(mod, Node) == '2 mod 1'