Commit 7f65d03d authored by Taddeus Kroes's avatar Taddeus Kroes

Revert "Fixed multiplication sign omission when left node ends with a digit."

This reverts commit 821c5062.
parent 821c5062
......@@ -39,6 +39,10 @@ def is_id(node):
return node.is_leaf and not node.title().isdigit()
def is_int(node):
return node.is_leaf and node.title().isdigit()
def is_power(node):
return not node.is_leaf and node.title() == '^'
......@@ -162,11 +166,11 @@ def generate_line(root):
# (a) * b -> (a)b
# (a) * (b) -> (a)(b)
# 2 * a -> 2a
left_end = e[0][-1]
right_begin = e[1][0]
left_paren = e[0][-1] == ')'
right_paren = e[1][0] == '('
left_suited = left_end == ')' or left_end.isdigit() or is_id(left)
right_suited = right_begin == '('
left_suited = left_paren or is_id(left) or is_int(left)
right_suited = right_paren
if not right_suited and not right.negated:
right_suited = is_id(right) or is_power(right)
......
......@@ -3,7 +3,7 @@ import doctest
import line
from node import Node as N, Leaf as L
from line import generate_line, is_id, is_power
from line import generate_line, is_id, is_int, is_power
class TestLine(unittest.TestCase):
......@@ -152,9 +152,6 @@ class TestLine(unittest.TestCase):
mul = N('*', l2, N('^', a, l2))
self.assertEquals(generate_line(mul), '2a ^ 2')
mul = N('*', N('^', a, l2), N('+', a, b))
self.assertEquals(generate_line(mul), 'a ^ 2(a + b)')
def test_plus_to_minus(self):
plus = N('+', L(1), -L(2))
self.assertEquals(generate_line(plus), '1 - 2')
......@@ -175,6 +172,11 @@ class TestLine(unittest.TestCase):
self.assertFalse(is_id(neg))
self.assertFalse(is_id(plus))
self.assertTrue(is_int(l1))
self.assertTrue(is_int(neg))
self.assertFalse(is_int(neg_a))
self.assertFalse(is_int(plus))
self.assertTrue(is_power(power))
self.assertFalse(is_power(l1))
self.assertFalse(is_power(plus))
......
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