Quellcode durchsuchen

Added a unit test that mysteriously failes validation...

Taddeus Kroes vor 13 Jahren
Ursprung
Commit
8f84aef468
2 geänderte Dateien mit 12 neuen und 2 gelöschten Zeilen
  1. 8 2
      src/validation.py
  2. 4 0
      tests/test_validation.py

+ 8 - 2
src/validation.py

@@ -32,21 +32,27 @@ def validate(exp, result):
     parser.set_root_node(exp)
     a = parser.rewrite_all()
 
+    if not a:
+        return False
+
     parser.set_root_node(result)
     b = parser.rewrite_all()
 
-    if not a or not a.equals(b):
+    if not a.equals(b):
         return False
 
     # TODO: make sure cycles are avoided / eliminated using cycle detection.
     def traverse_preorder(node, result):
+        #print 'node:', node, 'result:', result
         if node.equals(result):
             return True
 
         for p in find_possibilities(node):
             # Clone the root node because it will be used in multiple
             # substitutions
-            child = apply_suggestion(node.clone(), p)
+            temp = node.clone()
+            child = apply_suggestion(node, p)
+            node = temp
 
             if traverse_preorder(child, result):
                 return True

+ 4 - 0
tests/test_validation.py

@@ -31,6 +31,10 @@ class TestValidation(TestCase):
     def test_intermediate_failure(self):
         self.assertFalse(validate('3a + a + b + 2b', '4a + 4b'))
 
+    #def test_success(self):
+    #    self.assertTrue(validate('x^2 + x - 2x^2 + 3x + 1',
+    #                             'x^2 + 4x - 2x^2 + 1'))
+
     #def test_indefinite_integral(self):
     #    self.assertTrue(validate('int_2^4 x^2', '4^3/3 - 2^3/3'))