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
7f65d03d
Commit
7f65d03d
authored
Feb 27, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Fixed multiplication sign omission when left node ends with a digit."
This reverts commit
821c5062
.
parent
821c5062
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
line.py
line.py
+8
-4
tests/test_line.py
tests/test_line.py
+6
-4
No files found.
line.py
View file @
7f65d03d
...
@@ -39,6 +39,10 @@ def is_id(node):
...
@@ -39,6 +39,10 @@ def is_id(node):
return
node
.
is_leaf
and
not
node
.
title
().
isdigit
()
return
node
.
is_leaf
and
not
node
.
title
().
isdigit
()
def
is_int
(
node
):
return
node
.
is_leaf
and
node
.
title
().
isdigit
()
def
is_power
(
node
):
def
is_power
(
node
):
return
not
node
.
is_leaf
and
node
.
title
()
==
'^'
return
not
node
.
is_leaf
and
node
.
title
()
==
'^'
...
@@ -162,11 +166,11 @@ def generate_line(root):
...
@@ -162,11 +166,11 @@ def generate_line(root):
# (a) * b -> (a)b
# (a) * b -> (a)b
# (a) * (b) -> (a)(b)
# (a) * (b) -> (a)(b)
# 2 * a -> 2a
# 2 * a -> 2a
left_
end
=
e
[
0
][
-
1
]
left_
paren
=
e
[
0
][
-
1
]
==
')'
right_
begin
=
e
[
1
][
0
]
right_
paren
=
e
[
1
][
0
]
==
'('
left_suited
=
left_
end
==
')'
or
left_end
.
isdigit
()
or
is_id
(
left
)
left_suited
=
left_
paren
or
is_id
(
left
)
or
is_int
(
left
)
right_suited
=
right_
begin
==
'('
right_suited
=
right_
paren
if
not
right_suited
and
not
right
.
negated
:
if
not
right_suited
and
not
right
.
negated
:
right_suited
=
is_id
(
right
)
or
is_power
(
right
)
right_suited
=
is_id
(
right
)
or
is_power
(
right
)
...
...
tests/test_line.py
View file @
7f65d03d
...
@@ -3,7 +3,7 @@ import doctest
...
@@ -3,7 +3,7 @@ import doctest
import
line
import
line
from
node
import
Node
as
N
,
Leaf
as
L
from
node
import
Node
as
N
,
Leaf
as
L
from
line
import
generate_line
,
is_id
,
is_power
from
line
import
generate_line
,
is_id
,
is_
int
,
is_
power
class
TestLine
(
unittest
.
TestCase
):
class
TestLine
(
unittest
.
TestCase
):
...
@@ -152,9 +152,6 @@ class TestLine(unittest.TestCase):
...
@@ -152,9 +152,6 @@ class TestLine(unittest.TestCase):
mul
=
N
(
'*'
,
l2
,
N
(
'^'
,
a
,
l2
))
mul
=
N
(
'*'
,
l2
,
N
(
'^'
,
a
,
l2
))
self
.
assertEquals
(
generate_line
(
mul
),
'2a ^ 2'
)
self
.
assertEquals
(
generate_line
(
mul
),
'2a ^ 2'
)
mul
=
N
(
'*'
,
N
(
'^'
,
a
,
l2
),
N
(
'+'
,
a
,
b
))
self
.
assertEquals
(
generate_line
(
mul
),
'a ^ 2(a + b)'
)
def
test_plus_to_minus
(
self
):
def
test_plus_to_minus
(
self
):
plus
=
N
(
'+'
,
L
(
1
),
-
L
(
2
))
plus
=
N
(
'+'
,
L
(
1
),
-
L
(
2
))
self
.
assertEquals
(
generate_line
(
plus
),
'1 - 2'
)
self
.
assertEquals
(
generate_line
(
plus
),
'1 - 2'
)
...
@@ -175,6 +172,11 @@ class TestLine(unittest.TestCase):
...
@@ -175,6 +172,11 @@ class TestLine(unittest.TestCase):
self
.
assertFalse
(
is_id
(
neg
))
self
.
assertFalse
(
is_id
(
neg
))
self
.
assertFalse
(
is_id
(
plus
))
self
.
assertFalse
(
is_id
(
plus
))
self
.
assertTrue
(
is_int
(
l1
))
self
.
assertTrue
(
is_int
(
neg
))
self
.
assertFalse
(
is_int
(
neg_a
))
self
.
assertFalse
(
is_int
(
plus
))
self
.
assertTrue
(
is_power
(
power
))
self
.
assertTrue
(
is_power
(
power
))
self
.
assertFalse
(
is_power
(
l1
))
self
.
assertFalse
(
is_power
(
l1
))
self
.
assertFalse
(
is_power
(
plus
))
self
.
assertFalse
(
is_power
(
plus
))
...
...
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