|
@@ -7,20 +7,31 @@ from tests.rulestestcase import RulesTestCase, tree
|
|
|
class TestRulesGroups(RulesTestCase):
|
|
class TestRulesGroups(RulesTestCase):
|
|
|
|
|
|
|
|
def test_match_combine_groups_no_const(self):
|
|
def test_match_combine_groups_no_const(self):
|
|
|
- a0, a1 = root = tree('a + a')
|
|
|
|
|
|
|
+ root, l1 = tree('a + a,1')
|
|
|
|
|
+ a0, a1 = root
|
|
|
|
|
+
|
|
|
|
|
+ possibilities = match_combine_groups(root)
|
|
|
|
|
+ self.assertEqualPos(possibilities,
|
|
|
|
|
+ [P(root, combine_groups, (Scope(root), l1, a0, a0,
|
|
|
|
|
+ l1, a1, a1))])
|
|
|
|
|
+
|
|
|
|
|
+ def test_match_combine_groups_negation(self):
|
|
|
|
|
+ root, l1 = tree('-a + a,1')
|
|
|
|
|
+ a0, a1 = root
|
|
|
|
|
|
|
|
possibilities = match_combine_groups(root)
|
|
possibilities = match_combine_groups(root)
|
|
|
self.assertEqualPos(possibilities,
|
|
self.assertEqualPos(possibilities,
|
|
|
- [P(root, combine_groups, (Scope(root), 1, a0, a0,
|
|
|
|
|
- 1, a1, a1))])
|
|
|
|
|
|
|
+ [P(root, combine_groups, (Scope(root), -l1, +a0, a0,
|
|
|
|
|
+ l1, a1, a1))])
|
|
|
|
|
|
|
|
def test_match_combine_groups_single_const(self):
|
|
def test_match_combine_groups_single_const(self):
|
|
|
- a0, mul = root = tree('a + 2a')
|
|
|
|
|
|
|
+ root, l1 = tree('a + 2a,1')
|
|
|
|
|
+ a0, mul = root
|
|
|
l2, a1 = mul
|
|
l2, a1 = mul
|
|
|
|
|
|
|
|
possibilities = match_combine_groups(root)
|
|
possibilities = match_combine_groups(root)
|
|
|
self.assertEqualPos(possibilities,
|
|
self.assertEqualPos(possibilities,
|
|
|
- [P(root, combine_groups, (Scope(root), 1, a0, a0,
|
|
|
|
|
|
|
+ [P(root, combine_groups, (Scope(root), l1, a0, a0,
|
|
|
l2, a1, mul))])
|
|
l2, a1, mul))])
|
|
|
|
|
|
|
|
def test_match_combine_groups_two_const(self):
|
|
def test_match_combine_groups_two_const(self):
|
|
@@ -44,37 +55,40 @@ class TestRulesGroups(RulesTestCase):
|
|
|
l4, a2, m2))])
|
|
l4, a2, m2))])
|
|
|
|
|
|
|
|
def test_match_combine_groups_identifier_group_no_const(self):
|
|
def test_match_combine_groups_identifier_group_no_const(self):
|
|
|
- ab0, ab1 = root = tree('ab + ab')
|
|
|
|
|
|
|
+ root, l1 = tree('ab + ab,1')
|
|
|
|
|
+ ab0, ab1 = root
|
|
|
|
|
|
|
|
possibilities = match_combine_groups(root)
|
|
possibilities = match_combine_groups(root)
|
|
|
self.assertEqualPos(possibilities,
|
|
self.assertEqualPos(possibilities,
|
|
|
- [P(root, combine_groups, (Scope(root), 1, ab0, ab0,
|
|
|
|
|
- 1, ab1, ab1))])
|
|
|
|
|
|
|
+ [P(root, combine_groups, (Scope(root), l1, ab0, ab0,
|
|
|
|
|
+ l1, ab1, ab1))])
|
|
|
|
|
|
|
|
def test_match_combine_groups_identifier_group_single_const(self):
|
|
def test_match_combine_groups_identifier_group_single_const(self):
|
|
|
- m0, m1 = root = tree('ab + 2ab')
|
|
|
|
|
|
|
+ root, l1 = tree('ab + 2ab,1')
|
|
|
|
|
+ m0, m1 = root
|
|
|
(l2, a), b = m1
|
|
(l2, a), b = m1
|
|
|
|
|
|
|
|
possibilities = match_combine_groups(root)
|
|
possibilities = match_combine_groups(root)
|
|
|
self.assertEqualPos(possibilities,
|
|
self.assertEqualPos(possibilities,
|
|
|
- [P(root, combine_groups, (Scope(root), 1, m0, m0,
|
|
|
|
|
|
|
+ [P(root, combine_groups, (Scope(root), l1, m0, m0,
|
|
|
l2, a * b, m1))])
|
|
l2, a * b, m1))])
|
|
|
|
|
|
|
|
def test_match_combine_groups_identifier_group_unordered(self):
|
|
def test_match_combine_groups_identifier_group_unordered(self):
|
|
|
- m0, m1 = root = tree('ab + ba')
|
|
|
|
|
|
|
+ root, l1 = tree('ab + ba,1')
|
|
|
|
|
+ m0, m1 = root
|
|
|
b, a = m1
|
|
b, a = m1
|
|
|
|
|
|
|
|
possibilities = match_combine_groups(root)
|
|
possibilities = match_combine_groups(root)
|
|
|
self.assertEqualPos(possibilities,
|
|
self.assertEqualPos(possibilities,
|
|
|
- [P(root, combine_groups, (Scope(root), 1, m0, m0,
|
|
|
|
|
- 1, b * a, m1))])
|
|
|
|
|
|
|
+ [P(root, combine_groups, (Scope(root), l1, m0, m0,
|
|
|
|
|
+ l1, b * a, m1))])
|
|
|
|
|
|
|
|
def test_combine_groups_simple(self):
|
|
def test_combine_groups_simple(self):
|
|
|
root, l1 = tree('a + a,1')
|
|
root, l1 = tree('a + a,1')
|
|
|
a0, a1 = root
|
|
a0, a1 = root
|
|
|
|
|
|
|
|
self.assertEqualNodes(combine_groups(root,
|
|
self.assertEqualNodes(combine_groups(root,
|
|
|
- (Scope(root), 1, a0, a0, 1, a1, a1)),
|
|
|
|
|
|
|
+ (Scope(root), l1, a0, a0, l1, a1, a1)),
|
|
|
(l1 + 1) * a0)
|
|
(l1 + 1) * a0)
|
|
|
|
|
|
|
|
def test_combine_groups_nary(self):
|
|
def test_combine_groups_nary(self):
|
|
@@ -83,5 +97,5 @@ class TestRulesGroups(RulesTestCase):
|
|
|
ab, b = abb
|
|
ab, b = abb
|
|
|
|
|
|
|
|
self.assertEqualNodes(combine_groups(root,
|
|
self.assertEqualNodes(combine_groups(root,
|
|
|
- (Scope(root), 1, ab, ab, 1, ba, ba)),
|
|
|
|
|
|
|
+ (Scope(root), l1, ab, ab, l1, ba, ba)),
|
|
|
(l1 + 1) * ab + b)
|
|
(l1 + 1) * ab + b)
|