test_tools.py 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from sympy.strategies.branch.tools import canon
  2. from sympy.core.basic import Basic
  3. from sympy.core.numbers import Integer
  4. from sympy.core.singleton import S
  5. def posdec(x):
  6. if isinstance(x, Integer) and x > 0:
  7. yield x - 1
  8. else:
  9. yield x
  10. def branch5(x):
  11. if isinstance(x, Integer):
  12. if 0 < x < 5:
  13. yield x - 1
  14. elif 5 < x < 10:
  15. yield x + 1
  16. elif x == 5:
  17. yield x + 1
  18. yield x - 1
  19. else:
  20. yield x
  21. def test_zero_ints():
  22. expr = Basic(S(2), Basic(S(5), S(3)), S(8))
  23. expected = {Basic(S(0), Basic(S(0), S(0)), S(0))}
  24. brl = canon(posdec)
  25. assert set(brl(expr)) == expected
  26. def test_split5():
  27. expr = Basic(S(2), Basic(S(5), S(3)), S(8))
  28. expected = {
  29. Basic(S(0), Basic(S(0), S(0)), S(10)),
  30. Basic(S(0), Basic(S(10), S(0)), S(10))}
  31. brl = canon(branch5)
  32. assert set(brl(expr)) == expected