Procházet zdrojové kódy

Added some messages and comments to negation rules.

Taddeus Kroes před 14 roky
rodič
revize
9419b2b185
2 změnil soubory, kde provedl 14 přidání a 3 odebrání
  1. 10 3
      src/rules/negation.py
  2. 4 0
      tests/test_rules_negation.py

+ 10 - 3
src/rules/negation.py

@@ -16,6 +16,9 @@ def match_negated_factor(node):
     p = []
     scope = Scope(node)
 
+    # FIXME: The negation that is brought outside is assigned to the first
+    # element in the scope during the next parsing step:
+    # -ab -> -(ab), but -(ab) is printed as -ab
     for factor in scope:
         if factor.negated:
             p.append(P(node, negated_factor, (scope, factor)))
@@ -33,6 +36,10 @@ def negated_factor(root, args):
     return -scope.as_nary_node()
 
 
+MESSAGES[negated_factor] = \
+        _('Bring negation of {2} to the outside of the multiplication.')
+
+
 def match_negate_polynome(node):
     """
     --a       ->  a
@@ -60,7 +67,7 @@ def double_negation(root, args):
     return root.reduce_negation(2)
 
 
-MESSAGES[double_negation] = _('Remove double negation in {1}.')
+MESSAGES[double_negation] = _('Remove double negation in {0}.')
 
 
 def negate_polynome(root, args):
@@ -76,7 +83,7 @@ def negate_polynome(root, args):
     return +scope.as_nary_node()
 
 
-MESSAGES[negate_polynome] = _('Apply negation to the polynome {1}.')
+MESSAGES[negate_polynome] = _('Apply negation to the polynome {0}.')
 
 
 #def negate_group(root, args):
@@ -140,7 +147,7 @@ def double_negated_division(root, args):
 
 
 MESSAGES[double_negated_division] = \
-        _('Eliminate top and bottom negation in {1}.')
+        _('Eliminate top and bottom negation in {0}.')
 
 
 # TODO: negated multiplication: -a * -b = ab

+ 4 - 0
tests/test_rules_negation.py

@@ -46,6 +46,10 @@ class TestRulesNegation(RulesTestCase):
                 [P(root, double_negation, (b,)),
                  P(root, negate_polynome, ())])
 
+    def test_double_negation(self):
+        root = tree('--a')
+        self.assertEqualNodes(double_negation(root, ()), ++root)
+
     def test_negate_polynome(self):
         a, b = root = tree('-(a + b)')
         self.assertEqualNodes(negate_polynome(root, ()), -a + -b)