test_rules_integrals.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_integral_params(self):
  10. # f, x = root = tree('int fx dx')
  11. # self.assertEqual(integral_params(root), (f, x))
  12. # root = tree('int fx')
  13. # self.assertEqual(integral_params(root), (f, x))
  14. # root = tree('int 3')
  15. # self.assertEqual(integral_params(root), (3, x))
  16. def test_choose_constant(self):
  17. a, b, c = tree('a, b, c')
  18. self.assertEqual(choose_constant(tree('int x ^ n')), c)
  19. self.assertEqual(choose_constant(tree('int x ^ c')), a)
  20. self.assertEqual(choose_constant(tree('int a ^ c da')), b)
  21. def test_match_solve_indef(self):
  22. root = tree('[x ^ 2]_a^b')
  23. self.assertEqualPos(match_solve_indef(root), [P(root, solve_indef)])
  24. def test_solve_indef(self):
  25. root, expect = tree('[x ^ 2]_a^b, b2 - a2')
  26. self.assertEqual(solve_indef(root, ()), expect)
  27. def test_match_integrate_variable_power(self):
  28. for root in tree('int x ^ n, int x ^ n'):
  29. self.assertEqualPos(match_integrate_variable_power(root),
  30. [P(root, integrate_variable_root)])
  31. for root in tree('int g ^ x, int g ^ x'):
  32. self.assertEqualPos(match_integrate_variable_power(root),
  33. [P(root, integrate_variable_exponent)])
  34. def test_integrate_variable_root(self):
  35. root, expect = tree('int x ^ n, x ^ (n + 1) / (n + 1) + c')
  36. self.assertEqual(integrate_variable_root(root, ()), expect)
  37. def test_integrate_variable_exponent(self):
  38. root, expect = tree('int g ^ x, g ^ x / ln(g) + c')
  39. self.assertEqual(integrate_variable_exponent(root, ()), expect)