import { expect, test } from "vitest" import { doSrgbColorValuesMeetContrastRatio, isLightSrgbColorValue, linearRgbColorValueToRelativeLuminance, linearRgbColorValueToTristimulusSum, linearRgbColorValueToXyChromaticityValue, pickReadableSrgbTextColorValue, srgbColorValueToRelativeLuminance, srgbColorValueToTristimulusSum, srgbColorValueToXyChromaticityValue, srgbColorValuesToContrastRatio, } from "#Source/color/index.ts" test("linearRgbColorValueToRelativeLuminance follows the explicit RGB branch pipeline", () => { expect(linearRgbColorValueToRelativeLuminance({ red: 1, green: 0, blue: 0, alpha: 1 })).toBe( 0.212_673, ) expect(linearRgbColorValueToRelativeLuminance({ red: 1, green: 1, blue: 1, alpha: 1 })).toBe(1) }) test("srgbColorValueToRelativeLuminance follows the explicit RGB branch pipeline", () => { expect(srgbColorValueToRelativeLuminance({ red: 51, green: 102, blue: 153, alpha: 1 })).toBe( 0.125_053, ) expect(srgbColorValueToRelativeLuminance({ red: 255, green: 255, blue: 255, alpha: 1 })).toBe(1) }) test("srgbColorValuesToContrastRatio supports accessibility-oriented comparisons", () => { expect( srgbColorValuesToContrastRatio( { red: 0, green: 0, blue: 0, alpha: 1 }, { red: 255, green: 255, blue: 255, alpha: 1 }, ), ).toBe(21) expect( srgbColorValuesToContrastRatio( { red: 51, green: 102, blue: 153, alpha: 1 }, { red: 51, green: 102, blue: 153, alpha: 1 }, ), ).toBe(1) }) test("doSrgbColorValuesMeetContrastRatio validates thresholds and comparisons", () => { expect(() => doSrgbColorValuesMeetContrastRatio( { red: 0, green: 0, blue: 0, alpha: 1 }, { red: 255, green: 255, blue: 255, alpha: 1 }, 0.99, ), ).toThrow(RangeError) expect( doSrgbColorValuesMeetContrastRatio( { red: 0, green: 0, blue: 0, alpha: 1 }, { red: 255, green: 255, blue: 255, alpha: 1 }, 7, ), ).toBe(true) expect( doSrgbColorValuesMeetContrastRatio( { red: 120, green: 120, blue: 120, alpha: 1 }, { red: 255, green: 255, blue: 255, alpha: 1 }, 4.5, ), ).toBe(false) }) test("pickReadableSrgbTextColorValue chooses the more readable candidate", () => { expect(pickReadableSrgbTextColorValue({ red: 0, green: 102, blue: 204, alpha: 1 })).toEqual({ red: 255, green: 255, blue: 255, alpha: 1, }) expect( pickReadableSrgbTextColorValue( { red: 250, green: 240, blue: 210, alpha: 1 }, { darkColor: { red: 32, green: 32, blue: 32, alpha: 1 }, lightColor: { red: 255, green: 255, blue: 255, alpha: 1 }, }, ), ).toEqual({ red: 32, green: 32, blue: 32, alpha: 1, }) }) test("linearRgbColorValueToTristimulusSum follows the explicit RGB branch pipeline", () => { expect(linearRgbColorValueToTristimulusSum({ red: 1, green: 0, blue: 0, alpha: 1 })).toBe( 0.644_463, ) expect(linearRgbColorValueToTristimulusSum({ red: 1, green: 1, blue: 1, alpha: 1 })).toBe(3.039_3) }) test("srgbColorValueToTristimulusSum follows the explicit RGB branch pipeline", () => { expect(srgbColorValueToTristimulusSum({ red: 51, green: 102, blue: 153, alpha: 1 })).toBe( 0.562_889, ) expect(srgbColorValueToTristimulusSum({ red: 255, green: 255, blue: 255, alpha: 1 })).toBe( 3.039_3, ) }) test("linearRgbColorValueToXyChromaticityValue follows the explicit RGB branch pipeline", () => { expect(linearRgbColorValueToXyChromaticityValue({ red: 1, green: 0, blue: 0, alpha: 1 })).toEqual( { x: 0.64, y: 0.33, }, ) }) test("srgbColorValueToXyChromaticityValue follows the explicit RGB branch pipeline", () => { expect(srgbColorValueToXyChromaticityValue({ red: 51, green: 102, blue: 153, alpha: 1 })).toEqual( { x: 0.210_775, y: 0.222_163, }, ) }) test("isLightSrgbColorValue uses relative luminance threshold", () => { expect(isLightSrgbColorValue({ red: 255, green: 255, blue: 255, alpha: 1 })).toBe(true) expect(isLightSrgbColorValue({ red: 0, green: 0, blue: 0, alpha: 1 })).toBe(false) expect(isLightSrgbColorValue({ red: 128, green: 128, blue: 128, alpha: 1 }, 0.2)).toBe(true) expect(() => isLightSrgbColorValue({ red: 128, green: 128, blue: 128, alpha: 1 }, 1.1)).toThrow( RangeError, ) })