test_lmatrix3.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import pytest
  2. from copy import copy
  3. from panda3d import core
  4. def test_mat3_aliases():
  5. assert core.LMatrix3 is core.Mat3
  6. assert core.LMatrix3f is core.Mat3F
  7. assert core.LMatrix3d is core.Mat3D
  8. assert (core.LMatrix3f is core.Mat3) != (core.LMatrix3d is core.Mat3)
  9. @pytest.mark.parametrize("type", (core.LMatrix3f, core.LMatrix3d))
  10. def test_mat3_constructor(type):
  11. # Test that three ways of construction produce the same matrix.
  12. mat1 = type((1, 2, 3),
  13. (4, 5, 6),
  14. (7, 8, 9))
  15. mat2 = type(1, 2, 3, 4, 5, 6, 7, 8, 9)
  16. mat3 = type((1, 2, 3, 4, 5, 6, 7, 8, 9))
  17. assert mat1 == mat2
  18. assert mat2 == mat3
  19. assert mat1 == mat3
  20. @pytest.mark.parametrize("type", (core.LMatrix3d, core.LMatrix3f))
  21. def test_mat3_copy_constuctor(type):
  22. mat1 = type((1, 2, 3),
  23. (4, 5, 6),
  24. (7, 8, 9))
  25. # Make a copy. Changing it should not change the original.
  26. mat2 = type(mat1)
  27. assert mat1 == mat2
  28. mat2[0][0] = 100
  29. assert mat1 != mat2
  30. # Make a copy by unpacking.
  31. mat2 = type(*mat1)
  32. assert mat1 == mat2
  33. mat2[0][0] = 100
  34. assert mat1 != mat2
  35. # Make a copy by calling copy.copy.
  36. mat2 = copy(mat1)
  37. assert mat1 == mat2
  38. mat2[0][0] = 100
  39. assert mat1 != mat2
  40. @pytest.mark.parametrize("type", (core.LMatrix3d, core.LMatrix3f))
  41. def test_mat3_invert_same_type(type):
  42. mat = type((1, 0, 0,
  43. 0, 1, 0,
  44. 1, 2, 3))
  45. inv = core.invert(mat)
  46. assert mat.__class__ == inv.__class__