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
1855030e
Commit
1855030e
authored
Jan 05, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of kompiler.org:python/graph_drawing
parents
c4fd4af7
b99a1f72
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 @
1855030e
...
@@ -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 @
1855030e
...
@@ -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