Pārlūkot izejas kodu

Merged new tests with older changes.

Taddeus Kroes 14 gadi atpakaļ
vecāks
revīzija
a350c6f1f2
2 mainītis faili ar 6 papildinājumiem un 6 dzēšanām
  1. 1 1
      line.py
  2. 5 5
      tests/test_line.py

+ 1 - 1
line.py

@@ -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

+ 5 - 5
tests/test_line.py

@@ -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):