gram/packages/kitchen/tests/schedule-warnings.test.ts
abiwab c156d562aa
All checks were successful
CI / Build, Test & Publish (pull_request) Successful in 4m0s
refactor(scheduler): extract the scheduling engine into its own package
2026-10-04 11:26:53 +02:00

58 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { isSameSchedulingProblem } from "../src/schedule-warnings";
import { type Warning, WarningCode, pushWarning } from "../src/warnings";
const loc = (offset: number) => ({ start: offset, end: offset + 10 });
function contention(trackName: string, delay: number, offset = 30): Warning {
const warnings: Warning[] = [];
pushWarning(warnings, WarningCode.TRACK_CONTENTION, {
trackName,
delay,
item: "Step in section 'Bake'",
loc: loc(offset),
});
return warnings[0]!;
}
function paradox(conflict: string, offset: number): Warning {
const warnings: Warning[] = [];
pushWarning(warnings, WarningCode.TIME_PARADOX, {
cause: "Section 'Dough'",
conflict,
loc: loc(offset),
});
return warnings[0]!;
}
describe("isSameSchedulingProblem", () => {
it("matches a contention whatever its delay", () => {
expect(
isSameSchedulingProblem(contention("oven", 15), contention("oven", 40)),
).toBe(true);
expect(
isSameSchedulingProblem(contention("oven", 15), contention("oven", 0.5)),
).toBe(true);
});
it("tells contentions on two tracks apart", () => {
expect(
isSameSchedulingProblem(contention("oven", 15), contention("oven2", 15)),
).toBe(false);
});
it("matches a time paradox on its place in the source, not its message", () => {
expect(
isSameSchedulingProblem(paradox("T-10", 4), paradox("T-25", 4)),
).toBe(true);
expect(
isSameSchedulingProblem(paradox("T-10", 4), paradox("T-10", 9)),
).toBe(false);
});
it("never matches two different codes", () => {
expect(
isSameSchedulingProblem(contention("oven", 15), paradox("T-10", 3)),
).toBe(false);
});
});