test_vertex.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import numpy
  2. import pytest
  3. from freesurfer_surface import Vertex
  4. def test_init():
  5. vertex = Vertex(-4.0, 0.5, 21.42)
  6. assert isinstance(vertex, numpy.ndarray)
  7. assert vertex.right == pytest.approx(-4.0)
  8. assert vertex.anterior == pytest.approx(0.5)
  9. assert vertex.superior == pytest.approx(21.42)
  10. def test_init_kwargs():
  11. vertex = Vertex(right=-4.0, superior=21.42, anterior=0.5)
  12. assert vertex.right == pytest.approx(-4.0)
  13. assert vertex.anterior == pytest.approx(0.5)
  14. assert vertex.superior == pytest.approx(21.42)
  15. def test_repr():
  16. vertex = Vertex(right=-4.0, superior=21.42, anterior=0.5)
  17. assert repr(vertex) == 'Vertex(right=-4.0, anterior=0.5, superior=21.42)'
  18. def test_add():
  19. assert Vertex(-1.5, 4, 2) + Vertex(2, -4.5, 3) \
  20. == pytest.approx(Vertex(0.5, -0.5, 5))
  21. def test_mult():
  22. assert Vertex(-1.5, 4, 2) * -3 == pytest.approx(Vertex(4.5, -12, -6))
  23. def test_vars():
  24. attrs = vars(Vertex(-1.5, 4, 2))
  25. assert len(attrs) == 3
  26. assert attrs['right'] == pytest.approx(-1.5)
  27. assert attrs['anterior'] == pytest.approx(4)
  28. assert attrs['superior'] == pytest.approx(2)