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
2f60cbbc
Commit
2f60cbbc
authored
Nov 25, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added quaternary and quinary test cases and code cleanup.
parent
1d05417a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
6 deletions
+58
-6
graph.py
graph.py
+6
-5
line.py
line.py
+4
-1
tests/test_graph.py
tests/test_graph.py
+48
-0
No files found.
graph.py
View file @
2f60cbbc
# vim: set fileencoding=utf-8 :
from
node
import
Node
,
Leaf
def
generate_graph
(
root
,
node_type
,
separator
=
' '
,
verbose
=
False
):
...
...
@@ -107,8 +106,6 @@ def generate_graph(root, node_type, separator=' ', verbose=False):
title_line
=
center_text
(
node
.
title
(),
line_width
,
middle
)
node_mid
=
node_len
/
2
pipe_sign
=
'│'
.
decode
(
'utf-8'
)
dash_sign
=
'─'
.
decode
(
'utf-8'
)
cross_sign
=
'┼'
.
decode
(
'utf-8'
)
...
...
@@ -158,11 +155,15 @@ def generate_graph(root, node_type, separator=' ', verbose=False):
edge_line
+=
dash_sign
if
i
<
middle_node
:
marker
=
(
left_sign
if
i
==
0
else
tsplit_sign
)
marker
=
(
left_sign
if
i
==
0
else
tsplit_
dn_
sign
)
edge_line
+=
center_text
(
marker
,
box_widths
[
i
],
middle
=
0
,
right
=
dash_sign
)
else
:
marker
=
(
right_sign
if
i
==
node_len
-
1
else
tsplit_sign
)
if
i
==
node_len
-
1
:
marker
=
right_sign
else
:
marker
=
tsplit_dn_sign
edge_line
+=
center_text
(
marker
,
box_widths
[
i
],
middle
=
0
,
left
=
dash_sign
)
...
...
line.py
View file @
2f60cbbc
...
...
@@ -92,9 +92,12 @@ def generate_line(root, node_type):
right
=
'('
+
right
+
')'
s
=
left
+
' '
+
s
+
' '
+
right
else
:
raise
ValueError
(
'arity = %d is currently not supported.'
\
%
arity
)
else
:
# Function
s
+=
'('
+
', '
.
join
(
map
(
traverse
,
node
.
nodes
))
+
')'
s
+=
'('
+
', '
.
join
(
map
(
traverse
,
node
))
+
')'
return
s
...
...
tests/test_graph.py
View file @
2f60cbbc
...
...
@@ -77,6 +77,54 @@ class TestGraph(unittest.TestCase):
LL
"""
)
def
test_ternary_multichar_middle_right
(
self
):
exp
=
Leaf
(
'x'
)
minus_99
=
Node
(
'-'
,
Leaf
(
'99'
))
minus_inf
=
Node
(
'-'
,
Leaf
(
'oo'
))
integral
=
Node
(
'int'
,
exp
,
minus_inf
,
minus_99
)
g
=
generate_graph
(
integral
,
Node
,
verbose
=
True
)
self
.
assertEqualGraphs
(
g
,
"""
int
╭─┼──╮
x - -
│ │
oo 99
"""
)
def
test_ternary_multichar_right
(
self
):
exp
=
Leaf
(
'x'
)
minus_99
=
Node
(
'-'
,
Leaf
(
'99'
))
ten
=
Leaf
(
'10'
)
integral
=
Node
(
'int'
,
exp
,
ten
,
minus_99
)
g
=
generate_graph
(
integral
,
Node
,
verbose
=
True
)
self
.
assertEqualGraphs
(
g
,
"""
int
╭─┼──╮
x 10 -
│
99
"""
)
def
test_quaternary
(
self
):
a
,
b
,
c
,
d
=
Leaf
(
0
),
Leaf
(
1
),
Leaf
(
2
),
Leaf
(
3
)
sum_node
=
Node
(
'sum'
,
a
,
b
,
c
,
d
)
g
=
generate_graph
(
sum_node
,
Node
,
verbose
=
True
)
self
.
assertEqualGraphs
(
g
,
"""
sum
╭─┬┴┬─╮
0 1 2 3
"""
)
def
test_quinary
(
self
):
a
,
b
,
c
,
d
,
e
=
Leaf
(
0
),
Leaf
(
1
),
Leaf
(
2
),
Leaf
(
3
),
Leaf
(
4
)
sum_node
=
Node
(
'sum'
,
a
,
b
,
c
,
d
,
e
)
g
=
generate_graph
(
sum_node
,
Node
,
verbose
=
True
)
self
.
assertEqualGraphs
(
g
,
"""
sum
╭─┬─┼─┬─╮
0 1 2 3 4
"""
)
def
strip
(
self
,
str
):
return
str
.
replace
(
'
\
n
'
,
'
\
n
'
)[
1
:
-
1
]
...
...
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