test_line_segment.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # freesurfer-surface - Read and Write Surface Files in Freesurfer’s TriangularSurface Format
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import pytest
  18. from freesurfer_surface import LineSegment
  19. def test_init_fail():
  20. with pytest.raises(Exception):
  21. LineSegment((1, 2, 3))
  22. def test_eq():
  23. assert LineSegment((67018, 67019)) == LineSegment((67018, 67019))
  24. assert LineSegment((67018, 67019)) == LineSegment((67019, 67018))
  25. assert LineSegment((67019, 67018)) == LineSegment((67018, 67019))
  26. def test_repr():
  27. assert (
  28. repr(LineSegment((67018, 67019)))
  29. == "LineSegment(vertex_indices=(67018, 67019))"
  30. )
  31. def test_adjacent_vertex_indices_1():
  32. chain = LineSegment((1, 4))
  33. singles = list(chain.adjacent_vertex_indices(1))
  34. assert len(singles) == 2
  35. assert singles[0] == (1,)
  36. assert singles[1] == (4,)
  37. def test_adjacent_vertex_indices_2():
  38. chain = LineSegment((1, 4))
  39. pairs = list(chain.adjacent_vertex_indices(2))
  40. assert len(pairs) == 2
  41. assert pairs[0] == (1, 4)
  42. assert pairs[1] == (4, 1)
  43. def test_adjacent_vertex_indices_3():
  44. chain = LineSegment((1, 4))
  45. triplets = list(chain.adjacent_vertex_indices(3))
  46. assert len(triplets) == 2
  47. assert triplets[0] == (1, 4, 1)
  48. assert triplets[1] == (4, 1, 4)