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
86921137
Commit
86921137
authored
Jan 23, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate_line now rewrites 'a + -b' to 'a - b'.
parent
4fd27cc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
line.py
line.py
+7
-1
tests/test_line.py
tests/test_line.py
+4
-0
No files found.
line.py
View file @
86921137
...
@@ -103,8 +103,8 @@ def generate_line(root):
...
@@ -103,8 +103,8 @@ def generate_line(root):
e
.
append
(
exp
)
e
.
append
(
exp
)
# Check if a multiplication sign is nessecary
if
op
==
'*'
:
if
op
==
'*'
:
# Check if an explicit multiplication sign is nessecary
left
,
right
=
node
left
,
right
=
node
# Get the previous multiplication element if the arity is
# Get the previous multiplication element if the arity is
...
@@ -127,6 +127,12 @@ def generate_line(root):
...
@@ -127,6 +127,12 @@ def generate_line(root):
if
(
left_id
or
left_paren
or
left_int
)
\
if
(
left_id
or
left_paren
or
left_int
)
\
and
(
right_id
or
right_paren
):
and
(
right_id
or
right_paren
):
sep
=
''
sep
=
''
elif
op
==
'+'
:
# An addition with negation can be written as a
# subtraction, e.g. 1 + -2 == 1 - 2
if
node
[
1
].
title
()
==
'-'
and
len
(
node
[
1
])
==
1
:
sep
=
' - '
e
[
1
]
=
e
[
1
][
1
:]
result
+=
sep
.
join
(
e
)
result
+=
sep
.
join
(
e
)
else
:
else
:
...
...
tests/test_line.py
View file @
86921137
...
@@ -122,3 +122,7 @@ class TestLine(unittest.TestCase):
...
@@ -122,3 +122,7 @@ class TestLine(unittest.TestCase):
self
.
assertEquals
(
generate_line
(
mul
),
'2a'
)
self
.
assertEquals
(
generate_line
(
mul
),
'2a'
)
mul
=
N
(
'*'
,
a
,
l2
)
mul
=
N
(
'*'
,
a
,
l2
)
self
.
assertEquals
(
generate_line
(
mul
),
'a * 2'
)
self
.
assertEquals
(
generate_line
(
mul
),
'a * 2'
)
def
test_plus_to_minus
(
self
):
plus
=
N
(
'+'
,
L
(
1
),
N
(
'-'
,
L
(
2
)))
self
.
assertEquals
(
generate_line
(
plus
),
'1 - 2'
)
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