m2m模型翻译
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.

27 lines
868 B

6 months ago
  1. from sympy.strategies.tools import subs, typed
  2. from sympy.strategies.rl import rm_id
  3. from sympy.core.basic import Basic
  4. from sympy.core.singleton import S
  5. def test_subs():
  6. from sympy.core.symbol import symbols
  7. a,b,c,d,e,f = symbols('a,b,c,d,e,f')
  8. mapping = {a: d, d: a, Basic(e): Basic(f)}
  9. expr = Basic(a, Basic(b, c), Basic(d, Basic(e)))
  10. result = Basic(d, Basic(b, c), Basic(a, Basic(f)))
  11. assert subs(mapping)(expr) == result
  12. def test_subs_empty():
  13. assert subs({})(Basic(S(1), S(2))) == Basic(S(1), S(2))
  14. def test_typed():
  15. class A(Basic):
  16. pass
  17. class B(Basic):
  18. pass
  19. rmzeros = rm_id(lambda x: x == S(0))
  20. rmones = rm_id(lambda x: x == S(1))
  21. remove_something = typed({A: rmzeros, B: rmones})
  22. assert remove_something(A(S(0), S(1))) == A(S(1))
  23. assert remove_something(B(S(0), S(1))) == B(S(0))