import { expect, test } from "vitest" import { createHslColorValue, createHslColorValueByString, createHsvColorValue, createHsvColorValueByString, createLinearRgbColorValue, createSrgbColorValue, createSrgbColorValueByString, } from "#Source/color/index.ts" test("createLinearRgbColorValue accepts finite linear channels", () => { expect(createLinearRgbColorValue({ red: -0.25, green: 0.4, blue: 1.2, alpha: 1 })).toEqual({ red: -0.25, green: 0.4, blue: 1.2, alpha: 1, }) expect(createLinearRgbColorValue({ red: 0, green: 0, blue: 0, alpha: 0.5 })).toEqual({ red: 0, green: 0, blue: 0, alpha: 0.5, }) expect(() => createLinearRgbColorValue({ red: Number.NaN, green: 0.4, blue: 1.2, alpha: 1 }), ).toThrow(RangeError) }) test("createSrgbColorValue validates byte channels", () => { expect(createSrgbColorValue({ red: 51, green: 102, blue: 153, alpha: 0.5 })).toEqual({ red: 51, green: 102, blue: 153, alpha: 0.5, }) expect(() => createSrgbColorValue({ red: -1, green: 0, blue: 0, alpha: 1 })).toThrow(RangeError) expect(() => createSrgbColorValue({ red: 0, green: 0, blue: 256, alpha: 1 })).toThrow(RangeError) }) test("createHslColorValue normalizes hue and validates units", () => { expect(createHslColorValue({ hue: -30, saturation: 0.5, lightness: 0.4, alpha: 1 })).toEqual({ hue: 330, saturation: 0.5, lightness: 0.4, alpha: 1, }) expect(() => createHslColorValue({ hue: 0, saturation: 1.5, lightness: 0.4, alpha: 1 })).toThrow( RangeError, ) }) test("createHsvColorValue normalizes hue and validates units", () => { expect(createHsvColorValue({ hue: 390, saturation: 0.5, value: 0.6, alpha: 1 })).toEqual({ hue: 30, saturation: 0.5, value: 0.6, alpha: 1, }) expect(() => createHsvColorValue({ hue: 0, saturation: 0.5, value: 1.5, alpha: 1 })).toThrow( RangeError, ) }) test("createSrgbColorValueByString stays deterministic", () => { expect(createSrgbColorValueByString("mobius")).toEqual(createSrgbColorValueByString("mobius")) expect(createSrgbColorValueByString("mobius")).not.toEqual(createSrgbColorValueByString("planet")) }) test("createHslColorValueByString stays deterministic", () => { expect(createHslColorValueByString("mobius")).toEqual(createHslColorValueByString("mobius")) expect(createHslColorValueByString("mobius")).not.toEqual(createHslColorValueByString("planet")) }) test("createHsvColorValueByString stays deterministic", () => { expect(createHsvColorValueByString("mobius")).toEqual(createHsvColorValueByString("mobius")) expect(createHsvColorValueByString("mobius")).not.toEqual(createHsvColorValueByString("planet")) })