test_triangle.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Triangle
  19. def test_init():
  20. triangle = Triangle((0, 21, 42))
  21. assert triangle.vertex_indices == (0, 21, 42)
  22. def test_init_invalid_indices_len():
  23. with pytest.raises(Exception):
  24. Triangle((0, 21, 42, 84))
  25. def test_eq():
  26. assert Triangle((0, 1, 2)) == Triangle((0, 1, 2))
  27. assert Triangle((0, 1, 2)) == Triangle((1, 2, 0))
  28. # pylint: disable=unneeded-not
  29. assert not Triangle((0, 1, 2)) == Triangle((0, 1, 4))
  30. assert not Triangle((0, 1, 2)) == Triangle((0, 4, 2))
  31. assert not Triangle((0, 1, 2)) == Triangle((4, 1, 2))
  32. def test_repr():
  33. assert repr(Triangle((0, 1, 2))) == "Triangle(vertex_indices=(0, 1, 2))"
  34. def test_adjacent_vertex_indices_1():
  35. chain = Triangle((1, 4, 8))
  36. singles = list(chain.adjacent_vertex_indices(1))
  37. assert len(singles) == 3
  38. assert singles[0] == (1,)
  39. assert singles[1] == (4,)
  40. assert singles[2] == (8,)
  41. def test_adjacent_vertex_indices_2():
  42. chain = Triangle((1, 4, 8))
  43. pairs = list(chain.adjacent_vertex_indices(2))
  44. assert len(pairs) == 3
  45. assert pairs[0] == (1, 4)
  46. assert pairs[1] == (4, 8)
  47. assert pairs[2] == (8, 1)
  48. def test_adjacent_vertex_indices_3():
  49. chain = Triangle((1, 4, 8))
  50. triplets = list(chain.adjacent_vertex_indices(3))
  51. assert len(triplets) == 3
  52. assert triplets[0] == (1, 4, 8)
  53. assert triplets[1] == (4, 8, 1)
  54. assert triplets[2] == (8, 1, 4)
  55. def test_adjacent_vertex_indices_4():
  56. chain = Triangle((1, 4, 8))
  57. quadruples = list(chain.adjacent_vertex_indices(4))
  58. assert len(quadruples) == 3
  59. assert quadruples[0] == (1, 4, 8, 1)
  60. assert quadruples[1] == (4, 8, 1, 4)
  61. assert quadruples[2] == (8, 1, 4, 8)
  62. def test_adjacent_vertex_indices_5():
  63. chain = Triangle((1, 4, 8))
  64. quintuples = list(chain.adjacent_vertex_indices(5))
  65. assert len(quintuples) == 3
  66. assert quintuples[0] == (1, 4, 8, 1, 4)
  67. assert quintuples[1] == (4, 8, 1, 4, 8)
  68. assert quintuples[2] == (8, 1, 4, 8, 1)