// Chips the dealer took off the table on purpose. // // Starting the next hand with money still in the middle destroys it — the tool asks // first and says so afterwards. What it didn't do was remember, so the bank check saw // only that chips were gone and reported them as missing. const test = require("node:test"); const assert = require("node:assert"); const { HoldemState, Money, makeTable } = require("./load"); const table = () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2, 3], stack: 200 }); state.seats.slice(0, 4).forEach(player => { player.buyIns = 200; }); return state; }; test("a table with nothing thrown away balances as before", () => { const bank = HoldemState.bankReconciliation(table()); assert.equal(bank.balanced, true); assert.equal(bank.discarded, 0); }); test("chips that went missing are still reported", () => { // The check exists for this: cash in the box with no chips to match it. const state = table(); state.seats[0].stack = 150; const bank = HoldemState.bankReconciliation(state); assert.equal(bank.balanced, false); assert.equal(bank.difference, -50); }); test("an abandoned pot is accounted for rather than counted as missing", () => { const state = table(); state.seats[1].stack = 199; state.seats[2].stack = 198; state.seats[3].stack = 198; state.discarded = 5; const bank = HoldemState.bankReconciliation(state); assert.equal(bank.chipsInPlay, 795); assert.equal(bank.discarded, 5); assert.equal(bank.balanced, true, "the box knows exactly where that $5 went"); }); test("throwing a pot away doesn't hide a real shortfall underneath it", () => { const state = table(); state.seats[1].stack = 199; state.seats[2].stack = 198; state.seats[3].stack = 148; // $50 genuinely unaccounted for as well state.discarded = 5; const bank = HoldemState.bankReconciliation(state); assert.equal(bank.balanced, false); assert.equal(bank.difference, -50); }); test("a nonsense discarded value can't move the answer", () => { const state = table(); state.discarded = -100; assert.equal(HoldemState.bankReconciliation(state).discarded, 0); state.discarded = "not a number"; assert.equal(HoldemState.bankReconciliation(state).discarded, 0); }); test("a table saved before this existed reads as nothing thrown away", () => { const saved = JSON.stringify(table()); const parsed = JSON.parse(saved); delete parsed.discarded; const store = new Map([[HoldemState.STORAGE_KEY, JSON.stringify(parsed)]]); globalThis.localStorage = { getItem: key => (store.has(key) ? store.get(key) : null), setItem: (key, value) => store.set(key, value), removeItem: key => store.delete(key), }; const loaded = HoldemState.load(); assert.equal(loaded.discarded, 0); assert.equal(HoldemState.bankReconciliation(loaded).balanced, true); delete globalThis.localStorage; }); test("the amounts still add up the way the panel shows them", () => { const state = table(); state.seats[1].stack = 199; state.seats[2].stack = 198; state.seats[3].stack = 198; state.discarded = 5; const bank = HoldemState.bankReconciliation(state); assert.equal(Money.round(bank.chipsInPlay + bank.discarded), bank.cashIn); });