#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<Color1::Channel>(36), c.data[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<Color2::Channel>(36), c.data[0], "build 2 | 1");
    test.checkEqual(static_cast<Color2::Channel>(100), c.data[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<Color3::Channel>(36), c.data[0], "build 3 | 1");
    test.checkEqual(static_cast<Color3::Channel>(100), c.data[1], "build 3 | 2");
    test.checkEqual(static_cast<Color3::Channel>(200), c.data[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<Color4::Channel>(36), c.data[0], "build 4 | 1");
    test.checkEqual(static_cast<Color4::Channel>(100), c.data[1], "build 4 | 2");
    test.checkEqual(static_cast<Color4::Channel>(200), c.data[2], "build 4 | 3");
    test.checkEqual(static_cast<Color4::Channel>(142), c.data[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();
}