Commit 031e326f authored by Taddeus Kroes's avatar Taddeus Kroes

Added equality chck and negation take-over to Scope object.

parent f5d48c99
......@@ -354,6 +354,10 @@ class Scope(object):
def __iter__(self):
return iter(self.nodes)
def __eq__(self, other):
return isinstance(other, Scope) and self.node == other.node \
and self.nodes == other.node
def remove(self, node, replacement=None):
if node.is_leaf:
node_cmp = hash(node)
......@@ -381,7 +385,7 @@ class Scope(object):
self.remove(node, replacement=replacement)
def as_nary_node(self):
return nary_node(self.node.value, self.nodes)
return nary_node(self.node.value, self.nodes).negate(self.node.negated)
def nary_node(operator, scope):
......
......@@ -193,3 +193,8 @@ class TestNode(RulesTestCase):
def test_scope_as_nary_node(self):
self.assertEqualNodes(self.scope.as_nary_node(), self.n)
def test_scope_as_nary_node_negated(self):
n = tree('-(a + b)')
self.assertEqualNodes(Scope(n).as_nary_node(), n)
self.assertEqualNodes(Scope(-n).as_nary_node(), -n)
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