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
01cf1342
Commit
01cf1342
authored
Mar 14, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved multiplication sign omission.
parent
bb3c5d23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
10 deletions
+8
-10
line.py
line.py
+4
-9
tests/test_line.py
tests/test_line.py
+4
-1
No files found.
line.py
View file @
01cf1342
...
@@ -166,16 +166,11 @@ def generate_line(root):
...
@@ -166,16 +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
l
eft_paren
=
e
[
0
][
-
1
]
==
')'
l
=
e
[
0
][
-
1
]
r
ight_paren
=
e
[
1
][
0
]
==
'('
r
=
e
[
1
][
0
]
left_suited
=
left_paren
or
is_id
(
left
)
or
is_int
(
left
)
if
r
==
'('
or
(
l
==
')'
and
r
!=
'-'
)
\
right_suited
=
right_paren
or
((
is_id
(
left
)
or
is_int
(
left
))
and
r
.
isalpha
()):
if
not
right_suited
and
not
right
.
negated
:
right_suited
=
is_id
(
right
)
or
is_power
(
right
)
if
left_suited
and
right_suited
:
sep
=
''
sep
=
''
exp
=
sep
.
join
(
e
)
exp
=
sep
.
join
(
e
)
...
...
tests/test_line.py
View file @
01cf1342
...
@@ -139,7 +139,7 @@ class TestLine(unittest.TestCase):
...
@@ -139,7 +139,7 @@ class TestLine(unittest.TestCase):
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
c
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
c
)
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)c'
)
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)c'
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
l2
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
l2
)
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)
*
2'
)
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)2'
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
N
(
'+'
,
c
,
l2
))
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
N
(
'+'
,
c
,
l2
))
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)(c + 2)'
)
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)(c + 2)'
)
...
@@ -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
(
'*'
,
l2
,
N
(
'^'
,
l2
,
a
))
self
.
assertEquals
(
generate_line
(
mul
),
'2 * 2 ^ a'
)
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'
)
...
...
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