test_label.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Label
  19. @pytest.mark.parametrize(
  20. ("red", "green", "blue", "transparency", "color_code"),
  21. [
  22. (220, 20, 20, 0, 1316060),
  23. (60, 20, 220, 0, 14423100),
  24. (75, 50, 125, 0, 8204875),
  25. (20, 220, 160, 0, 10542100),
  26. ],
  27. )
  28. def test_color_code(red, green, blue, transparency, color_code):
  29. label = Label(
  30. index=21,
  31. name="name",
  32. red=red,
  33. green=green,
  34. blue=blue,
  35. transparency=transparency,
  36. )
  37. assert color_code == label.color_code
  38. def test_color_code_unknown():
  39. label = Label(index=0, name="unknown", red=21, green=21, blue=21, transparency=0)
  40. assert label.color_code == 0
  41. @pytest.mark.parametrize(
  42. ("red", "green", "blue", "hex_color_code"),
  43. [
  44. (0, 0, 0, "#000000"),
  45. (255, 255, 255, "#ffffff"),
  46. (255, 0, 0, "#ff0000"),
  47. (0, 255, 0, "#00ff00"),
  48. (0, 0, 255, "#0000ff"),
  49. (1, 2, 3, "#010203"),
  50. (17, 18, 19, "#111213"),
  51. (128, 192, 255, "#80c0ff"),
  52. (20, 220, 160, "#14dca0"),
  53. ],
  54. )
  55. def test_hex_color_code(red, green, blue, hex_color_code):
  56. label = Label(
  57. index=21, name="name", red=red, green=green, blue=blue, transparency=0
  58. )
  59. assert hex_color_code == label.hex_color_code.lower()
  60. def test_str():
  61. label = Label(
  62. index=24, name="precentral", red=60, green=20, blue=220, transparency=0
  63. )
  64. assert str(label) == "Label(name=precentral, index=24, color=#3c14dc)"
  65. def test_repr():
  66. label = Label(
  67. index=24, name="precentral", red=60, green=20, blue=220, transparency=0
  68. )
  69. assert repr(label) == "Label(name=precentral, index=24, color=#3c14dc)"