Ver código fonte

Bugfix: added negation copy to substitute function.

Taddeus Kroes 14 anos atrás
pai
commit
49391e6c0f
4 arquivos alterados com 5 adições e 6 exclusões
  1. 1 1
      external/graph_drawing
  2. 1 4
      src/node.py
  3. 1 1
      src/rules/utils.py
  4. 2 0
      tests/test_rules_utils.py

+ 1 - 1
external/graph_drawing

@@ -1 +1 @@
-Subproject commit aade5fc51f4b19e84d180fcff9b6c6d89db93667
+Subproject commit ab2d0af74078bf71f10da5e1f671f866caa84908

+ 1 - 4
src/node.py

@@ -32,7 +32,7 @@ OP_AND = 9
 OP_OR = 10
 
 # Binary operators that are considered n-ary
-NARY_OPERATORS = [OP_ADD, OP_SUB, OP_MUL]
+NARY_OPERATORS = [OP_ADD, OP_SUB, OP_MUL, OP_AND, OP_OR]
 
 # N-ary (functions)
 OP_INT = 11
@@ -139,9 +139,6 @@ def to_expression(obj):
 
 
 class ExpressionBase(object):
-    def __init__(self, *args, **kwargs):
-        self.negated = 0
-
     def __lt__(self, other):
         """
         Comparison between this expression{node,leaf} and another

+ 1 - 1
src/rules/utils.py

@@ -125,7 +125,7 @@ def substitute(f, x, replacement):
 
     children = map(lambda c: substitute(c, x, replacement), f)
 
-    return N(f.op, *children)
+    return N(f.op, *children, negated=f.negated)
 
 
 def divides(m, n):

+ 2 - 0
tests/test_rules_utils.py

@@ -58,6 +58,8 @@ class TestRulesUtils(RulesTestCase):
         self.assertEqual(substitute(tree('x2'), x, a), tree('a2'))
         self.assertEqual(substitute(tree('y + x + 1'), x, a),
                          tree('y + a + 1'))
+        self.assertEqual(substitute(tree('1 - 2x'), x, a),
+                         tree('1 - 2a'))
 
     def test_divides(self):
         self.assertTrue(divides(3, 3))