ddnet/src/test/color.cpp

25 lines
671 B
C++
Raw Normal View History

2019-04-24 20:47:03 +00:00
#include "test.h"
#include <gtest/gtest.h>
#include <base/system.h>
#include <base/color.h>
TEST(Color, HRHConv)
{
for(int i = 0; i < 0xFFFFFF; i+= 0xFF){
2019-04-26 18:01:41 +00:00
ColorHSLA hsl = i;
ColorRGBA rgb = color_cast<ColorRGBA>(hsl);
ColorHSLA hsl2 = color_cast<ColorHSLA>(rgb);
2019-04-24 20:47:03 +00:00
if(hsl.s == 0.0f || hsl.s == 1.0f)
EXPECT_FLOAT_EQ(hsl.l, hsl2.l);
2019-04-26 18:01:41 +00:00
else if(hsl.l == 0.0f || hsl.l == 1.0f)
EXPECT_FLOAT_EQ(hsl.l, hsl2.l);
2019-04-24 20:47:03 +00:00
else {
2019-04-26 18:01:41 +00:00
EXPECT_NEAR(fmod(hsl.h, 1.0f), fmod(hsl2.h, 1.0f), 0.001f);
2019-04-24 20:47:03 +00:00
EXPECT_NEAR(hsl.s, hsl2.s, 0.0001f);
EXPECT_FLOAT_EQ(hsl.l, hsl2.l);
}
}
}