Przeglądaj źródła

Some code coverage fixes.

Taddeus Kroes 14 lat temu
rodzic
commit
bd6d26a6a0
2 zmienionych plików z 20 dodań i 16 usunięć
  1. 6 9
      src/rules/derivatives.py
  2. 14 7
      tests/test_rules_integrals.py

+ 6 - 9
src/rules/derivatives.py

@@ -155,22 +155,19 @@ def match_variable_power(node):
     evars = find_variables(exponent)
     x = get_derivation_variable(node, rvars | evars)
 
-    if x in rvars and x in evars:
-        return [P(node, power_rule)]
-
     if x in rvars:
+        if x in evars:
+            return [P(node, power_rule)]
+
         if root.is_variable():
             return [P(node, variable_root)]
 
         return [P(node, chain_rule, (root, variable_root, ()))]
 
-    if x in evars:
-        if exponent.is_variable():
-            return [P(node, variable_exponent)]
+    if exponent.is_variable():
+        return [P(node, variable_exponent)]
 
-        return [P(node, chain_rule, (exponent, variable_exponent, ()))]
-
-    return []
+    return [P(node, chain_rule, (exponent, variable_exponent, ()))]
 
 
 def power_rule(root, args):

+ 14 - 7
tests/test_rules_integrals.py

@@ -132,13 +132,20 @@ class TestRulesIntegrals(RulesTestCase):
         ])
 
     def test_match_function_integral(self):
-        root0, root1, root2 = tree('int ln x, int sin x, int cos x')
-        self.assertEqualPos(match_function_integral(root0),
-                [P(root0, logarithm_integral)])
-        self.assertEqualPos(match_function_integral(root1),
-                [P(root1, sinus_integral)])
-        self.assertEqualPos(match_function_integral(root2),
-                [P(root2, cosinus_integral)])
+        root = tree('int ln x')
+        self.assertEqualPos(match_function_integral(root),
+                [P(root, logarithm_integral)])
+
+        root = tree('int sin x')
+        self.assertEqualPos(match_function_integral(root),
+                [P(root, sinus_integral)])
+
+        root = tree('int cos x')
+        self.assertEqualPos(match_function_integral(root),
+                [P(root, cosinus_integral)])
+
+        root = tree('int sqrt x')
+        self.assertEqualPos(match_function_integral(root), [])
 
     def test_logarithm_integral(self):
         root, expect = tree('int ln x, (xlnx - x) / ln e + c')