Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
graph_drawing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
graph_drawing
Commits
b99a1f72
Commit
b99a1f72
authored
Dec 13, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed parentheses issue in expression that use both plus and minus.
parent
003a9e25
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
line.py
line.py
+4
-1
tests/test_line.py
tests/test_line.py
+11
-0
No files found.
line.py
View file @
b99a1f72
...
@@ -93,7 +93,10 @@ def generate_line(root):
...
@@ -93,7 +93,10 @@ def generate_line(root):
# Check if there is an precedence conflict.
# Check if there is an precedence conflict.
# If so, add parentheses
# If so, add parentheses
if
pred
(
child
)
<
node_pred
:
child_pred
=
pred
(
child
)
if
child_pred
<
node_pred
or
\
(
child_pred
==
node_pred
and
s
!=
child
.
title
()):
exp
=
'('
+
exp
+
')'
exp
=
'('
+
exp
+
')'
e
.
append
(
exp
)
e
.
append
(
exp
)
...
...
tests/test_line.py
View file @
b99a1f72
...
@@ -23,6 +23,17 @@ class TestLine(unittest.TestCase):
...
@@ -23,6 +23,17 @@ class TestLine(unittest.TestCase):
times
=
Node
(
'*'
,
plus
,
plus
)
times
=
Node
(
'*'
,
plus
,
plus
)
self
.
assertEquals
(
generate_line
(
times
),
'(1 + 2) * (1 + 2)'
)
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
)
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
)
self
.
assertEquals
(
generate_line
(
plus
),
'1 + 2 + 3'
)
def
test_function
(
self
):
def
test_function
(
self
):
exp
=
Leaf
(
'x'
)
exp
=
Leaf
(
'x'
)
inf
=
Leaf
(
'oo'
)
inf
=
Leaf
(
'oo'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment