test_color.py 813 B

12345678910111213141516171819202122232425
  1. import sys
  2. from subprocess import run, PIPE
  3. from unittest import TestCase
  4. from colorsys import hls_to_rgb
  5. run(["cc", "-O2", "-o", "test_color.bin", "test_color.c"])
  6. class Color_Test(TestCase):
  7. def test_0(self):
  8. def t(h, s, l):
  9. res = (int(x)
  10. for x in run(["./test_color.bin", str(h), str(s), str(l)],
  11. stdout=PIPE).stdout.decode("UTF-8").split())
  12. exp = (round(x * 0xFFFF)
  13. for x in hls_to_rgb(h / 0xFFFF, l / 0xFFFF, s / 0xFFFF))
  14. if not all( abs(a - b) <= 6 for a, b in zip(res, exp) ):
  15. print("H = %X S = %X L = %X" % (h, s, l))
  16. print("res =", list(res), ", exp =", list(exp))
  17. assert 0, "Invalid RGB conversion."
  18. for h in range(0, 0xFFFF+1, 0x1000):
  19. for s in range(0, 0xFFFF+1, 0x1000):
  20. for l in range(0, 0xFFFF+1, 0x1000):
  21. t(h, s, l)