functional

This commit is contained in:
2026-09-17 01:19:19 -04:00
commit 3d4d75fdfb
19 changed files with 3257 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
import { describe, it, expect } from "vitest";
import rawConfig from "./config.json";
import { loadConfig } from "./configLoader";
import { estimate } from "./engine";
import { parseISODate } from "./dates";
describe("real config sanity", () => {
const result = loadConfig(rawConfig);
it("loads the shipped config without errors", () => {
expect(result.ok).toBe(true);
});
it("produces sensible Green-plan numbers at the halfway point", () => {
if (!result.ok) throw new Error("config failed to load");
const config = result.config;
// Roughly mid-semester target.
const r = estimate(config, {
selectedPlanId: "green",
targetDate: parseISODate("2026-10-18")!,
activeMissingPeriodIds: new Set(),
extraExcludedDays: 0,
});
// Green = 210 blocks / 500 flex over ~112 days (Aug 24 -> Dec 13).
expect(r.totalActiveDays).toBe(112);
// per-week block rate ~ 210/112*7 = 13.125
expect(r.perWeekMealBlocks).toBeCloseTo(13.125, 2);
// consumed + remaining conserves the total
expect(r.consumedMealBlocks + r.remainingMealBlocks).toBeCloseTo(210);
expect(r.consumedFlexDollars + r.remainingFlexDollars).toBeCloseTo(500);
// partway through, consumption is strictly between 0 and total
expect(r.consumedMealBlocks).toBeGreaterThan(0);
expect(r.consumedMealBlocks).toBeLessThan(210);
});
it("checking a break reduces total active days", () => {
if (!result.ok) throw new Error("config failed to load");
const config = result.config;
const base = estimate(config, {
selectedPlanId: "green",
targetDate: parseISODate("2026-12-13")!,
activeMissingPeriodIds: new Set(),
extraExcludedDays: 0,
});
const withBreak = estimate(config, {
selectedPlanId: "green",
targetDate: parseISODate("2026-12-13")!,
activeMissingPeriodIds: new Set(["thanksgiving"]),
extraExcludedDays: 0,
});
expect(withBreak.totalActiveDays).toBeLessThan(base.totalActiveDays);
// Per-week rate rises because the same total spreads over fewer days.
expect(withBreak.perWeekMealBlocks).toBeGreaterThan(base.perWeekMealBlocks);
});
});