test_triangle.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import pytest
  2. from freesurfer_surface import Triangle
  3. def test_init():
  4. triangle = Triangle((0, 21, 42))
  5. assert triangle.vertex_indices == (0, 21, 42)
  6. def test_init_invalid_indices_len():
  7. with pytest.raises(Exception):
  8. Triangle((0, 21, 42, 84))
  9. def test_eq():
  10. assert Triangle((0, 1, 2)) == Triangle((0, 1, 2))
  11. assert Triangle((0, 1, 2)) == Triangle((1, 2, 0))
  12. # pylint: disable=unneeded-not
  13. assert not Triangle((0, 1, 2)) == Triangle((0, 1, 4))
  14. assert not Triangle((0, 1, 2)) == Triangle((0, 4, 2))
  15. assert not Triangle((0, 1, 2)) == Triangle((4, 1, 2))
  16. def test_repr():
  17. assert repr(Triangle((0, 1, 2))) == "Triangle(vertex_indices=(0, 1, 2))"
  18. def test_adjacent_vertex_indices_1():
  19. chain = Triangle((1, 4, 8))
  20. singles = list(chain.adjacent_vertex_indices(1))
  21. assert len(singles) == 3
  22. assert singles[0] == (1,)
  23. assert singles[1] == (4,)
  24. assert singles[2] == (8,)
  25. def test_adjacent_vertex_indices_2():
  26. chain = Triangle((1, 4, 8))
  27. pairs = list(chain.adjacent_vertex_indices(2))
  28. assert len(pairs) == 3
  29. assert pairs[0] == (1, 4)
  30. assert pairs[1] == (4, 8)
  31. assert pairs[2] == (8, 1)
  32. def test_adjacent_vertex_indices_3():
  33. chain = Triangle((1, 4, 8))
  34. triplets = list(chain.adjacent_vertex_indices(3))
  35. assert len(triplets) == 3
  36. assert triplets[0] == (1, 4, 8)
  37. assert triplets[1] == (4, 8, 1)
  38. assert triplets[2] == (8, 1, 4)
  39. def test_adjacent_vertex_indices_4():
  40. chain = Triangle((1, 4, 8))
  41. quadruples = list(chain.adjacent_vertex_indices(4))
  42. assert len(quadruples) == 3
  43. assert quadruples[0] == (1, 4, 8, 1)
  44. assert quadruples[1] == (4, 8, 1, 4)
  45. assert quadruples[2] == (8, 1, 4, 8)
  46. def test_adjacent_vertex_indices_5():
  47. chain = Triangle((1, 4, 8))
  48. quintuples = list(chain.adjacent_vertex_indices(5))
  49. assert len(quintuples) == 3
  50. assert quintuples[0] == (1, 4, 8, 1, 4)
  51. assert quintuples[1] == (4, 8, 1, 4, 8)
  52. assert quintuples[2] == (8, 1, 4, 8, 1)