-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
class based implementation starting to work
- Loading branch information
1 parent
e6df6d4
commit 93d1585
Showing
4 changed files
with
598 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,84 @@ | ||
import { expect, test } from "vitest"; | ||
import LLEval from "./lint-language"; | ||
import { LLEval, prettyPrintLL } from "./ugh"; | ||
|
||
test("LintLanguage basic eval ", async () => { | ||
const colors = [ | ||
{ nodeType: "Color", value: "#005ebe" }, | ||
{ nodeType: "Color", value: "#5260d1" }, | ||
{ nodeType: "Color", value: "#005ebe" }, | ||
]; | ||
const exampleProgramWithAnnotations = { | ||
nodeType: "Predicate", | ||
type: "gt", | ||
left: { | ||
nodeType: "Reduce", | ||
type: "count", | ||
input: { | ||
nodeType: "Variable", | ||
value: "colors", | ||
}, | ||
function: { | ||
nodeType: "ValueFunction", | ||
type: "channel", | ||
space: "string", | ||
input: { | ||
nodeType: "Color", | ||
value: "lab", | ||
test("LintLanguage basic eval ", () => { | ||
const colors = ["#005ebe", "#5260d1", "#005ebe"]; | ||
// eval with no references | ||
const prog1 = { "<": { left: { count: colors }, right: 2 } }; | ||
expect(LLEval(prog1, colors)).toBe(false); | ||
expect(prettyPrintLL(prog1)).toBe("count([#005ebe, #5260d1, #005ebe]) < 2"); | ||
|
||
const prog2 = { "<": { left: { count: colors }, right: 10 } }; | ||
expect(LLEval(prog2, colors)).toBe(true); | ||
expect(prettyPrintLL(prog2)).toBe("count([#005ebe, #5260d1, #005ebe]) < 10"); | ||
|
||
// eval with main reference | ||
const prog3 = { "<": { left: { count: "colors" }, right: 2 } }; | ||
expect(LLEval(prog3, colors)).toBe(false); | ||
expect(prettyPrintLL(prog3)).toBe("count(colors) < 2"); | ||
|
||
const prog4 = { "<": { left: { count: "colors" }, right: 10 } }; | ||
expect(LLEval(prog4, colors)).toBe(true); | ||
expect(prettyPrintLL(prog4)).toBe("count(colors) < 10"); | ||
}); | ||
|
||
test.only("LintLanguage Quantifiers", () => { | ||
const colorBlind = { | ||
all: { | ||
input: "colors", | ||
value: "a", | ||
predicate: { | ||
all: { | ||
input: "colors", | ||
value: "b", | ||
predicate: { | ||
not: { | ||
"==": { | ||
left: { cvd_sim: "a", type: "deuteranopia" }, | ||
right: { cvd_sim: "b", type: "deuteranopia" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
right: { | ||
nodeType: "LLNumber", | ||
value: 2, | ||
}, | ||
}; | ||
const result = LLEval(exampleProgramWithAnnotations, colors); | ||
expect(result).toBe(false); | ||
// const colorBlind = { | ||
// not: { | ||
// exist: { | ||
// input: "colors", | ||
// value: "a", | ||
// predicate: { | ||
// exist: { | ||
// input: "colors", | ||
// value: "b", | ||
// predicate: { | ||
// not: { | ||
// "!=": { | ||
// left: { cvd_sim: "a", type: "deuteranopia" }, | ||
// right: { cvd_sim: "b", type: "deuteranopia" }, | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
// }; | ||
expect(LLEval(colorBlind, ["#005ebe", "#5260d1", "#005ebe"])).toBe(false); | ||
}); | ||
|
||
// YAML VERSION | ||
// <: | ||
// left: {count: colors} | ||
// right: {value: 10} | ||
// all: | ||
// input: colors, | ||
// value: 'a', | ||
// predicate: | ||
// all: | ||
// colors, | ||
// value: 'b', | ||
// predicate: | ||
// not: | ||
// equal: | ||
// left: {cvd_sim: 'a', type: 'deuteranopia'} | ||
// right: {cvd_sim: 'b', type: 'deuteranopia'} | ||
// JSON VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.