test_rules_integrals.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from src.rules.integrals import choose_constant, \
  2. 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_integrate_variable_power(self):
  22. for root in tree('int x ^ n, int x ^ n'):
  23. self.assertEqualPos(match_integrate_variable_power(root),
  24. [P(root, integrate_variable_root)])
  25. for root in tree('int g ^ x, int g ^ x'):
  26. self.assertEqualPos(match_integrate_variable_power(root),
  27. [P(root, integrate_variable_exponent)])
  28. def test_integrate_variable_root(self):
  29. ((x, n), x), c = root, c = tree('int x ^ n, c')
  30. self.assertEqual(integrate_variable_root(root, ()),
  31. x ** (n + 1) / (n + 1) + c)
  32. def test_integrate_variable_exponent(self):
  33. ((g, x), x), c = root, c = tree('int g ^ x, c')
  34. self.assertEqual(integrate_variable_exponent(root, ()),
  35. g ** x / ln(g) + c)