import { createColorBlindSimulationAdjustment, initializeColorBlindSimulationAdjustment, } from './colorBlindSimulationAdjustment.ts'; import { applyColorMatrixToColor } from './colorMatrixMath.ts'; describe('createColorBlindSimulationAdjustment', () => { it('defaults to deuteranopia and bakes its linear matrix, preserving alpha', () => { const adjustment = createColorBlindSimulationAdjustment(); expect(adjustment.kind).toBe('ColorBlindSimulationAdjustment'); expect(adjustment.colorMatrix).toHaveLength(20); // Float32 coefficients preserve Rust precision: pure red maps to R'=159, G'=178, B'=0. expect(applyColorMatrixToColor(adjustment.colorMatrix, 0xff0000ff)).toBe(0x9fb200ff); }); it('achromatopsia collapses to equal-channel luma (monochrome)', () => { const adjustment = createColorBlindSimulationAdjustment({ type: 'achromatopsia' }); // Pure red → 0.299·255≈76 across all channels. expect(applyColorMatrixToColor(adjustment.colorMatrix, 0xff0000ff)).toBe(0x4c4c4cff); }); it('selects a distinct matrix per type', () => { const protan = createColorBlindSimulationAdjustment({ type: 'protanopia' }); const tritan = createColorBlindSimulationAdjustment({ type: 'tritanopia' }); const green = 0x00ff00ff; expect(applyColorMatrixToColor(protan.colorMatrix, green)).not.toBe( applyColorMatrixToColor(tritan.colorMatrix, green), ); }); }); describe('initializeColorBlindSimulationAdjustment', () => { it('is the construction initializer of createColorBlindSimulationAdjustment', () => { expect(typeof initializeColorBlindSimulationAdjustment).toBe('function'); }); });