Explorar el Código

Fixed previously added rule for all negation cases.

Taddeus Kroes hace 13 años
padre
commit
d53719e88f
Se han modificado 2 ficheros con 13 adiciones y 1 borrados
  1. 1 1
      src/rules/fractions.py
  2. 12 0
      tests/test_rules_fractions.py

+ 1 - 1
src/rules/fractions.py

@@ -570,7 +570,7 @@ def fraction_in_division(root, args):
     is_nominator, scope, fraction = args
     nom, denom = root
 
-    if fraction.negated:
+    if fraction.negated or fraction[0].negated:
         scope.replace(fraction, fraction[0].negate(fraction.negated))
     else:
         scope.remove(fraction)

+ 12 - 0
tests/test_rules_fractions.py

@@ -383,3 +383,15 @@ class TestRulesFractions(RulesTestCase):
         root, expected = tree('c / (1 / a * b), (ac) / b')
         self.assertEqual(fraction_in_division(root,
             (False, Scope(root[1]), root[1][0])), expected)
+
+        root, expected = tree('c / (-(1 / a) * b), (ac) / ((-1)b)')
+        self.assertEqual(fraction_in_division(root,
+            (False, Scope(root[1]), root[1][0])), expected)
+
+        root, expected = tree('c / ((-1) / a * b), (ac) / ((-1)b)')
+        self.assertEqual(fraction_in_division(root,
+            (False, Scope(root[1]), root[1][0])), expected)
+
+        root, expected = tree('c / (1 / (-a) * b), ((-a)c) / b')
+        self.assertEqual(fraction_in_division(root,
+            (False, Scope(root[1]), root[1][0])), expected)