Commit a350c6f1 authored by Taddeus Kroes's avatar Taddeus Kroes

Merged new tests with older changes.

parent 567e8f5c
......@@ -98,7 +98,7 @@ def generate_line(root):
child_pred = pred(child)
if child_pred < node_pred or \
(child_pred == node_pred and s != child.title()):
(child_pred == node_pred and op != child.title()):
exp = '(' + exp + ')'
# a * b -> ab
......
......@@ -24,14 +24,14 @@ class TestLine(unittest.TestCase):
self.assertEquals(generate_line(times), '(1 + 2) * (1 + 2)')
def test_parentheses_equal_precedence(self):
l0, l1, l2 = Leaf(1), Leaf(2), Leaf(3)
plus = Node('+', l1, l2)
minus = Node('-', l0, plus)
l0, l1, l2 = L(1), L(2), L(3)
plus = N('+', l1, l2)
minus = N('-', l0, plus)
self.assertEquals(generate_line(minus), '1 - (2 + 3)')
def test_parentheses_nary(self):
l0, l1, l2 = Leaf(1), Leaf(2), Leaf(3)
plus = Node('+', Node('+', l0, l1), l2)
l0, l1, l2 = L(1), L(2), L(3)
plus = N('+', N('+', l0, l1), l2)
self.assertEquals(generate_line(plus), '1 + 2 + 3')
def test_function(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment