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
821c5062
Commit
821c5062
authored
Feb 27, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed multiplication sign omission when left node ends with a digit.
parent
43e674b5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
14 deletions
+8
-14
line.py
line.py
+4
-8
tests/test_line.py
tests/test_line.py
+4
-6
No files found.
line.py
View file @
821c5062
...
@@ -39,10 +39,6 @@ def is_id(node):
...
@@ -39,10 +39,6 @@ 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
()
==
'^'
...
@@ -166,11 +162,11 @@ def generate_line(root):
...
@@ -166,11 +162,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_
paren
=
e
[
0
][
-
1
]
==
')'
left_
end
=
e
[
0
][
-
1
]
right_
paren
=
e
[
1
][
0
]
==
'('
right_
begin
=
e
[
1
][
0
]
left_suited
=
left_
paren
or
is_id
(
left
)
or
is_int
(
left
)
left_suited
=
left_
end
==
')'
or
left_end
.
isdigit
()
or
is_id
(
left
)
right_suited
=
right_
paren
right_suited
=
right_
begin
==
'('
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 @
821c5062
...
@@ -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_
int
,
is_
power
from
line
import
generate_line
,
is_id
,
is_power
class
TestLine
(
unittest
.
TestCase
):
class
TestLine
(
unittest
.
TestCase
):
...
@@ -152,6 +152,9 @@ class TestLine(unittest.TestCase):
...
@@ -152,6 +152,9 @@ 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'
)
...
@@ -172,11 +175,6 @@ class TestLine(unittest.TestCase):
...
@@ -172,11 +175,6 @@ 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