Skip to content

Commit

Permalink
fix blame ish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Feb 10, 2024
1 parent 60f1977 commit 9026c2e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 53 deletions.
25 changes: 21 additions & 4 deletions src/lib/ColorLint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"];
Expand Down
44 changes: 0 additions & 44 deletions src/lib/lint-language/LintLanguage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
11 changes: 6 additions & 5 deletions src/lib/lint-language/lint-language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,8 @@ export class LLQuantifier extends LLNode {
);
let blameIndices = new Set<number>([]);
let topEnv = env.copy();
const checkedKeys = new Set<string>();
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]]];
});
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 9026c2e

Please sign in to comment.