Added numeric combinations unit test and refactored tests.

parent 49ef7df0
...@@ -12,14 +12,6 @@ def tree(exp, **kwargs): ...@@ -12,14 +12,6 @@ def tree(exp, **kwargs):
class TestRulesPoly(unittest.TestCase): class TestRulesPoly(unittest.TestCase):
#def test_match_combine_polynomes_numeric_combinations(self):
# l0, l1, l2 = L(1), L(2), L(2)
# plus = N('+', N('+', l0, l1), l2)
# p = match_combine_polynomes(plus)
# self.assertEqualPos(p, [P(plus, combine_polynomes, (l0, l1)),
# P(plus, combine_polynomes, (l0, l2)),
# P(plus, combine_polynomes, (l1, l2))])
def assertEqualPos(self, possibilities, expected): def assertEqualPos(self, possibilities, expected):
self.assertEqual(len(possibilities), len(expected)) self.assertEqual(len(possibilities), len(expected))
...@@ -33,35 +25,40 @@ class TestRulesPoly(unittest.TestCase): ...@@ -33,35 +25,40 @@ class TestRulesPoly(unittest.TestCase):
def test_numbers(self): def test_numbers(self):
l1, l2 = root = tree('1+2') l1, l2 = root = tree('1+2')
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((l1, (l1, l1, l1)), [P(root, combine_polynomes, ((l1, (l1, l1, l1)),
(l2, (l1, l2, l1))))]) (l2, (l1, l2, l1))))])
def test_identifiers_basic(self): def test_identifiers_basic(self):
l1, l2 = tree('1,2') l1, l2 = tree('1,2')
a1, a2 = root = tree('a+a') a1, a2 = root = tree('a+a')
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((a1, (l1, a1, l1)), [P(root, combine_polynomes, ((a1, (l1, a1, l1)),
(a2, (l1, a2, l1))))]) (a2, (l1, a2, l1))))])
def test_identifiers_normal(self): def test_identifiers_normal(self):
l1, l2 = tree('1,2') l1, l2 = tree('1,2')
a1, a2 = root = tree('a+2a') a1, a2 = root = tree('a+2a')
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((a1, (l1, a1, l1)), [P(root, combine_polynomes, ((a1, (l1, a1, l1)),
(a2, (l2, a2[1], l1))))]) (a2, (l2, a2[1], l1))))])
def test_identifiers_reverse(self): def test_identifiers_reverse(self):
l1, l2, la = tree('1,2,a') l1, l2, la = tree('1,2,a')
a1, a2 = root = tree('a+a*2') a1, a2 = root = tree('a+a*2')
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((a1, (l1, a1, l1)), [P(root, combine_polynomes, ((a1, (l1, a1, l1)),
(a2, (l2, la, l1))))]) (a2, (l2, la, l1))))])
def test_identifiers_exponent(self): def test_identifiers_exponent(self):
l1, l2 = tree('1,2') l1, l2 = tree('1,2')
a1, a2 = root = tree('a2+a2') a1, a2 = root = tree('a2+a2')
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((a1, (l1, a1[0], l2)), [P(root, combine_polynomes, ((a1, (l1, a1[0], l2)),
(a2, (l1, a2[0], l2))))]) (a2, (l1, a2[0], l2))))])
...@@ -70,19 +67,34 @@ class TestRulesPoly(unittest.TestCase): ...@@ -70,19 +67,34 @@ class TestRulesPoly(unittest.TestCase):
left, right = root = tree('(a+b)^d + (a+b)^d') left, right = root = tree('(a+b)^d + (a+b)^d')
self.assertEqual(left, right) self.assertEqual(left, right)
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((left, (l1, a_b, d)), [P(root, combine_polynomes, ((left, (l1, a_b, d)),
(right, (l1, a_b, d))))]) (right, (l1, a_b, d))))])
left, right = root = tree('5(a+b)^d + 7(a+b)^d') left, right = root = tree('5(a+b)^d + 7(a+b)^d')
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((left, (l5, a_b, d)), [P(root, combine_polynomes, ((left, (l5, a_b, d)),
(right, (l7, a_b, d))))]) (right, (l7, a_b, d))))])
left, right = root = tree('c(a+b)^d + c(a+b)^d') left, right = root = tree('c(a+b)^d + c(a+b)^d')
self.assertEqual(left, right) self.assertEqual(left, right)
self.assertEqualPos(match_combine_polynomes(root), possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((left, (c, a_b, d)), [P(root, combine_polynomes, ((left, (c, a_b, d)),
(right, (c, a_b, d))))]) (right, (c, a_b, d))))])
def test_match_combine_polynomes_numeric_combinations(self):
root = tree('0+1+2')
l0, l1, l2 = root[0][0], root[0][1], root[1]
possibilities = match_combine_polynomes(root)
self.assertEqualPos(possibilities,
[P(root, combine_polynomes, ((l0, (l1, l0, l1)),
(l1, (l1, l1, l1)))),
P(root, combine_polynomes, ((l0, (l1, l0, l1)),
(l2, (l1, l2, l1)))),
P(root, combine_polynomes, ((l1, (l1, l1, l1)),
(l2, (l1, l2, l1))))])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment