Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
graph_drawing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
graph_drawing
Commits
da0af403
Commit
da0af403
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed parenthesis with new negation method in line generator.
parent
fbfd0f2a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
line.py
+9
-6
9 additions, 6 deletions
line.py
tests/test_line.py
+15
-0
15 additions, 0 deletions
tests/test_line.py
with
24 additions
and
6 deletions
line.py
+
9
−
6
View file @
da0af403
...
...
@@ -255,13 +255,18 @@ def generate_line(root):
for
i
,
child
in
enumerate
(
node
):
exp
=
content
[
child
]
#if i and op == '+' and exp[:2] == '-(':
# exp = '-' + exp[2:-1]
# print 'exp:', exp
# Check if there is a precedence conflict
# If so, add parentheses
child_pred
=
pred
(
child
)
if
child_pred
<
node_pred
or
\
(
i
and
child_pred
==
node_pred
\
and
op
!=
child
.
title
()):
if
not
child
.
negated
and
(
child_pred
<
node_pred
\
or
(
i
and
child_pred
==
node_pred
\
and
(
op
!=
child
.
title
()
\
or
(
op
==
'
+
'
and
child
[
1
].
negated
)))):
exp
=
'
(
'
+
exp
+
'
)
'
e
.
append
(
exp
)
...
...
@@ -290,9 +295,7 @@ def generate_line(root):
exp
=
sep
.
join
(
e
)
#if node.negated:
# FIXME: Keep it this way?
if
node
.
negated
and
op
!=
'
*
'
:
if
node
.
negated
and
op
not
in
(
'
*
'
,
'
/
'
):
exp
=
'
(
'
+
exp
+
'
)
'
return
exp
...
...
This diff is collapsed.
Click to expand it.
tests/test_line.py
+
15
−
0
View file @
da0af403
...
...
@@ -162,12 +162,21 @@ class TestLine(unittest.TestCase):
neg
=
-
N
(
'
-
'
,
L
(
1
),
L
(
2
))
self
.
assertEquals
(
generate_line
(
neg
),
'
-(1 - 2)
'
)
neg
=
N
(
'
+
'
,
L
(
1
),
N
(
'
+
'
,
L
(
1
),
L
(
2
)))
self
.
assertEquals
(
generate_line
(
neg
),
'
1 + 1 + 2
'
)
neg
=
N
(
'
+
'
,
L
(
1
),
-
N
(
'
+
'
,
L
(
1
),
L
(
2
)))
self
.
assertEquals
(
generate_line
(
neg
),
'
1 - (1 + 2)
'
)
neg
=
N
(
'
+
'
,
L
(
1
),
N
(
'
+
'
,
L
(
1
),
-
L
(
2
)))
self
.
assertEquals
(
generate_line
(
neg
),
'
1 + (1 - 2)
'
)
neg
=
-
N
(
'
*
'
,
L
(
4
),
L
(
'
a
'
))
self
.
assertEquals
(
generate_line
(
neg
),
'
-4a
'
)
neg
=
N
(
'
*
'
,
L
(
4
),
-
L
(
'
a
'
))
self
.
assertEquals
(
generate_line
(
neg
),
'
4 * -a
'
)
neg
=
-
N
(
'
*
'
,
L
(
4
),
L
(
5
))
self
.
assertEquals
(
generate_line
(
neg
),
'
-4 * 5
'
)
...
...
@@ -177,6 +186,12 @@ class TestLine(unittest.TestCase):
plus
=
N
(
'
+
'
,
L
(
1
),
-
L
(
4
))
self
.
assertEquals
(
generate_line
(
plus
),
'
1 - 4
'
)
plus
=
N
(
'
+
'
,
N
(
'
/
'
,
L
(
'
a
'
),
L
(
'
b
'
)),
-
N
(
'
/
'
,
L
(
'
c
'
),
L
(
'
d
'
)))
self
.
assertEquals
(
generate_line
(
plus
),
'
a / b - c / d
'
)
mul
=
N
(
'
*
'
,
N
(
'
+
'
,
L
(
'
a
'
),
L
(
'
b
'
)),
-
N
(
'
+
'
,
L
(
'
c
'
),
L
(
'
d
'
)))
self
.
assertEquals
(
generate_line
(
mul
),
'
(a + b) * -(c + d)
'
)
def
test_double_negation
(
self
):
neg
=
--
L
(
1
)
self
.
assertEquals
(
generate_line
(
neg
),
'
--1
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment