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
bf0b2e54
Commit
bf0b2e54
authored
Jan 08, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved test cases for multiplication sign omission in line generator.
parent
591a3e65
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
line.py
line.py
+10
-2
tests/test_line.py
tests/test_line.py
+7
-1
No files found.
line.py
View file @
bf0b2e54
...
@@ -115,9 +115,17 @@ def generate_line(root):
...
@@ -115,9 +115,17 @@ def generate_line(root):
# a * b -> ab
# a * b -> ab
# a * 2 -> a * 2
# a * 2 -> a * 2
# a * (b) -> a(b)
# a * (b) -> a(b)
# (a) * b -> (a)b
# (a) * (b) -> (a)(b)
# 2 * a -> 2a
# 2 * a -> 2a
if
(
is_id
(
left
)
and
(
is_id
(
right
)
or
e
[
1
][
0
]
==
'('
))
\
left_id
=
is_id
(
left
)
or
(
is_int
(
left
)
and
is_id
(
right
)):
right_id
=
is_id
(
right
)
left_paren
=
e
[
0
][
-
1
]
==
')'
right_paren
=
e
[
1
][
0
]
==
'('
left_int
=
is_int
(
left
)
if
(
left_id
or
left_paren
or
left_int
)
\
and
(
right_id
or
right_paren
):
sep
=
''
sep
=
''
result
+=
sep
.
join
(
e
)
result
+=
sep
.
join
(
e
)
...
...
tests/test_line.py
View file @
bf0b2e54
...
@@ -18,7 +18,7 @@ class TestLine(unittest.TestCase):
...
@@ -18,7 +18,7 @@ class TestLine(unittest.TestCase):
l0
,
l1
=
L
(
1
),
L
(
2
)
l0
,
l1
=
L
(
1
),
L
(
2
)
plus
=
N
(
'+'
,
l0
,
l1
)
plus
=
N
(
'+'
,
l0
,
l1
)
times
=
N
(
'*'
,
plus
,
plus
)
times
=
N
(
'*'
,
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_right
(
self
):
def
test_parentheses_equal_precedence_right
(
self
):
l0
,
l1
,
l2
=
L
(
1
),
L
(
2
),
L
(
3
)
l0
,
l1
,
l2
=
L
(
1
),
L
(
2
),
L
(
3
)
...
@@ -107,6 +107,12 @@ class TestLine(unittest.TestCase):
...
@@ -107,6 +107,12 @@ class TestLine(unittest.TestCase):
mul
=
N
(
'*'
,
a
,
N
(
'-'
,
b
,
c
))
mul
=
N
(
'*'
,
a
,
N
(
'-'
,
b
,
c
))
self
.
assertEquals
(
generate_line
(
mul
),
'a(b - c)'
)
self
.
assertEquals
(
generate_line
(
mul
),
'a(b - c)'
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
c
)
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)c'
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
N
(
'+'
,
c
,
l2
))
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)(c + 2)'
)
mul
=
N
(
'*'
,
l2
,
a
)
mul
=
N
(
'*'
,
l2
,
a
)
self
.
assertEquals
(
generate_line
(
mul
),
'2a'
)
self
.
assertEquals
(
generate_line
(
mul
),
'2a'
)
...
...
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