test_polygonal_circuit.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import pytest
  2. from freesurfer_surface import _PolygonalCircuit
  3. @pytest.mark.parametrize(('source_vertex_indices', 'expected_vertex_indices'), [
  4. ((1,), (1,)),
  5. ((1, 2), (1, 2)),
  6. ((2, 1), (1, 2)),
  7. ((1, 2, 3), (1, 2, 3)),
  8. ((2, 3, 1), (1, 2, 3)),
  9. ((3, 1, 2), (1, 2, 3)),
  10. ((1, 3, 2), (1, 2, 3)),
  11. ((2, 1, 3), (1, 2, 3)),
  12. ((3, 2, 1), (1, 2, 3)),
  13. ((1, 2, 3, 5), (1, 2, 3, 5)),
  14. ((2, 3, 5, 1), (1, 2, 3, 5)),
  15. ((3, 5, 1, 2), (1, 2, 3, 5)),
  16. ((2, 1, 5, 3), (1, 2, 3, 5)),
  17. ((5, 3, 2, 1), (1, 2, 3, 5)),
  18. ])
  19. def test__normalize(source_vertex_indices, expected_vertex_indices):
  20. # pylint: disable=protected-access
  21. circuit = _PolygonalCircuit(source_vertex_indices)
  22. assert expected_vertex_indices == circuit._normalize()._vertex_indices
  23. def test_eq():
  24. assert _PolygonalCircuit((0, 1)) == _PolygonalCircuit((0, 1))
  25. assert _PolygonalCircuit((0, 1)) == _PolygonalCircuit((1, 0))
  26. assert _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((0, 1, 2))
  27. assert _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((1, 2, 0))
  28. assert _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((2, 0, 1))
  29. # pylint: disable=unneeded-not
  30. assert not _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((0, 1, 4))
  31. assert not _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((0, 4, 2))
  32. assert not _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((4, 1, 2))
  33. def test_eq_reverse():
  34. assert _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((2, 1, 0))
  35. assert _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((0, 2, 1))
  36. assert _PolygonalCircuit((0, 1, 2, 4)) == _PolygonalCircuit((4, 2, 1, 0))
  37. assert _PolygonalCircuit((0, 1, 2, 4)) == _PolygonalCircuit((1, 0, 4, 2))
  38. def test_hash():
  39. assert hash(_PolygonalCircuit((0, 1, 2))) \
  40. == hash(_PolygonalCircuit((0, 1, 2)))
  41. assert hash(_PolygonalCircuit((0, 1, 2))) \
  42. == hash(_PolygonalCircuit((1, 2, 0)))
  43. assert hash(_PolygonalCircuit((0, 1, 2))) \
  44. == hash(_PolygonalCircuit((2, 0, 1)))
  45. assert hash(_PolygonalCircuit((0, 1, 2))) \
  46. != hash(_PolygonalCircuit((0, 1, 4)))
  47. assert hash(_PolygonalCircuit((0, 1, 2))) \
  48. != hash(_PolygonalCircuit((0, 4, 2)))
  49. assert hash(_PolygonalCircuit((0, 1, 2))) \
  50. != hash(_PolygonalCircuit((4, 1, 2)))
  51. def test_hash_reverse():
  52. assert hash(_PolygonalCircuit((0, 1, 2))) \
  53. == hash(_PolygonalCircuit((2, 1, 0)))
  54. assert hash(_PolygonalCircuit((0, 1, 2))) \
  55. == hash(_PolygonalCircuit((0, 2, 1)))
  56. assert hash(_PolygonalCircuit((0, 1, 2, 4))) \
  57. == hash(_PolygonalCircuit((4, 2, 1, 0)))
  58. assert hash(_PolygonalCircuit((0, 1, 2, 4))) \
  59. == hash(_PolygonalCircuit((1, 0, 4, 2)))
  60. assert hash(_PolygonalCircuit((0, 1, 2, 4))) \
  61. != hash(_PolygonalCircuit((1, 4, 0, 2)))