Commit 77af3ae1 authored by Taddeus Kroes's avatar Taddeus Kroes

Fixed non-strict node comparison.\n\n- Children lists of each non-addition or...

Fixed non-strict node comparison.\n\n- Children lists of each non-addition or -multiplication are now compared in order.
parent e32aa00c
......@@ -313,8 +313,11 @@ class ExpressionNode(Node, ExpressionBase):
if not found:
return False
elif self.op == OP_DIV:
return self[0].equals(other[0]) and self[1].equals(other[1])
else:
# Check if all children are non-strictly equal, preserving order
for i, child in enumerate(self):
if not child.equals(other[i]):
return False
return True
......
......@@ -3,6 +3,7 @@ from itertools import combinations
from ..node import OP_ADD, OP_MUL, ExpressionNode as Node, \
ExpressionLeaf as Leaf
from ..possibilities import Possibility as P, MESSAGES
from ..translate import _
from .utils import nary_node
......@@ -39,8 +40,10 @@ def match_combine_groups(node):
g = others[0] if len(others) == 1 else Node('*', *others)
groups.append((sub_node, g, n))
#print [map(str, group) for group in groups]
for g0, g1 in combinations(groups, 2):
if g0[1].equals(g1[1]):
#print type(g0[1]), str(g0[1]), 'equals', type(g1[1]), str(g1[1])
p.append(P(node, combine_groups, g0 + g1))
return p
......@@ -61,3 +64,7 @@ def combine_groups(root, args):
scope.remove(n1)
return nary_node('+', scope)
MESSAGES[combine_groups] = \
_('Group "{2}" is multiplied by {1} and {4}, combine them.')
......@@ -4,7 +4,8 @@ from tests.rulestestcase import RulesTestCase as TestCase, rewrite
class TestLeidenOefenopgave(TestCase):
def test_1(self):
for chain in [['-5(x2 - 3x + 6)', '-5(x ^ 2 - 3x) - 5 * 6',
# FIXME: '-5 * x ^ 2 - 5 * -3x - 5 * 6',
'-5 * x ^ 2 - 5 * -3x - 5 * 6',
'-5 * x ^ 2 - -15x - 5 * 6',
# FIXME: '-5 * x ^ 2 - 5 * -3x - 30',
], #'-30 + 15 * x - 5 * x ^ 2'],
]:
......
......@@ -138,7 +138,7 @@ class TestNode(unittest.TestCase):
def test_equals_nary(self):
p0, p1, p2, p3, p4 = \
tree('a + b + c,a + c + b,b + a + c,b + c + a, a + b + d')
tree('a + b + c,a + c + b,b + a + c,b + c + a,a + b + d')
self.assertTrue(p0.equals(p1))
self.assertTrue(p0.equals(p2))
......@@ -158,3 +158,13 @@ class TestNode(unittest.TestCase):
self.assertTrue(d0.equals(d1))
self.assertFalse(d0.equals(d2))
def test_equals_neg(self):
a0, a1 = tree('-a,a')
self.assertFalse(a0.equals(a1))
a0, a1 = tree('-a,-a')
self.assertTrue(a0.equals(a1))
m0, m1 = tree('-5 * -3,-5 * 6')
self.assertFalse(m0.equals(m1))
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