#include "tests/ColorTests.h" #include "test/Test.h" #include "utils/Color.h" const float eps = 0.0001f; static void testColor1() { Core::Color1 c(36); CORE_TEST_EQUAL(36, c[0]); CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps); } static void testColor2() { Core::Color2 c(36 + 256, 100.0); CORE_TEST_EQUAL(36, c[0]); CORE_TEST_EQUAL(100, c[1]); CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps); CORE_TEST_FLOAT(100.0f / 255.0f, c.asFloat(1), eps); } static void testColor3() { Core::Color3 c(36, 100.0f, 200); CORE_TEST_EQUAL(36, c[0]); CORE_TEST_EQUAL(100, c[1]); CORE_TEST_EQUAL(200, c[2]); CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps); CORE_TEST_FLOAT(100.0f / 255.0f, c.asFloat(1), eps); CORE_TEST_FLOAT(200.0f / 255.0f, c.asFloat(2), eps); } static void testColor4() { Core::Color4 c(36, 100, 200, 142); CORE_TEST_EQUAL(36, c[0]); CORE_TEST_EQUAL(100, c[1]); CORE_TEST_EQUAL(200, c[2]); CORE_TEST_EQUAL(142, c[3]); CORE_TEST_FLOAT(36.0f / 255.0f, c.asFloat(0), eps); CORE_TEST_FLOAT(100.0f / 255.0f, c.asFloat(1), eps); CORE_TEST_FLOAT(200.0f / 255.0f, c.asFloat(2), eps); CORE_TEST_FLOAT(142.0f / 255.0f, c.asFloat(3), eps); } static void testColor4Empty() { Core::Color4 c; CORE_TEST_EQUAL(0, c[0]); CORE_TEST_EQUAL(0, c[1]); CORE_TEST_EQUAL(0, c[2]); CORE_TEST_EQUAL(0, c[3]); } void Core::ColorTests::test() { testColor1(); testColor2(); testColor3(); testColor4(); testColor4Empty(); }