test_function.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """ Unit tests for Hyper_Function"""
  2. from sympy.core import symbols, Dummy, Tuple, S, Rational
  3. from sympy.functions import hyper
  4. from sympy.simplify.hyperexpand import Hyper_Function
  5. def test_attrs():
  6. a, b = symbols('a, b', cls=Dummy)
  7. f = Hyper_Function([2, a], [b])
  8. assert f.ap == Tuple(2, a)
  9. assert f.bq == Tuple(b)
  10. assert f.args == (Tuple(2, a), Tuple(b))
  11. assert f.sizes == (2, 1)
  12. def test_call():
  13. a, b, x = symbols('a, b, x', cls=Dummy)
  14. f = Hyper_Function([2, a], [b])
  15. assert f(x) == hyper([2, a], [b], x)
  16. def test_has():
  17. a, b, c = symbols('a, b, c', cls=Dummy)
  18. f = Hyper_Function([2, -a], [b])
  19. assert f.has(a)
  20. assert f.has(Tuple(b))
  21. assert not f.has(c)
  22. def test_eq():
  23. assert Hyper_Function([1], []) == Hyper_Function([1], [])
  24. assert (Hyper_Function([1], []) != Hyper_Function([1], [])) is False
  25. assert Hyper_Function([1], []) != Hyper_Function([2], [])
  26. assert Hyper_Function([1], []) != Hyper_Function([1, 2], [])
  27. assert Hyper_Function([1], []) != Hyper_Function([1], [2])
  28. def test_gamma():
  29. assert Hyper_Function([2, 3], [-1]).gamma == 0
  30. assert Hyper_Function([-2, -3], [-1]).gamma == 2
  31. n = Dummy(integer=True)
  32. assert Hyper_Function([-1, n, 1], []).gamma == 1
  33. assert Hyper_Function([-1, -n, 1], []).gamma == 1
  34. p = Dummy(integer=True, positive=True)
  35. assert Hyper_Function([-1, p, 1], []).gamma == 1
  36. assert Hyper_Function([-1, -p, 1], []).gamma == 2
  37. def test_suitable_origin():
  38. assert Hyper_Function((S.Half,), (Rational(3, 2),))._is_suitable_origin() is True
  39. assert Hyper_Function((S.Half,), (S.Half,))._is_suitable_origin() is False
  40. assert Hyper_Function((S.Half,), (Rational(-1, 2),))._is_suitable_origin() is False
  41. assert Hyper_Function((S.Half,), (0,))._is_suitable_origin() is False
  42. assert Hyper_Function((S.Half,), (-1, 1,))._is_suitable_origin() is False
  43. assert Hyper_Function((S.Half, 0), (1,))._is_suitable_origin() is False
  44. assert Hyper_Function((S.Half, 1),
  45. (2, Rational(-2, 3)))._is_suitable_origin() is True
  46. assert Hyper_Function((S.Half, 1),
  47. (2, Rational(-2, 3), Rational(3, 2)))._is_suitable_origin() is True