diff --git a/src/lib/ColorLint.test.ts b/src/lib/ColorLint.test.ts index 258d4b3e..ed777a43 100644 --- a/src/lib/ColorLint.test.ts +++ b/src/lib/ColorLint.test.ts @@ -4,8 +4,9 @@ import { Color } from "./Color"; import type { Palette } from "../stores/color-store"; import ColorNameDiscriminability, { getName } from "./lints/name-discrim"; -import ColorBlind from "./lints/blind-check"; import BackgroundDifferentiability from "./lints/background-differentiability"; +import BUILT_INS from "../stores/built-in-lints"; +import { CreateCustomLint } from "./lints/CustomLint"; function makePalFromHexes(hexes: string[]): Palette { return { @@ -50,17 +51,33 @@ test("ColorLint - ColorBlind", async () => { "#00becf", ]; const examplePal = makePalFromHexes(tableau10); - const exampleLint1 = new ColorBlind[0](examplePal).run(); + const cbDeuteranopia = CreateCustomLint( + BUILT_INS.find((x) => x.id === "colorblind-friendly-deuteranopia-built-in")! + ); + const exampleLint1 = new cbDeuteranopia(examplePal).run(); expect(exampleLint1.passes).toBe(false); expect(exampleLint1.message).toMatchSnapshot(); - const exampleLint2 = new ColorBlind[1](examplePal).run(); + const cbProtanopia = CreateCustomLint( + BUILT_INS.find((x) => x.id === "colorblind-friendly-protanopia-built-in")! + ); + const exampleLint2 = new cbProtanopia(examplePal).run(); expect(exampleLint2.passes).toBe(false); expect(exampleLint2.message).toMatchSnapshot(); - const exampleLint3 = new ColorBlind[2](examplePal).run(); + const cbTritanopia = CreateCustomLint( + BUILT_INS.find((x) => x.id === "colorblind-friendly-tritanopia-built-in")! + ); + const exampleLint3 = new cbTritanopia(examplePal).run(); expect(exampleLint3.passes).toBe(false); expect(exampleLint3.message).toMatchSnapshot(); + + const cbGrayscale = CreateCustomLint( + BUILT_INS.find((x) => x.id === "colorblind-friendly-grayscale-built-in")! + ); + const exampleLint4 = new cbGrayscale(examplePal).run(); + expect(exampleLint4.passes).toBe(false); + expect(exampleLint4.message).toMatchSnapshot(); }); const ughWhat = ["#00ffff", "#00faff", "#00e4ff", "#fdfdfc", "#00ffff"]; diff --git a/src/lib/lint-language/LintLanguage.test.ts b/src/lib/lint-language/LintLanguage.test.ts index 1ea846ce..1732bea9 100644 --- a/src/lib/lint-language/LintLanguage.test.ts +++ b/src/lib/lint-language/LintLanguage.test.ts @@ -590,50 +590,6 @@ test("LintLanguage Sequential Colors", () => { ); }); -test("LintLanguage Sequential Colors", () => { - const sequential = { - "==": { - left: { "-": { left: "index(a)", right: 1 } }, - right: "index(b)", - }, - }; - const program = { - or: [ - { - all: { - in: "colors", - varbs: ["a", "b"], - where: sequential, - predicate: { - ">": { left: { "lab.l": "a" }, right: { "lab.l": "b" } }, - }, - }, - }, - { - all: { - in: "colors", - varbs: ["a", "b"], - where: sequential, - predicate: { - "<": { left: { "lab.l": "a" }, right: { "lab.l": "b" } }, - }, - }, - }, - ], - }; - - const outOfOrder = toPal(["#d4a8ff", "#008694", "#7bb9ff"]); - const ooResult = LLEval(program, outOfOrder); - expect(ooResult.result).toBe(false); - expect(ooResult.blame).toStrictEqual([0, 1, 2]); - - const inOrder = toPal(["#d4a8ff", "#7bb9ff", "#008694"]); - expect(LLEval(program, inOrder).result).toBe(true); - expect(prettyPrintLL(program)).toBe( - "ALL (a, b) in colors WHERE index(a) - 1 == index(b), lab.l(a) > lab.l(b) or ALL (a, b) in colors WHERE index(a) - 1 == index(b), lab.l(a) < lab.l(b)" - ); -}); - test.skip("LintLanguage Diverging Colors - dense notation", () => { const sequential = { and: [ diff --git a/src/lib/lint-language/lint-language.ts b/src/lib/lint-language/lint-language.ts index 56d4c2e5..ff74eb5d 100644 --- a/src/lib/lint-language/lint-language.ts +++ b/src/lib/lint-language/lint-language.ts @@ -695,12 +695,8 @@ export class LLQuantifier extends LLNode { ); let blameIndices = new Set([]); let topEnv = env.copy(); - const checkedKeys = new Set(); const mappedEvaluations = carts .map((combo: any) => { - const key = combo.sort().join(","); - if (checkedKeys.has(key)) return "skip"; - checkedKeys.add(key); const varbIndex = this.varbs.map((varb, idx) => { return [varb, inputData[combo[idx]]]; }); @@ -976,6 +972,12 @@ export function permutativeBlame( ): number[] | number[][] { const initialRun = LLEval(root, palette); if (initialRun.result) return []; + // dont compute blame if it doesn't matter + const hasColorsRef = JSON.stringify(root).includes("colors"); + const hasBgRef = JSON.stringify(root).includes("background"); + if (!hasColorsRef && !hasBgRef) { + return []; + } // single blame const allIndices = palette.colors.map((_, i) => i); @@ -987,7 +989,6 @@ export function permutativeBlame( const result = LLEval(root, tempPalette); if (!result.result) { blamedIndices.push(x); - console.log("constructive", x); } }); if (blamedIndices.length > 0) return blamedIndices;