// node --test tests/ const test = require("node:test"); const assert = require("node:assert"); const path = require("path"); const G = require("../../core/graph"); // the bot importer's output on tests/fixtures/bot (the importer is Python now: tests/collection/test_bot.py checks // that it still produces exactly this file) const { scenes, trajectories } = require(path.join(__dirname, "../fixtures/bot/expected.json")); test("crosswalk maps bot choices to form variables", () => { const { vars } = G.trajectoryVariables(trajectories[0]); assert.strictEqual(vars.company, "Alone"); assert.strictEqual(vars.direction, "Center"); assert.strictEqual(vars.outcome, "Incinerated"); const v2 = G.trajectoryVariables(trajectories[1]).vars; assert.strictEqual(v2.company, "1 Squadmate"); assert.strictEqual(v2.outcome_color, "Green"); }); test("variable graph counts by source", () => { const recs = trajectories.map((t) => ({ source: "bot", vars: G.trajectoryVariables(t).vars })); recs.push({ source: "form", vars: { company: "Alone", direction: "Center", outcome: "Bonded", outcome_color: "Blue" } }); const g = G.buildVariableGraph(recs); const e = g.edges.find((x) => x.from === "company=Alone" && x.to === "direction=Center"); assert.deepStrictEqual(e.bySource, { bot: 1, form: 1 }); assert.ok(Math.abs(e.p.mean - 2.5 / 3) < 1e-12); }); test("scene graph marks chance, burns and untested options", () => { const g = G.buildSceneGraph(scenes, trajectories); const start = Object.values(g).find((n) => Object.values(n.options).some((o) => /alone/i.test(o.text))); assert.strictEqual(Object.values(start.options).every((o) => o.n === 1), true); const dragon = Object.values(g).find((n) => Object.values(n.options).some((o) => /hide behind/i.test(o.text))); const hide = Object.values(dragon.options).find((o) => /hide/i.test(o.text)); const respect = Object.values(dragon.options).find((o) => /respect/i.test(o.text)); assert.strictEqual(hide.to.BURNED, 1); assert.strictEqual(respect.untested, true); }); test("Beta credible interval", () => { const p = G.betaPosterior(0, 4); assert.ok(p.lo >= 0 && p.hi < 0.5 && p.mean === 0.1); }); // every route choice the bot has seen maps onto a column: tests/collection/test_collection.py (Bot)