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
821c5062
Commit
821c5062
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed multiplication sign omission when left node ends with a digit.
parent
43e674b5
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
+4
-8
4 additions, 8 deletions
line.py
tests/test_line.py
+4
-6
4 additions, 6 deletions
tests/test_line.py
with
8 additions
and
14 deletions
line.py
+
4
−
8
View file @
821c5062
...
...
@@ -39,10 +39,6 @@ def is_id(node):
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
):
return
not
node
.
is_leaf
and
node
.
title
()
==
'
^
'
...
...
@@ -166,11 +162,11 @@ def generate_line(root):
# (a) * b -> (a)b
# (a) * (b) -> (a)(b)
# 2 * a -> 2a
left_
par
en
=
e
[
0
][
-
1
]
==
'
)
'
right_
pare
n
=
e
[
1
][
0
]
==
'
(
'
left_en
d
=
e
[
0
][
-
1
]
right_
begi
n
=
e
[
1
][
0
]
left_suited
=
left_
paren
or
is_id
(
left
)
or
is_i
nt
(
left
)
right_suited
=
right_
paren
left_suited
=
left_
end
==
'
)
'
or
left_end
.
isdigit
(
)
or
is_i
d
(
left
)
right_suited
=
right_
begin
==
'
(
'
if
not
right_suited
and
not
right
.
negated
:
right_suited
=
is_id
(
right
)
or
is_power
(
right
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_line.py
+
4
−
6
View file @
821c5062
...
...
@@ -3,7 +3,7 @@ import doctest
import
line
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
):
...
...
@@ -152,6 +152,9 @@ class TestLine(unittest.TestCase):
mul
=
N
(
'
*
'
,
l2
,
N
(
'
^
'
,
a
,
l2
))
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
):
plus
=
N
(
'
+
'
,
L
(
1
),
-
L
(
2
))
self
.
assertEquals
(
generate_line
(
plus
),
'
1 - 2
'
)
...
...
@@ -172,11 +175,6 @@ class TestLine(unittest.TestCase):
self
.
assertFalse
(
is_id
(
neg
))
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
.
assertFalse
(
is_power
(
l1
))
self
.
assertFalse
(
is_power
(
plus
))
...
...
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