---@diagnostic disable: undefined-global
-- Verifies VDS_ColorMath against real DB2 dye colours (docs/VDS_ColorTheory.md).
dofile("../Core/VDS_ColorMath.lua")
local CM = VDS.ColorMath

local function approx(actual, expected, tol, msg)
    tol = tol or 0.02
    if math.abs(actual - expected) > tol then
        error(string.format("%s: expected ~%.3f, got %.3f", msg, expected, actual), 2)
    end
end
local function L255(r, g, b) return CM.L(r / 255, g / 255, b / 255) end

-- OKLab lightness matches the verified table (tol 0.02)
approx(L255(177, 28, 30),   0.49, 0.02, "Horde Red L")
approx(L255(255, 245, 151), 0.96, 0.02, "Sungrass Yellow L")
approx(L255(64, 70, 77),    0.39, 0.02, "Obsidium Black L")
print("  [OK] OKLab lightness matches verified DB2 colours")

-- chroma: greys near-zero; vivid out-chromas washed (the Pinewood-as-pop guard)
assert(CM.chroma(134 / 255, 141 / 255, 144 / 255) < 0.04, "Dark Iron should be near-grey")
assert(CM.chroma(63 / 255, 160 / 255, 78 / 255) > CM.chroma(167 / 255, 164 / 255, 124 / 255),
    "Lush Green must out-chroma Pinewood")
print("  [OK] chroma: greys near-zero, vivid > washed")

-- value gap (anti-mud)
local hordeRed = { r = 177 / 255, g = 28 / 255, b = 30 / 255 }
local white    = { r = 1, g = 1, b = 1 }
assert(CM.valueGap(hordeRed, white) > 0.15, "Horde Red vs White must clear the value gap")
assert(CM.valueGap(hordeRed, hordeRed) < 0.001, "self value-gap is zero")
print("  [OK] value gap")

print("ALL colormath tests passed")
