* build(deps-dev): bump @biomejs/biome from 1.9.4 to 2.3.3 Bumps [@biomejs/biome](https://github.com/biomejs/biome/tree/HEAD/packages/@biomejs/biome) from 1.9.4 to 2.3.3. - [Release notes](https://github.com/biomejs/biome/releases) - [Changelog](https://github.com/biomejs/biome/blob/main/packages/@biomejs/biome/CHANGELOG.md) - [Commits](https://github.com/biomejs/biome/commits/@biomejs/biome@2.3.3/packages/@biomejs/biome) --- updated-dependencies: - dependency-name: "@biomejs/biome" dependency-version: 2.3.3 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: cannorin <cannorin@users.noreply.github.com>
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { power } from "@cannorin/utils";
|
|
import { expect, test } from "vitest";
|
|
import { validWorlds } from "../src/sat";
|
|
import { type Frame, satisfy, type World, worlds } from "../src/semantics";
|
|
import {
|
|
type Formula,
|
|
type PropVar,
|
|
prettyPrint,
|
|
propVars,
|
|
vars,
|
|
} from "../src/syntax";
|
|
import { randomFormula, randomFrame, testFormulas } from "./utils";
|
|
|
|
const elapsed = <T>(f: () => T) => {
|
|
const start = Date.now();
|
|
const value = f();
|
|
const end = Date.now();
|
|
return { value, elapsed: end - start };
|
|
};
|
|
|
|
export function validWorldsNaive(
|
|
f: Frame,
|
|
fml: Formula,
|
|
allValuations: `${World}${PropVar}`[][],
|
|
) {
|
|
const result: World[] = [];
|
|
for (const w of worlds) {
|
|
let valid = true;
|
|
for (const v of allValuations) {
|
|
if (!satisfy({ ...f, valuations: new Set(v) }, w, fml)) {
|
|
valid = false;
|
|
break;
|
|
}
|
|
}
|
|
if (valid) result.push(w);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
for (const fml of testFormulas.concat(
|
|
[...Array(100)].map(() => randomFormula()),
|
|
)) {
|
|
test(`SAT works for ${prettyPrint(fml)}`, () => {
|
|
const count = 100;
|
|
let diff = 0;
|
|
const allValuations = power(
|
|
worlds.flatMap((w) =>
|
|
(fml ? Array.from(vars(fml)) : propVars).map(
|
|
(p) => `${w}${p}` as const,
|
|
),
|
|
),
|
|
);
|
|
for (let i = 0; i < count; i++) {
|
|
const frame = randomFrame();
|
|
const expected = elapsed(() =>
|
|
validWorldsNaive(frame, fml, allValuations),
|
|
);
|
|
const actual = elapsed(() => validWorlds(frame, fml));
|
|
|
|
expect(actual.value.sort()).toStrictEqual(expected.value.sort());
|
|
diff += actual.elapsed - expected.elapsed;
|
|
}
|
|
expect(diff / count).toBeLessThanOrEqual(10);
|
|
});
|
|
}
|