MCPcopy
hub / github.com/slopus/happy / expectColorClose

Function expectColorClose

packages/codium/sources/theme/__tests__/derive.test.ts:45–57  ·  view source on GitHub ↗
(actual: string, expected: string, label: string)

Source from the content-addressed store, hash-verified

43const ALPHA_TOL = 0.04 // ±0.04 alpha — accommodates curve-fit residuals across themes
44
45function expectColorClose(actual: string, expected: string, label: string) {
46 const a = parseRgba(actual)
47 const e = parseRgba(expected)
48 if (!a || !e) {
49 expect(actual, `${label}: unparseable`).toBe(expected)
50 return
51 }
52 for (let i = 0; i < 3; i++) {
53 const d = Math.abs(a.rgb[i] - e.rgb[i])
54 expect(d, `${label}: channel ${i} ${a.rgb[i]} vs ${e.rgb[i]} (got=${actual} want=${expected})`).toBeLessThanOrEqual(HEX_TOL)
55 }
56 expect(Math.abs(a.a - e.a), `${label}: alpha ${a.a} vs ${e.a}`).toBeLessThanOrEqual(ALPHA_TOL)
57}
58
59/* ---------- tokens we cover ---------- */
60

Callers 1

derive.test.tsFile · 0.85

Calls 3

parseRgbaFunction · 0.85
expectFunction · 0.85
toBeMethod · 0.80

Tested by

no test coverage detected