图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

  1. from sympy.core.expr import unchanged
  2. from sympy.core.numbers import oo
  3. from sympy.core.relational import Eq
  4. from sympy.core.singleton import S
  5. from sympy.core.symbol import Symbol
  6. from sympy.sets.contains import Contains
  7. from sympy.sets.sets import (FiniteSet, Interval)
  8. from sympy.testing.pytest import raises
  9. def test_contains_basic():
  10. raises(TypeError, lambda: Contains(S.Integers, 1))
  11. assert Contains(2, S.Integers) is S.true
  12. assert Contains(-2, S.Naturals) is S.false
  13. i = Symbol('i', integer=True)
  14. assert Contains(i, S.Naturals) == Contains(i, S.Naturals, evaluate=False)
  15. def test_issue_6194():
  16. x = Symbol('x')
  17. assert unchanged(Contains, x, Interval(0, 1))
  18. assert Interval(0, 1).contains(x) == (S.Zero <= x) & (x <= 1)
  19. assert Contains(x, FiniteSet(0)) != S.false
  20. assert Contains(x, Interval(1, 1)) != S.false
  21. assert Contains(x, S.Integers) != S.false
  22. def test_issue_10326():
  23. assert Contains(oo, Interval(-oo, oo)) == False
  24. assert Contains(-oo, Interval(-oo, oo)) == False
  25. def test_binary_symbols():
  26. x = Symbol('x')
  27. y = Symbol('y')
  28. z = Symbol('z')
  29. assert Contains(x, FiniteSet(y, Eq(z, True))
  30. ).binary_symbols == {y, z}
  31. def test_as_set():
  32. x = Symbol('x')
  33. y = Symbol('y')
  34. # Contains is a BooleanFunction whose value depends on an arg's
  35. # containment in a Set -- rewriting as a Set is not yet implemented
  36. raises(NotImplementedError, lambda:
  37. Contains(x, FiniteSet(y)).as_set())
  38. def test_type_error():
  39. # Pass in a parameter not of type "set"
  40. raises(TypeError, lambda: Contains(2, None))