import { test } from "node:test"; import assert from "node:assert/strict"; import { pokerSpoken } from "./pokerSpoken"; const cue = (start: number, text: string) => ({ start, end: start + 3, text }); const pick = (rs: ReturnType, field: string) => rs.filter((r) => r.field === field).map((r) => [r.t, r.value]); test("players left, said in words, dated by its cue", () => { const rs = pokerSpoken([cue(339, "okay eighty five players left"), cue(3218, "we are down to fifteen players left now")]); assert.deepEqual(pick(rs, "playersLeft"), [[339, 85], [3218, 15]]); }); test("a phrase split across two cues still reads, dated by its first cue", () => { const rs = pokerSpoken([cue(10, "we have eighty five"), cue(13, "players left in this one")]); assert.deepEqual(pick(rs, "playersLeft"), [[10, 85]]); }); test("a buy-in, in dollars or words", () => { const rs = pokerSpoken([cue(3326, "this is the $2,750 buy in"), cue(5000, "the buy in is six bucks for the viewers")]); assert.deepEqual(pick(rs, "buyIn"), [[3326, 2750], [5000, 6]]); }); test("a stack said without 'thousand' beside an average said with it is scaled, and marked approx", () => { const rs = pokerSpoken([cue(6557, "the average stack is three hundred seventy three thousand"), cue(6560, "I have two hundred thirty three")]); assert.deepEqual(pick(rs, "averageStack"), [[6557, 373000]]); const stack = rs.filter((r) => r.field === "stack"); assert.deepEqual(stack.map((r) => [r.t, r.value, r.approx]), [[6560, 233000, true]]); }); test("a small stack with no average near it is left out, as is a count of something else", () => { const rs = pokerSpoken([cue(10, "I have two hundred thirty three"), cue(20, "I have 2 kings"), cue(30, "I have 500 bucks on this")]); assert.deepEqual(pick(rs, "stack"), []); }); test("an opponent's chips are not the hero's", () => { const rs = pokerSpoken([cue(5350, "he's at five hundred sixty seven thousand chips")]); assert.deepEqual(pick(rs, "stack"), []); }); test("stack in big blinds, blinds, level, first prize", () => { const rs = pokerSpoken([ cue(100, "I'm down to six big blinds"), cue(200, "blinds are fifteen hundred three thousand"), cue(300, "we're on level fourteen"), cue(400, "first place five hundred bucks"), ]); assert.deepEqual(pick(rs, "stackBB"), [[100, 6]]); assert.deepEqual(pick(rs, "bigBlind"), [[200, 3000]]); assert.deepEqual(pick(rs, "smallBlind"), [[200, 1500]]); assert.deepEqual(pick(rs, "level"), [[300, 14]]); assert.deepEqual(pick(rs, "firstPrize"), [[400, 500]]); }); test("two numbers beside 'blinds' that are not a blind pair are not read as one", () => { const rs = pokerSpoken([cue(10, "blinds are 5 50")]); assert.deepEqual(pick(rs, "bigBlind"), []); }); test("the same number said again within 30 s is one reading", () => { const rs = pokerSpoken([cue(10, "eighty five players left"), cue(20, "yeah eighty five players left"), cue(100, "eighty five players left")]); assert.deepEqual(pick(rs, "playersLeft"), [[10, 85], [100, 85]]); }); test("no cues, no readings; the text is kept for a reader", () => { assert.deepEqual(pokerSpoken([]), []); const [r] = pokerSpoken([cue(1, "eighty five players left")]); assert.equal(r.text, "eighty five players left"); }); test("calibrated phrasings: a k after a number, a buy-in said in dollars, the ASR's 'buying', a prize pool before its number", () => { const rs = pokerSpoken([ cue(10, "the average is four hundred twelve K I have three hundred eight K"), cue(20, "no it's one thousand one hundred dollars buy in"), cue(30, "tonight's buying is like four bucks"), cue(40, "two million dollars in the prize pool"), ]); assert.deepEqual(pick(rs, "averageStack"), [[10, 412000]]); assert.deepEqual(pick(rs, "stack"), [[10, 308000]]); assert.deepEqual(pick(rs, "buyIn"), [[20, 1100], [30, 4]]); assert.deepEqual(pick(rs, "prizePool"), [[40, 2000000]]); }); test("the hero's place in the field, and the field it is out of", () => { const rs = pokerSpoken([cue(10, "I'm in sixty fourth place out of seventy two people"), cue(100, "and I moved up to forty first")]); assert.deepEqual(pick(rs, "position"), [[10, 64], [100, 41]]); assert.deepEqual(pick(rs, "playersLeft"), [[10, 72]]); }); test("a stack said as a supposition is not a reading; a bare 'level' of a game is not the blind level", () => { const rs = pokerSpoken([ cue(10, "once I'm down to sixty thousand chips I shove"), cue(20, "it's not like I'm sitting on forty k"), cue(30, "I'd buy a level sixty character"), cue(40, "we're at level nine now"), ]); assert.deepEqual(pick(rs, "stack"), []); assert.deepEqual(pick(rs, "level"), [[40, 9]]); }); test("a stack said without 'thousand' is scaled by an average said up to half an hour away", () => { const rs = pokerSpoken([cue(100, "the average stack is two hundred thousand"), cue(1500, "well I've got one hundred eighty")]); assert.deepEqual(rs.filter((r) => r.field === "stack").map((r) => [r.value, r.approx]), [[180000, true]]); });