test_dimensionsystem.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from sympy.core.symbol import symbols
  2. from sympy.matrices.dense import (Matrix, eye)
  3. from sympy.physics.units.definitions.dimension_definitions import (
  4. action, current, length, mass, time,
  5. velocity)
  6. from sympy.physics.units.dimensions import DimensionSystem
  7. def test_extend():
  8. ms = DimensionSystem((length, time), (velocity,))
  9. mks = ms.extend((mass,), (action,))
  10. res = DimensionSystem((length, time, mass), (velocity, action))
  11. assert mks.base_dims == res.base_dims
  12. assert mks.derived_dims == res.derived_dims
  13. def test_list_dims():
  14. dimsys = DimensionSystem((length, time, mass))
  15. assert dimsys.list_can_dims == (length, mass, time)
  16. def test_dim_can_vector():
  17. dimsys = DimensionSystem(
  18. [length, mass, time],
  19. [velocity, action],
  20. {
  21. velocity: {length: 1, time: -1}
  22. }
  23. )
  24. assert dimsys.dim_can_vector(length) == Matrix([1, 0, 0])
  25. assert dimsys.dim_can_vector(velocity) == Matrix([1, 0, -1])
  26. dimsys = DimensionSystem(
  27. (length, velocity, action),
  28. (mass, time),
  29. {
  30. time: {length: 1, velocity: -1}
  31. }
  32. )
  33. assert dimsys.dim_can_vector(length) == Matrix([0, 1, 0])
  34. assert dimsys.dim_can_vector(velocity) == Matrix([0, 0, 1])
  35. assert dimsys.dim_can_vector(time) == Matrix([0, 1, -1])
  36. dimsys = DimensionSystem(
  37. (length, mass, time),
  38. (velocity, action),
  39. {velocity: {length: 1, time: -1},
  40. action: {mass: 1, length: 2, time: -1}})
  41. assert dimsys.dim_vector(length) == Matrix([1, 0, 0])
  42. assert dimsys.dim_vector(velocity) == Matrix([1, 0, -1])
  43. def test_inv_can_transf_matrix():
  44. dimsys = DimensionSystem((length, mass, time))
  45. assert dimsys.inv_can_transf_matrix == eye(3)
  46. def test_can_transf_matrix():
  47. dimsys = DimensionSystem((length, mass, time))
  48. assert dimsys.can_transf_matrix == eye(3)
  49. dimsys = DimensionSystem((length, velocity, action))
  50. assert dimsys.can_transf_matrix == eye(3)
  51. dimsys = DimensionSystem((length, time), (velocity,), {velocity: {length: 1, time: -1}})
  52. assert dimsys.can_transf_matrix == eye(2)
  53. def test_is_consistent():
  54. assert DimensionSystem((length, time)).is_consistent is True
  55. def test_print_dim_base():
  56. mksa = DimensionSystem(
  57. (length, time, mass, current),
  58. (action,),
  59. {action: {mass: 1, length: 2, time: -1}})
  60. L, M, T = symbols("L M T")
  61. assert mksa.print_dim_base(action) == L**2*M/T
  62. def test_dim():
  63. dimsys = DimensionSystem(
  64. (length, mass, time),
  65. (velocity, action),
  66. {velocity: {length: 1, time: -1},
  67. action: {mass: 1, length: 2, time: -1}}
  68. )
  69. assert dimsys.dim == 3