1 | #include "test.h" |
2 | #include <gtest/gtest.h> |
3 | |
4 | #include <base/color.h> |
5 | |
6 | TEST(Color, HRHConv) |
7 | { |
8 | for(int i = 0; i < 0xFFFFFF; i += 0xFF) |
9 | { |
10 | ColorHSLA hsl = i; |
11 | ColorRGBA rgb = color_cast<ColorRGBA>(hsl); |
12 | ColorHSLA hsl2 = color_cast<ColorHSLA>(rgb); |
13 | |
14 | if(hsl.s == 0.0f || hsl.s == 1.0f) |
15 | EXPECT_FLOAT_EQ(hsl.l, hsl2.l); |
16 | else if(hsl.l == 0.0f || hsl.l == 1.0f) |
17 | EXPECT_FLOAT_EQ(hsl.l, hsl2.l); |
18 | else |
19 | { |
20 | EXPECT_NEAR(std::fmod(hsl.h, 1.0f), std::fmod(hsl2.h, 1.0f), 0.001f); |
21 | EXPECT_NEAR(hsl.s, hsl2.s, 0.0001f); |
22 | EXPECT_FLOAT_EQ(hsl.l, hsl2.l); |
23 | } |
24 | } |
25 | } |
26 | |
27 | // Any color_cast should keep the same alpha value |
28 | TEST(Color, ConvKeepsAlpha) |
29 | { |
30 | const int Max = 10; |
31 | for(int i = 0; i <= Max; i++) |
32 | { |
33 | const float Alpha = i / (float)Max; |
34 | EXPECT_FLOAT_EQ(color_cast<ColorRGBA>(ColorHSLA(0.1f, 0.2f, 0.3f, Alpha)).a, Alpha); |
35 | EXPECT_FLOAT_EQ(color_cast<ColorRGBA>(ColorHSVA(0.1f, 0.2f, 0.3f, Alpha)).a, Alpha); |
36 | EXPECT_FLOAT_EQ(color_cast<ColorHSLA>(ColorRGBA(0.1f, 0.2f, 0.3f, Alpha)).a, Alpha); |
37 | EXPECT_FLOAT_EQ(color_cast<ColorHSLA>(ColorHSVA(0.1f, 0.2f, 0.3f, Alpha)).a, Alpha); |
38 | EXPECT_FLOAT_EQ(color_cast<ColorHSVA>(ColorRGBA(0.1f, 0.2f, 0.3f, Alpha)).a, Alpha); |
39 | EXPECT_FLOAT_EQ(color_cast<ColorHSVA>(ColorHSLA(0.1f, 0.2f, 0.3f, Alpha)).a, Alpha); |
40 | } |
41 | } |
42 | |