test_physics.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # coding: utf-8
  2. import pytest
  3. from synergine2_xyz.physics import Matrixes
  4. from tests import BaseTest
  5. class TestVisibilityMatrix(BaseTest):
  6. def test_initialize_empty_matrix(self):
  7. visibility = Matrixes()
  8. visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2, value_structure=['opacity'])
  9. matrix = visibility.get_matrix('testing')
  10. assert isinstance(matrix, list)
  11. assert [(0.0,), (0.0,), (0.0,)] == matrix[0]
  12. assert [(0.0,), (0.0,), (0.0,)] == matrix[1]
  13. def test_update_matrix(self):
  14. visibility = Matrixes()
  15. visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2, value_structure=['opacity'])
  16. visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
  17. visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
  18. matrix = visibility.get_matrix('testing')
  19. assert [(0.7,), (0.0,), (0.0,)] == matrix[0]
  20. assert [(0.0,), (0.0,), (0.5,)] == matrix[1]
  21. def test_get_path_positions(self):
  22. visibility = Matrixes()
  23. visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2, value_structure=['opacity'])
  24. visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
  25. visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
  26. path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
  27. assert [(0, 0), (1, 0), (2, 1)] == path_positions
  28. def test_get_path_values(self):
  29. visibility = Matrixes()
  30. visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2, value_structure=['opacity'])
  31. visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
  32. visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
  33. path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
  34. path_values = visibility.get_values_for_path('testing', path_positions=path_positions)
  35. assert [(0.7,), (0.0,), (0.5,)] == path_values
  36. def test_get_path_value(self):
  37. visibility = Matrixes()
  38. visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2, value_structure=['opacity'])
  39. visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
  40. visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
  41. path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
  42. path_values = visibility.get_values_for_path('testing', path_positions=path_positions, value_name='opacity')
  43. assert [0.7, 0.0, 0.5] == path_values
  44. def test_get_value(self):
  45. visibility = Matrixes()
  46. visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2, value_structure=['opacity'])
  47. visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
  48. value = visibility.get_value('testing', x=2, y=1, value_name='opacity')
  49. assert 0.5 == value