import { expect, test } from "vitest" import { xyzColorValueToRelativeLuminance, xyzColorValueToTristimulusSum, xyzColorValueToXyChromaticityValue, } from "#Source/color/index.ts" test("xyzColorValueToRelativeLuminance returns y channel", () => { expect(xyzColorValueToRelativeLuminance({ x: 0.25, y: 0.3, z: 0.4, alpha: 1 })).toBe(0.3) expect(xyzColorValueToRelativeLuminance({ x: 0, y: 0, z: 0, alpha: 1 })).toBe(0) }) test("xyzColorValueToTristimulusSum returns x plus y plus z", () => { expect(xyzColorValueToTristimulusSum({ x: 0.25, y: 0.3, z: 0.4, alpha: 1 })).toBe(0.95) expect(xyzColorValueToTristimulusSum({ x: 0, y: 0, z: 0, alpha: 1 })).toBe(0) }) test("xyzColorValueToXyChromaticityValue returns xy chromaticity coordinates", () => { expect(xyzColorValueToXyChromaticityValue({ x: 0.25, y: 0.3, z: 0.4, alpha: 1 })).toEqual({ x: 0.263_158, y: 0.315_789, }) expect( xyzColorValueToXyChromaticityValue({ x: 0.412_456, y: 0.212_673, z: 0.019_334, alpha: 1 }), ).toEqual({ x: 0.64, y: 0.33, }) expect(() => xyzColorValueToXyChromaticityValue({ x: 0, y: 0, z: 0, alpha: 1 })).toThrow( "XYZ tristimulus sum must be greater than 0 to compute xy chromaticity", ) })