Jelajahi Sumber

Added test for maximum code coverage in powers rules.

Taddeus Kroes 14 tahun lalu
induk
melakukan
17d69216b5
2 mengubah file dengan 9 tambahan dan 1 penghapusan
  1. 1 1
      src/rules/powers.py
  2. 8 0
      tests/test_rules_powers.py

+ 1 - 1
src/rules/powers.py

@@ -27,7 +27,7 @@ def match_add_exponents(node):
             # Order powers by their roots, e.g. a^p and a^q are put in the same
             # list because of the mutual 'a'
             s, exponent = n
-        else:
+        else:  # pragma: nocover
             continue
 
         s_str = str(s)

+ 8 - 0
tests/test_rules_powers.py

@@ -39,6 +39,14 @@ class TestRulesPowers(RulesTestCase):
                 [P(root, add_exponents, (Scope(root), a0, a1, a, p, q)),
                  P(root, add_exponents, (Scope(root), b0, b1, b, p, q))])
 
+    def test_match_add_exponents_nary_multiplication(self):
+        a, p, q = tree('a,p,q')
+        (n0, l1), n1 = root = a ** p * 2 * a ** q
+
+        possibilities = match_add_exponents(root)
+        self.assertEqualPos(possibilities,
+                [P(root, add_exponents, (Scope(root), n0, n1, a, p, q))])
+
     def test_match_subtract_exponents_powers(self):
         a, p, q = tree('a,p,q')
         root = a ** p / a ** q