ColorTests.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "tests/ColorTests.h"
  2. #include "tests/Test.h"
  3. #include "utils/Color.h"
  4. const float eps = 0.0001f;
  5. static void testColor1(Test& test) {
  6. Color1 c = Color1(36);
  7. test.checkEqual(static_cast<Color1::Channel>(36), c.data[0], "build 1 | 1");
  8. test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 1 | 2");
  9. }
  10. static void testColor2(Test& test) {
  11. Color2 c = Color2(36, 100);
  12. test.checkEqual(static_cast<Color2::Channel>(36), c.data[0], "build 2 | 1");
  13. test.checkEqual(static_cast<Color2::Channel>(100), c.data[1], "build 2 | 2");
  14. test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 2 | 3");
  15. test.checkFloat(100.0f / 255.0f, c.asFloat(1), eps, "build 2 | 4");
  16. }
  17. static void testColor3(Test& test) {
  18. Color3 c = Color3(36, 100, 200);
  19. test.checkEqual(static_cast<Color3::Channel>(36), c.data[0], "build 3 | 1");
  20. test.checkEqual(static_cast<Color3::Channel>(100), c.data[1], "build 3 | 2");
  21. test.checkEqual(static_cast<Color3::Channel>(200), c.data[2], "build 3 | 3");
  22. test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 3 | 4");
  23. test.checkFloat(100.0f / 255.0f, c.asFloat(1), eps, "build 3 | 5");
  24. test.checkFloat(200.0f / 255.0f, c.asFloat(2), eps, "build 3 | 6");
  25. }
  26. static void testColor4(Test& test) {
  27. Color4 c = Color4(36, 100, 200, 142);
  28. test.checkEqual(static_cast<Color4::Channel>(36), c.data[0], "build 4 | 1");
  29. test.checkEqual(static_cast<Color4::Channel>(100), c.data[1], "build 4 | 2");
  30. test.checkEqual(static_cast<Color4::Channel>(200), c.data[2], "build 4 | 3");
  31. test.checkEqual(static_cast<Color4::Channel>(142), c.data[3], "build 4 | 4");
  32. test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 4 | 5");
  33. test.checkFloat(100.0f / 255.0f, c.asFloat(1), eps, "build 4 | 6");
  34. test.checkFloat(200.0f / 255.0f, c.asFloat(2), eps, "build 4 | 7");
  35. test.checkFloat(142.0f / 255.0f, c.asFloat(3), eps, "build 4 | 8");
  36. }
  37. void ColorTests::test() {
  38. Test test("Color");
  39. testColor1(test);
  40. testColor2(test);
  41. testColor3(test);
  42. testColor4(test);
  43. test.finalize();
  44. }