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
ea4270eb
Commit
ea4270eb
authored
Apr 09, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduced negation precedence to MINUS.
parent
70714ec0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
line.py
line.py
+5
-1
tests/test_line.py
tests/test_line.py
+5
-3
No files found.
line.py
View file @
ea4270eb
...
@@ -142,7 +142,11 @@ def generate_line(root):
...
@@ -142,7 +142,11 @@ def generate_line(root):
if
child
.
negated
:
if
child
.
negated
:
# (-a) ^ b
# (-a) ^ b
if
op
==
'^'
and
not
i
:
# -a ^ -b
# (-a) * b
# a * -b
# (-a) / b
if
(
node_pred
>
NEG_PRED
and
not
i
):
exp
=
'('
+
exp
+
')'
exp
=
'('
+
exp
+
')'
elif
child_pred
<
node_pred
:
elif
child_pred
<
node_pred
:
exp
=
'('
+
exp
+
')'
exp
=
'('
+
exp
+
')'
...
...
tests/test_line.py
View file @
ea4270eb
...
@@ -138,8 +138,10 @@ class TestLine(unittest.TestCase):
...
@@ -138,8 +138,10 @@ class TestLine(unittest.TestCase):
mul
=
N
(
'*'
,
N
(
'*'
,
a
,
l2
),
b
)
mul
=
N
(
'*'
,
N
(
'*'
,
a
,
l2
),
b
)
self
.
assertEquals
(
generate_line
(
mul
),
'a * 2b'
)
self
.
assertEquals
(
generate_line
(
mul
),
'a * 2b'
)
plus
=
N
(
'*'
,
N
(
'*'
,
-
a
,
b
),
c
)
mul
=
-
N
(
'*'
,
N
(
'*'
,
a
,
b
),
c
)
self
.
assertEquals
(
generate_line
(
plus
),
'-abc'
)
self
.
assertEquals
(
generate_line
(
mul
),
'-abc'
)
mul
=
N
(
'*'
,
N
(
'*'
,
-
a
,
b
),
c
)
self
.
assertEquals
(
generate_line
(
mul
),
'(-a)bc'
)
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)'
)
...
@@ -173,7 +175,7 @@ class TestLine(unittest.TestCase):
...
@@ -173,7 +175,7 @@ class TestLine(unittest.TestCase):
self
.
assertEquals
(
generate_line
(
plus
),
'1 - 2'
)
self
.
assertEquals
(
generate_line
(
plus
),
'1 - 2'
)
l1
,
a
,
b
,
c
=
L
(
1
),
L
(
'a'
),
L
(
'b'
),
L
(
'c'
)
l1
,
a
,
b
,
c
=
L
(
1
),
L
(
'a'
),
L
(
'b'
),
L
(
'c'
)
plus
=
N
(
'+'
,
l1
,
N
(
'*'
,
N
(
'*'
,
-
a
,
b
),
c
))
plus
=
N
(
'+'
,
l1
,
-
N
(
'*'
,
N
(
'*'
,
a
,
b
),
c
))
self
.
assertEquals
(
generate_line
(
plus
),
'1 - abc'
)
self
.
assertEquals
(
generate_line
(
plus
),
'1 - abc'
)
def
test_helper_functions
(
self
):
def
test_helper_functions
(
self
):
...
...
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