1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include "tests/ColorTests.h"
- #include "tests/Test.h"
- #include "utils/Color.h"
- const float eps = 0.0001f;
- static void testColor1(Test& test) {
- Color1 c = Color1(36);
- test.checkEqual(static_cast<ColorChannel>(36), c[0], "build 1 | 1");
- test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 1 | 2");
- }
- static void testColor2(Test& test) {
- Color2 c = Color2(36, 100);
- test.checkEqual(static_cast<ColorChannel>(36), c[0], "build 2 | 1");
- test.checkEqual(static_cast<ColorChannel>(100), c[1], "build 2 | 2");
- test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 2 | 3");
- test.checkFloat(100.0f / 255.0f, c.asFloat(1), eps, "build 2 | 4");
- }
- static void testColor3(Test& test) {
- Color3 c = Color3(36, 100, 200);
- test.checkEqual(static_cast<ColorChannel>(36), c[0], "build 3 | 1");
- test.checkEqual(static_cast<ColorChannel>(100), c[1], "build 3 | 2");
- test.checkEqual(static_cast<ColorChannel>(200), c[2], "build 3 | 3");
- test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 3 | 4");
- test.checkFloat(100.0f / 255.0f, c.asFloat(1), eps, "build 3 | 5");
- test.checkFloat(200.0f / 255.0f, c.asFloat(2), eps, "build 3 | 6");
- }
- static void testColor4(Test& test) {
- Color4 c = Color4(36, 100, 200, 142);
- test.checkEqual(static_cast<ColorChannel>(36), c[0], "build 4 | 1");
- test.checkEqual(static_cast<ColorChannel>(100), c[1], "build 4 | 2");
- test.checkEqual(static_cast<ColorChannel>(200), c[2], "build 4 | 3");
- test.checkEqual(static_cast<ColorChannel>(142), c[3], "build 4 | 4");
- test.checkFloat(36.0f / 255.0f, c.asFloat(0), eps, "build 4 | 5");
- test.checkFloat(100.0f / 255.0f, c.asFloat(1), eps, "build 4 | 6");
- test.checkFloat(200.0f / 255.0f, c.asFloat(2), eps, "build 4 | 7");
- test.checkFloat(142.0f / 255.0f, c.asFloat(3), eps, "build 4 | 8");
- }
- void ColorTests::test() {
- Test test("Color");
- testColor1(test);
- testColor2(test);
- testColor3(test);
- testColor4(test);
- test.finalize();
- }
|