test_equal.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from sympy.core.numbers import Rational
  2. from sympy.core.symbol import (Dummy, Symbol)
  3. from sympy.functions.elementary.exponential import exp
  4. def test_equal():
  5. b = Symbol("b")
  6. a = Symbol("a")
  7. e1 = a + b
  8. e2 = 2*a*b
  9. e3 = a**3*b**2
  10. e4 = a*b + b*a
  11. assert not e1 == e2
  12. assert not e1 == e2
  13. assert e1 != e2
  14. assert e2 == e4
  15. assert e2 != e3
  16. assert not e2 == e3
  17. x = Symbol("x")
  18. e1 = exp(x + 1/x)
  19. y = Symbol("x")
  20. e2 = exp(y + 1/y)
  21. assert e1 == e2
  22. assert not e1 != e2
  23. y = Symbol("y")
  24. e2 = exp(y + 1/y)
  25. assert not e1 == e2
  26. assert e1 != e2
  27. e5 = Rational(3) + 2*x - x - x
  28. assert e5 == 3
  29. assert 3 == e5
  30. assert e5 != 4
  31. assert 4 != e5
  32. assert e5 != 3 + x
  33. assert 3 + x != e5
  34. def test_expevalbug():
  35. x = Symbol("x")
  36. e1 = exp(1*x)
  37. e3 = exp(x)
  38. assert e1 == e3
  39. def test_cmp_bug1():
  40. class T:
  41. pass
  42. t = T()
  43. x = Symbol("x")
  44. assert not (x == t)
  45. assert (x != t)
  46. def test_cmp_bug2():
  47. class T:
  48. pass
  49. t = T()
  50. assert not (Symbol == t)
  51. assert (Symbol != t)
  52. def test_cmp_issue_4357():
  53. """ Check that Basic subclasses can be compared with sympifiable objects.
  54. https://github.com/sympy/sympy/issues/4357
  55. """
  56. assert not (Symbol == 1)
  57. assert (Symbol != 1)
  58. assert not (Symbol == 'x')
  59. assert (Symbol != 'x')
  60. def test_dummy_eq():
  61. x = Symbol('x')
  62. y = Symbol('y')
  63. u = Dummy('u')
  64. assert (u**2 + 1).dummy_eq(x**2 + 1) is True
  65. assert ((u**2 + 1) == (x**2 + 1)) is False
  66. assert (u**2 + y).dummy_eq(x**2 + y, x) is True
  67. assert (u**2 + y).dummy_eq(x**2 + y, y) is False