test_rules_integrals.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from src.rules.integrals import choose_constant, match_solve_indef, \
  2. solve_indef, match_integrate_variable_power, integrate_variable_root, \
  3. integrate_variable_exponent
  4. from src.rules.logarithmic import ln
  5. #from .goniometry import sin, cos
  6. from src.possibilities import Possibility as P
  7. from tests.rulestestcase import RulesTestCase, tree
  8. class TestRulesIntegrals(RulesTestCase):
  9. def test_choose_constant(self):
  10. a, b, c = tree('a, b, c')
  11. self.assertEqual(choose_constant(tree('int x ^ n')), c)
  12. self.assertEqual(choose_constant(tree('int x ^ c')), a)
  13. self.assertEqual(choose_constant(tree('int a ^ c da')), b)
  14. def test_match_solve_indef(self):
  15. root = tree('[x ^ 2]_a^b')
  16. self.assertEqualPos(match_solve_indef(root), [P(root, solve_indef)])
  17. def test_solve_indef(self):
  18. root, expect = tree('[x ^ 2]_a^b, b2 - a2')
  19. self.assertEqual(solve_indef(root, ()), expect)
  20. def test_match_integrate_variable_power(self):
  21. for root in tree('int x ^ n, int x ^ n'):
  22. self.assertEqualPos(match_integrate_variable_power(root),
  23. [P(root, integrate_variable_root)])
  24. for root in tree('int g ^ x, int g ^ x'):
  25. self.assertEqualPos(match_integrate_variable_power(root),
  26. [P(root, integrate_variable_exponent)])
  27. def test_integrate_variable_root(self):
  28. root, expect = tree('int x ^ n, x ^ (n + 1) / (n + 1) + c')
  29. self.assertEqual(integrate_variable_root(root, ()), expect)
  30. def test_integrate_variable_exponent(self):
  31. root, expect = tree('int g ^ x, g ^ x / ln(g) + c')
  32. self.assertEqual(integrate_variable_exponent(root, ()), expect)