package zutil;

import org.junit.Test;

import static org.junit.Assert.*;

public class ColorUtilTest {

    @Test
    public void getHexString() {
        assertEquals("#000000", ColorUtil.getHexString(0, 0, 0));
        assertEquals("#090909", ColorUtil.getHexString(9, 9, 9));
        assertEquals("#ffffff", ColorUtil.getHexString(255, 255, 255));
        assertEquals("#6496c8", ColorUtil.getHexString(100, 150, 200));
    }

    @Test
    public void getRgbFromHexString() {
        assertArrayEquals(new int[]{0, 0, 0}, ColorUtil.getRgbFromHexString("#000000"));
        assertArrayEquals(new int[]{9, 9, 9}, ColorUtil.getRgbFromHexString("#090909"));
        assertArrayEquals(new int[]{255, 255, 255}, ColorUtil.getRgbFromHexString("#ffffff"));
        assertArrayEquals(new int[]{100, 150, 200}, ColorUtil.getRgbFromHexString("#6496c8"));
    }

    @Test
    public void getHueFromRGB() {
        assertEquals(0.0, ColorUtil.getHue(0, 0, 0), 0);
        assertEquals(0.0, ColorUtil.getHue(255, 255, 255), 0);
        assertEquals(0.0, ColorUtil.getHue(255, 0, 0), 0);
        assertEquals(120.0, ColorUtil.getHue(0, 255, 0), 0);
        assertEquals(240.0, ColorUtil.getHue(0, 0, 255), 0);
        assertEquals(0.0, ColorUtil.getHue(128, 128, 128), 0);
        assertEquals(12.0, ColorUtil.getHue(100, 60, 50), 0);
        assertEquals(108.0, ColorUtil.getHue(60, 100, 50), 0);
        assertEquals(228.0, ColorUtil.getHue(50, 60, 100), 0);
    }

    @Test
    public void getSaturationFromRGB() {
        assertEquals(0.0, ColorUtil.getSaturation(0, 0, 0), 0);
        assertEquals(0.0, ColorUtil.getSaturation(255, 255, 255), 0);
        assertEquals(1.0, ColorUtil.getSaturation(255, 0, 0), 0);
        assertEquals(1.0, ColorUtil.getSaturation(0, 255, 0), 0);
        assertEquals(1.0, ColorUtil.getSaturation(0, 0, 255), 0);
        assertEquals(0.0, ColorUtil.getSaturation(128, 128, 128), 0);
        assertEquals(0.333, ColorUtil.getSaturation(100, 60, 50), 0.001);
        assertEquals(0.333, ColorUtil.getSaturation(60, 100, 50), 0.001);
        assertEquals(0.333, ColorUtil.getSaturation(50, 60, 100), 0.001);
    }

    @Test
    public void getLightnessFromRGB() {
        assertEquals(0.0, ColorUtil.getLightness(0, 0, 0), 0);
        assertEquals(1.0, ColorUtil.getLightness(255, 255, 255), 0);
        assertEquals(0.5, ColorUtil.getLightness(255, 0, 0), 0);
        assertEquals(0.5, ColorUtil.getLightness(0, 255, 0), 0);
        assertEquals(0.5, ColorUtil.getLightness(0, 0, 255), 0);
        assertEquals(0.75, ColorUtil.getLightness(191, 191, 191), 0.01);
        assertEquals(0.5, ColorUtil.getLightness(128, 128, 128), 0.01);
        assertEquals(0.294, ColorUtil.getLightness(100, 60, 50), 0.01);
        assertEquals(0.294, ColorUtil.getLightness(60, 100, 50), 0.01);
        assertEquals(0.294, ColorUtil.getLightness(50, 60, 100), 0.01);
    }
}