Selaa lähdekoodia

Added unit testss for integral helper function.

Taddeus Kroes 14 vuotta sitten
vanhempi
sitoutus
0d3981fd8b
2 muutettua tiedostoa jossa 17 lisäystä ja 4 poistoa
  1. 1 1
      src/rules/integrals.py
  2. 16 3
      tests/test_rules_integrals.py

+ 1 - 1
src/rules/integrals.py

@@ -56,7 +56,7 @@ def solve_integral(integral, F):
     x, lbnd, ubnd = integral[1:4]
 
     if x != find_variable(F):
-        return replace_variable(F, x, b) - replace_variable(F, x, a)
+        return replace_variable(F, x, ubnd) - replace_variable(F, x, lbnd)
 
     return indef(F, lbnd, ubnd)
 

+ 16 - 3
tests/test_rules_integrals.py

@@ -1,6 +1,6 @@
-from src.rules.integrals import choose_constant, match_solve_indef, \
-        solve_indef, match_integrate_variable_power, integrate_variable_root, \
-        integrate_variable_exponent
+from src.rules.integrals import indef, choose_constant, solve_integral, \
+        match_solve_indef, solve_indef, match_integrate_variable_power, \
+        integrate_variable_root, integrate_variable_exponent
 from src.rules.logarithmic import ln
 #from .goniometry import sin, cos
 from src.possibilities import Possibility as P
@@ -19,6 +19,19 @@ class TestRulesIntegrals(RulesTestCase):
         root = tree('[x ^ 2]_a^b')
         self.assertEqualPos(match_solve_indef(root), [P(root, solve_indef)])
 
+    def test_solve_integral(self):
+        root, F, Fc = tree('int x ^ 2 dx, 1 / 3 x ^ 3, 1 / 3 x ^ 3 + c')
+        self.assertEqual(solve_integral(root, F), Fc)
+        x2, x, a, b = root = tree('int_a^b x ^ 2 dx')
+        self.assertEqual(solve_integral(root, F), indef(Fc, a, b))
+
+    def test_solve_integral_skip_indef(self):
+        root, x, c, l1 = tree('int_a^b y ^ x dy, x, c, 1')
+        F = tree('1 / (x + 1)y ^ (x + 1)')
+        y, a, b = root[1:4]
+        Fx = lambda y: l1 / (x + 1) * y ** (x + 1) + c
+        self.assertEqual(solve_integral(root, F), Fx(b) - Fx(a))
+
     def test_solve_indef(self):
         root, expect = tree('[x ^ 2]_a^b, b2 - a2')
         self.assertEqual(solve_indef(root, ()), expect)