ColorTests.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "tests/ColorTests.hpp"
  2. #include "test/Test.hpp"
  3. #include "utils/Color.hpp"
  4. const float eps = 0.0001f;
  5. static void testColor1() {
  6. Core::Color1 c(36);
  7. CORE_TEST_EQUAL(36, c[0]);
  8. CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps);
  9. }
  10. static void testColor2() {
  11. Core::Color2 c(36 + 256, 100.0);
  12. CORE_TEST_EQUAL(36, c[0]);
  13. CORE_TEST_EQUAL(100, c[1]);
  14. CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps);
  15. CORE_TEST_FLOAT(100.0f / 255.0f, c.asFloat(1), eps);
  16. }
  17. static void testColor3() {
  18. Core::Color3 c(36, 100.0f, 200);
  19. CORE_TEST_EQUAL(36, c[0]);
  20. CORE_TEST_EQUAL(100, c[1]);
  21. CORE_TEST_EQUAL(200, c[2]);
  22. CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps);
  23. CORE_TEST_FLOAT(100.0f / 255.0f, c.asFloat(1), eps);
  24. CORE_TEST_FLOAT(200.0f / 255.0f, c.asFloat(2), eps);
  25. }
  26. static void testColor4() {
  27. Core::Color4 c(36, 100, 200, 142);
  28. CORE_TEST_EQUAL(36, c[0]);
  29. CORE_TEST_EQUAL(100, c[1]);
  30. CORE_TEST_EQUAL(200, c[2]);
  31. CORE_TEST_EQUAL(142, c[3]);
  32. CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps);
  33. CORE_TEST_FLOAT(100.0f / 255.0f, c.asFloat(1), eps);
  34. CORE_TEST_FLOAT(200.0f / 255.0f, c.asFloat(2), eps);
  35. CORE_TEST_FLOAT(142.0f / 255.0f, c.asFloat(3), eps);
  36. }
  37. static void testColor4Empty() {
  38. Core::Color4 c;
  39. CORE_TEST_EQUAL(0, c[0]);
  40. CORE_TEST_EQUAL(0, c[1]);
  41. CORE_TEST_EQUAL(0, c[2]);
  42. CORE_TEST_EQUAL(0, c[3]);
  43. }
  44. void Core::ColorTests::test() {
  45. testColor1();
  46. testColor2();
  47. testColor3();
  48. testColor4();
  49. testColor4Empty();
  50. }