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
bf7d96e6
Commit
bf7d96e6
authored
Feb 20, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed unit tests form group rules.
parent
11a8876c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
src/rules/groups.py
src/rules/groups.py
+3
-3
tests/test_rules_groups.py
tests/test_rules_groups.py
+23
-11
No files found.
src/rules/groups.py
View file @
bf7d96e6
...
...
@@ -22,9 +22,9 @@ def match_combine_groups(node):
p
=
[]
groups
=
[]
scope
=
Scope
(
node
)
root_
scope
=
Scope
(
node
)
for
n
in
scope
:
for
n
in
root_
scope
:
groups
.
append
((
1
,
n
,
n
))
# Each number multiplication yields a group, multiple occurences of
...
...
@@ -46,7 +46,7 @@ def match_combine_groups(node):
for
g0
,
g1
in
combinations
(
groups
,
2
):
if
g0
[
1
].
equals
(
g1
[
1
]):
p
.
append
(
P
(
node
,
combine_groups
,
(
scope
,)
+
g0
+
g1
))
p
.
append
(
P
(
node
,
combine_groups
,
(
root_
scope
,)
+
g0
+
g1
))
return
p
...
...
tests/test_rules_groups.py
View file @
bf7d96e6
from
src.rules.groups
import
match_combine_groups
,
combine_groups
from
src.node
import
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
...
@@ -10,7 +11,8 @@ class TestRulesGroups(RulesTestCase):
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
1
,
a0
,
a0
,
1
,
a1
,
a1
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
1
,
a0
,
a0
,
1
,
a1
,
a1
))])
def
test_match_combine_groups_single_const
(
self
):
a0
,
mul
=
root
=
tree
(
'a + 2a'
)
...
...
@@ -18,30 +20,36 @@ class TestRulesGroups(RulesTestCase):
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
1
,
a0
,
a0
,
l2
,
a1
,
mul
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
1
,
a0
,
a0
,
l2
,
a1
,
mul
))])
def
test_match_combine_groups_two_const
(
self
):
((
l2
,
a0
),
b
),
(
l3
,
a1
)
=
(
m0
,
b
),
m1
=
root
=
tree
(
'2a + b + 3a'
)
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
l2
,
a0
,
m0
,
l3
,
a1
,
m1
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
l2
,
a0
,
m0
,
l3
,
a1
,
m1
))])
def
test_match_combine_groups_n_const
(
self
):
((
l2
,
a0
),
(
l3
,
a1
)),
(
l4
,
a2
)
=
(
m0
,
m1
),
m2
=
root
=
tree
(
'2a+3a+4a'
)
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
l2
,
a0
,
m0
,
l3
,
a1
,
m1
)),
P
(
root
,
combine_groups
,
(
l2
,
a0
,
m0
,
l4
,
a2
,
m2
)),
P
(
root
,
combine_groups
,
(
l3
,
a1
,
m1
,
l4
,
a2
,
m2
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
l2
,
a0
,
m0
,
l3
,
a1
,
m1
)),
P
(
root
,
combine_groups
,
(
Scope
(
root
),
l2
,
a0
,
m0
,
l4
,
a2
,
m2
)),
P
(
root
,
combine_groups
,
(
Scope
(
root
),
l3
,
a1
,
m1
,
l4
,
a2
,
m2
))])
def
test_match_combine_groups_identifier_group_no_const
(
self
):
ab0
,
ab1
=
root
=
tree
(
'ab + ab'
)
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
1
,
ab0
,
ab0
,
1
,
ab1
,
ab1
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
1
,
ab0
,
ab0
,
1
,
ab1
,
ab1
))])
def
test_match_combine_groups_identifier_group_single_const
(
self
):
m0
,
m1
=
root
=
tree
(
'ab + 2ab'
)
...
...
@@ -49,7 +57,8 @@ class TestRulesGroups(RulesTestCase):
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
1
,
m0
,
m0
,
l2
,
a
*
b
,
m1
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
1
,
m0
,
m0
,
l2
,
a
*
b
,
m1
))])
def
test_match_combine_groups_identifier_group_unordered
(
self
):
m0
,
m1
=
root
=
tree
(
'ab + ba'
)
...
...
@@ -57,13 +66,15 @@ class TestRulesGroups(RulesTestCase):
possibilities
=
match_combine_groups
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
combine_groups
,
(
1
,
m0
,
m0
,
1
,
b
*
a
,
m1
))])
[
P
(
root
,
combine_groups
,
(
Scope
(
root
),
1
,
m0
,
m0
,
1
,
b
*
a
,
m1
))])
def
test_combine_groups_simple
(
self
):
root
,
l1
=
tree
(
'a + a,1'
)
a0
,
a1
=
root
self
.
assertEqualNodes
(
combine_groups
(
root
,
(
1
,
a0
,
a0
,
1
,
a1
,
a1
)),
self
.
assertEqualNodes
(
combine_groups
(
root
,
(
Scope
(
root
),
1
,
a0
,
a0
,
1
,
a1
,
a1
)),
(
l1
+
1
)
*
a0
)
def
test_combine_groups_nary
(
self
):
...
...
@@ -71,5 +82,6 @@ class TestRulesGroups(RulesTestCase):
abb
,
ba
=
root
ab
,
b
=
abb
self
.
assertEqualNodes
(
combine_groups
(
root
,
(
1
,
ab
,
ab
,
1
,
ba
,
ba
)),
self
.
assertEqualNodes
(
combine_groups
(
root
,
(
Scope
(
root
),
1
,
ab
,
ab
,
1
,
ba
,
ba
)),
(
l1
+
1
)
*
ab
+
b
)
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