Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
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
trs
Commits
90549d26
Commit
90549d26
authored
Jan 14, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of kompiler.org:trs
parents
0c9c2995
1257c37a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
17 deletions
+27
-17
src/possibilities.py
src/possibilities.py
+8
-12
tests/test_possibilities.py
tests/test_possibilities.py
+19
-3
tests/test_rules_poly.py
tests/test_rules_poly.py
+0
-2
No files found.
src/possibilities.py
View file @
90549d26
...
...
@@ -28,30 +28,26 @@ class Possibility(object):
and
self
.
args
==
other
.
args
def
filter_duplicates
(
item
s
):
def
filter_duplicates
(
possibilitie
s
):
"""
Filter duplicated possibilities. Duplicated possibilities occur in n-ary
nodes, the root-level node and a lower-level node will both recognize a
re
q
rite possibility within their sscope, whereas only the root-level one
re
w
rite possibility within their sscope, whereas only the root-level one
matters.
Example: 1 + 2 + 3
The addition of 1 and 2 is recognized bij n-ary additions "1 + 2" and
"1 + 2 + 3". The "1 + 2" addition should be removed by this function.
"""
# TODO: Finish according to docstrings
features
=
[]
unique
=
[]
for
item
in
items
:
f
ound
=
False
for
p
in
reversed
(
possibilities
)
:
f
eature
=
(
p
.
handler
,
p
.
args
)
for
compare
in
unique
:
if
item
==
compare
:
found
=
True
break
if
not
found
:
unique
.
append
(
item
)
if
feature
not
in
features
:
features
.
append
(
feature
)
unique
.
insert
(
0
,
p
)
return
unique
...
...
tests/test_possibilities.py
View file @
90549d26
import
unittest
from
src.possibilities
import
MESSAGES
,
Possibility
as
P
,
filter_duplicates
from
src.rules.numerics
import
add_numerics
from
tests.test_rules_poly
import
tree
...
...
@@ -36,7 +37,22 @@ class TestPossibilities(unittest.TestCase):
assert
self
.
p0
!=
self
.
p1
def
test_filter_duplicates
(
self
):
a
,
b
=
ab
=
tree
(
'a + b'
)
p0
=
P
(
a
,
dummy_handler
,
(
1
,
2
))
p1
=
P
(
ab
,
dummy_handler
,
(
1
,
2
))
p2
=
P
(
ab
,
dummy_handler
,
(
1
,
2
,
3
))
p3
=
P
(
ab
,
dummy_handler_msg
,
(
1
,
2
))
self
.
assertEqual
(
filter_duplicates
([]),
[])
self
.
assertEqual
(
filter_duplicates
([
1
,
2
]),
[
1
,
2
])
self
.
assertEqual
(
filter_duplicates
([
1
,
2
,
2
]),
[
1
,
2
])
self
.
assertEqual
(
filter_duplicates
([
1
,
2
,
3
,
2
]),
[
1
,
2
,
3
])
self
.
assertEqual
(
filter_duplicates
([
p0
,
p1
]),
[
p1
])
self
.
assertEqual
(
filter_duplicates
([
p1
,
p2
]),
[
p1
,
p2
])
self
.
assertEqual
(
filter_duplicates
([
p1
,
p3
]),
[
p1
,
p3
])
self
.
assertEqual
(
filter_duplicates
([
p0
,
p1
,
p2
,
p3
]),
[
p1
,
p2
,
p3
])
# Docstrings example
(
l1
,
l2
),
l3
=
left
,
l3
=
right
=
tree
(
'1 + 2 + 3'
)
p0
=
P
(
left
,
add_numerics
,
(
1
,
2
,
1
,
2
))
p1
=
P
(
right
,
add_numerics
,
(
1
,
2
,
1
,
2
))
p2
=
P
(
right
,
add_numerics
,
(
1
,
3
,
1
,
3
))
p3
=
P
(
right
,
add_numerics
,
(
2
,
3
,
2
,
3
))
self
.
assertEqual
(
filter_duplicates
([
p0
,
p1
,
p2
,
p3
]),
[
p1
,
p2
,
p3
])
tests/test_rules_poly.py
View file @
90549d26
...
...
@@ -25,8 +25,6 @@ class TestRulesPoly(RulesTestCase):
[
P
(
root
,
combine_polynomes
,
(
a1
,
a2
,
1
,
2
,
'a'
,
1
))])
def
test_identifiers_reverse
(
self
):
return
# TODO: Move to normalisation test
a1
,
a2
=
root
=
tree
(
'a+a*2'
)
possibilities
=
match_combine_polynomes
(
root
)
self
.
assertEqualPos
(
possibilities
,
...
...
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