test_hypothesis.py 728 B

123456789101112131415161718192021222324
  1. from hypothesis import given
  2. from hypothesis import strategies as st
  3. from sympy import divisors
  4. from sympy.functions.combinatorial.numbers import divisor_sigma, totient
  5. from sympy.ntheory.primetest import is_square
  6. @given(n=st.integers(1, 10**10))
  7. def test_tau_hypothesis(n):
  8. div = divisors(n)
  9. tau_n = len(div)
  10. assert is_square(n) == (tau_n % 2 == 1)
  11. sigmas = [divisor_sigma(i) for i in div]
  12. totients = [totient(n // i) for i in div]
  13. mul = [a * b for a, b in zip(sigmas, totients)]
  14. assert n * tau_n == sum(mul)
  15. @given(n=st.integers(1, 10**10))
  16. def test_totient_hypothesis(n):
  17. assert totient(n) <= n
  18. div = divisors(n)
  19. totients = [totient(i) for i in div]
  20. assert n == sum(totients)