import { expect, test } from "vitest" import { hslColorValueToSrgbColorValue, hsvColorValueToSrgbColorValue, linearRgbColorValueToSrgbColorValue, srgbColorValueToHslColorValue, srgbColorValueToHsvColorValue, srgbColorValueToLinearRgbColorValue, } from "#Source/color/index.ts" test("linearRgbColorValueToSrgbColorValue converts in-gamut linear values to sRGB", () => { expect(linearRgbColorValueToSrgbColorValue({ red: 1, green: 0, blue: 0, alpha: 0.5 })).toEqual({ red: 255, green: 0, blue: 0, alpha: 0.5, }) expect( linearRgbColorValueToSrgbColorValue({ red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5 }), ).toEqual({ red: 188, green: 188, blue: 188, alpha: 0.5 }) expect(() => linearRgbColorValueToSrgbColorValue({ red: 1.2, green: 0, blue: 0, alpha: 1 }), ).toThrow(RangeError) }) test("srgbColorValueToLinearRgbColorValue converts sRGB values to linear values", () => { expect(srgbColorValueToLinearRgbColorValue({ red: 255, green: 0, blue: 0, alpha: 0.5 })).toEqual({ red: 1, green: 0, blue: 0, alpha: 0.5, }) expect( srgbColorValueToLinearRgbColorValue({ red: 128, green: 128, blue: 128, alpha: 0.5 }), ).toEqual({ red: 0.215_861, green: 0.215_861, blue: 0.215_861, alpha: 0.5 }) }) test("srgbColorValueToHslColorValue converts sRGB values to HSL", () => { expect(srgbColorValueToHslColorValue({ red: 51, green: 102, blue: 153, alpha: 1 })).toEqual({ hue: 210, saturation: 0.5, lightness: 0.4, alpha: 1, }) expect(srgbColorValueToHslColorValue({ red: 128, green: 128, blue: 128, alpha: 1 })).toEqual({ hue: 0, saturation: 0, lightness: 0.501_961, alpha: 1, }) }) test("hslColorValueToSrgbColorValue converts HSL values to sRGB", () => { expect( hslColorValueToSrgbColorValue({ hue: 210, saturation: 0.5, lightness: 0.4, alpha: 1 }), ).toEqual({ red: 51, green: 102, blue: 153, alpha: 1 }) expect( hslColorValueToSrgbColorValue({ hue: 0, saturation: 0, lightness: 0.501_961, alpha: 1 }), ).toEqual({ red: 128, green: 128, blue: 128, alpha: 1 }) }) test("srgbColorValueToHsvColorValue converts sRGB values to HSV", () => { expect(srgbColorValueToHsvColorValue({ red: 51, green: 102, blue: 153, alpha: 1 })).toEqual({ hue: 210, saturation: 0.666_667, value: 0.6, alpha: 1, }) expect(srgbColorValueToHsvColorValue({ red: 128, green: 128, blue: 128, alpha: 1 })).toEqual({ hue: 0, saturation: 0, value: 0.501_961, alpha: 1, }) }) test("hsvColorValueToSrgbColorValue converts HSV values to sRGB", () => { expect( hsvColorValueToSrgbColorValue({ hue: 210, saturation: 0.666_667, value: 0.6, alpha: 1 }), ).toEqual({ red: 51, green: 102, blue: 153, alpha: 1 }) expect( hsvColorValueToSrgbColorValue({ hue: 0, saturation: 0, value: 0.501_961, alpha: 1 }), ).toEqual({ red: 128, green: 128, blue: 128, alpha: 1 }) })