import { expect, test } from "bun:test"; import { calibrate, normalize, verdictFor, verdictOnItself } from "./oracle.ts"; test("the same question always gets the same verdict", () => { const first = verdictFor("Should I ship it on Friday?"); const again = verdictFor("Should I ship it on Friday?"); expect(again).toEqual(first); }); test("shouting, spacing and punctuation are the same question", () => { const plain = verdictFor("will it rain"); expect(verdictFor("Will it rain?")).toEqual(plain); expect(verdictFor(" WILL IT RAIN!!! ")).toEqual(plain); expect(normalize(" Will it RAIN? ")).toBe("will it rain"); }); test("different questions get different verdicts", () => { // Not a guarantee for every pair — a 16-stance table collides — but these // two must not read as one question. expect(verdictFor("should I quit")).not.toEqual(verdictFor("should I stay")); }); test("it never admits to a coin flip", () => { for (const q of ["a", "b", "c", "should I?", "是否", "x".repeat(280)]) { const { confidence } = verdictFor(q); expect(confidence).toBeGreaterThanOrEqual(52); expect(confidence).toBeLessThanOrEqual(98); } }); test("scoring counts only what a person judged", () => { const c = calibrate([ { confidence: 90, outcome: "right" }, { confidence: 70, outcome: "wrong" }, { confidence: 99, outcome: "unjudged" }, ]); expect(c.judged).toBe(2); expect(c.right).toBe(1); expect(c.accuracy).toBe(50); expect(c.claimed).toBe(80); expect(c.gap).toBe(30); }); test("nothing judged is not evidence either way", () => { const c = calibrate([{ confidence: 98, outcome: "unjudged" }]); expect(c.judged).toBe(0); expect(c.accuracy).toBeUndefined(); expect(verdictOnItself(c)).toContain("Nothing judged yet"); }); test("it calls its own bluster", () => { const bluster = calibrate( Array.from({ length: 6 }, (_, i) => ({ confidence: 95, outcome: i === 0 ? "right" : "wrong", })), ); expect(verdictOnItself(bluster)).toContain("talks a better game"); });