Răsfoiți Sursa

Merge branch 'master' of kompiler.org:trs

Taddeus Kroes 14 ani în urmă
părinte
comite
a290533edd
2 a modificat fișierele cu 19 adăugiri și 3 ștergeri
  1. 0 3
      src/rules/negation.py
  2. 19 0
      tests/test_leiden_oefenopgave.py

+ 0 - 3
src/rules/negation.py

@@ -63,13 +63,10 @@ def negate_group(root, args):
     """
     node, scope = args
 
-    print 'negate_group:', node, map(str, scope)
-
     # Negate each group
     for i, n in enumerate(scope):
         scope[i] = -n
 
-    print nary_node('+', scope)
     return nary_node('+', scope)
 
 

+ 19 - 0
tests/test_leiden_oefenopgave.py

@@ -86,6 +86,25 @@ class TestLeidenOefenopgave(TestCase):
         # FIXME: self.assertRewrite(['x * -1 + x * -1', '(-1 + -1)x', '-2x'])
         pass
 
+    def test_1_5(self):
+        self.assertRewrite(['(2x + x)x', '(2 + 1)xx', '3xx',
+                            '3 * x ^ (1 + 1)', '3 * x ^ 2'])
+
+    def test_1_7(self):
+        self.assertRewrite(['(4x + 5) * -(5 - 4x)',
+                            '(4x + 5)(-5 - -4x)',
+                            '(4x + 5)(-5 + 4x)',
+                            '4x * -5 + 4x * 4x + 5 * -5 + 5 * 4x',
+                            '-20x + 4x * 4x + 5 * -5 + 5 * 4x',
+                            '-20x + 16xx + 5 * -5 + 5 * 4x',
+                            '-20x + 16 * x ^ (1 + 1) + 5 * -5 + 5 * 4x',
+                            '-20x + 16 * x ^ 2 + 5 * -5 + 5 * 4x',
+                            '-20x + 16 * x ^ 2 - 25 + 5 * 4x',
+                            '-20x + 16 * x ^ 2 - 25 + 20x',
+                            '(-20 + 20)x + 16 * x ^ 2 - 25',
+                            '0x + 16 * x ^ 2 - 25',])
+                            # FIXME: '16x^2 - 25'])
+
     def test_2(self):
         pass