Forráskód Böngészése

Applied usage of Scope.replace method and fixed some failing unit tests.

Taddeus Kroes 14 éve
szülő
commit
c7a9125f63

+ 2 - 2
src/rules/factors.py

@@ -45,7 +45,7 @@ def expand_single(root, args):
     scope = Scope(root)
 
     # Replace 'a' with the new expression
-    scope.remove(a, a * b + a * c)
+    scope.replace(a, a * b + a * c)
 
     # Remove the addition
     scope.remove(bc)
@@ -66,7 +66,7 @@ def expand_double(root, args):
     scope = Scope(root)
 
     # Replace 'a + b' with the new expression
-    scope.remove(ab, a * c + a * d + b * c + b * d)
+    scope.replace(ab, a * c + a * d + b * c + b * d)
 
     # Remove the right addition
     scope.remove(cd)

+ 10 - 5
src/rules/fractions.py

@@ -1,7 +1,7 @@
 from itertools import combinations
 
 from .utils import least_common_multiple
-from ..node import ExpressionLeaf as L, Scope, OP_DIV, OP_ADD, OP_MUL
+from ..node import ExpressionLeaf as L, Scope, negate, OP_DIV, OP_ADD, OP_MUL
 from ..possibilities import Possibility as P, MESSAGES
 from ..translate import _
 
@@ -112,10 +112,15 @@ def equalize_denominators(root, args):
         mult = denom / d.value
 
         if mult != 1:
-            n = L(n.value * mult) if n.is_numeric() else L(mult) * n
+            if n.is_numeric():
+                n = L(n.value * mult)
+            else:
+                n = L(mult) * n
 
-            scope.remove(fraction, negate(n / L(d.value * mult),
-                                          fraction.negated))
+            #n = L(n.value * mult) if n.is_numeric() else L(mult) * n
+
+            scope.replace(fraction, negate(n / L(d.value * mult),
+                                           fraction.negated))
 
     return scope.as_nary_node()
 
@@ -137,7 +142,7 @@ def add_nominators(root, args):
     scope = Scope(root)
 
     # Replace the left node with the new expression
-    scope.remove(ab, (a + negate(cb[0], cb.negated)) / b)
+    scope.replace(ab, (a + cb[0].negate(cb.negated)) / b)
 
     # Remove the right node
     scope.remove(cb)

+ 1 - 1
src/rules/groups.py

@@ -59,7 +59,7 @@ def combine_groups(root, args):
         c0 = Leaf(c0)
 
     # Replace the left node with the new expression
-    scope.remove(n0, (c0 + c1) * g0)
+    scope.replace(n0, (c0 + c1) * g0)
 
     # Remove the right node
     scope.remove(n1)

+ 2 - 2
src/rules/numerics.py

@@ -19,7 +19,7 @@ def add_numerics(root, args):
     scope = Scope(root)
 
     # Replace the left node with the new expression
-    scope.remove(n0, Leaf(c0.actual_value() + c1.actual_value()))
+    scope.replace(n0, Leaf(c0.actual_value() + c1.actual_value()))
 
     # Remove the right node
     scope.remove(n1)
@@ -171,7 +171,7 @@ def multiply_numerics(root, args):
     scope = Scope(root)
 
     # Replace the left node with the new expression
-    scope.remove(n0, substitution)
+    scope.replace(n0, substitution)
 
     # Remove the right node
     scope.remove(n1)

+ 1 - 1
src/rules/poly.py

@@ -84,7 +84,7 @@ def combine_polynomes(root, args):
     # Replace the left node with the new expression:
     # (c0 + c1) * a ^ b
     # a, b and c are from 'left', d is from 'right'.
-    scope.remove(n0, (c0 + c1) * power)
+    scope.replace(n0, (c0 + c1) * power)
 
     # Remove the right node
     scope.remove(n1)

+ 1 - 1
src/rules/powers.py

@@ -54,7 +54,7 @@ def add_exponents(root, args):
     scope = Scope(root)
 
     # Replace the left node with the new expression
-    scope.remove(n0, a ** (p + q))
+    scope.replace(n0, a ** (p + q))
 
     # Remove the right node
     scope.remove(n1)