diff options
| author | historia <[not public]> | 2026-10-03 01:38:58 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-03 01:38:58 -0400 |
| commit | 0ec8f3692960a064616e630c914058298b22897b (patch) | |
| tree | 2b51327eb66be7df8fdcd7c12cc306ca6fa84891 /internal/game/roulette_animation_test.go | |
| parent | 82e571d227feeafd0af4011e701ce26b99c5e3d9 (diff) | |
| download | thehouseoficarus-0ec8f3692960a064616e630c914058298b22897b.tar.gz | |
feat: replaced roulette wheel graphic with line-by-line 'spin'
Diffstat (limited to 'internal/game/roulette_animation_test.go')
| -rw-r--r-- | internal/game/roulette_animation_test.go | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/internal/game/roulette_animation_test.go b/internal/game/roulette_animation_test.go new file mode 100644 index 0000000..96f14bb --- /dev/null +++ b/internal/game/roulette_animation_test.go @@ -0,0 +1,102 @@ +package game + +import ( + "strings" + "testing" + "thehouseoficarus/internal/casino" + "thehouseoficarus/internal/color" + "thehouseoficarus/internal/net" +) + +func TestRouletteSpinOutputHasNoPromptOrBlankLines(t *testing.T) { + g, sess, conn := uxCasinoGame(t) + g.Hub = net.NewHub() + g.Hub.EnterRoom(sess, 1) + sess.Player.Options = map[string]any{"color": "none", "unicode": true} + g.emitCasinoEvents(g.Casino.Join(1, casino.TableConfig{ID: "roulette", Game: casino.GameRoulette}, sess.Player.Name)) + sess.ClearPrompt() + conn.data = nil + g.executeBet(sess, []string{"2", "on", "2"}, "bet 2 on 2") + g.writePrompt(sess) // the command queue's post-command prompt + text := strings.ReplaceAll(string(conn.data), "\r\n", "\n") + if !strings.HasSuffix(text, "The roulette wheel spins...\n") { + t.Fatalf("prompt after spin announcement: %q", text) + } + before := len(conn.data) + g.reprompt(sess) + if len(conn.data) != before { + t.Fatal("reprompt interrupted animation") + } + for tick := 1; tick <= 5; tick++ { + conn.data = nil + g.CasinoTick() + text = strings.ReplaceAll(string(conn.data), "\r\n", "\n") + if strings.Count(text, "\n") != 1 || !strings.HasSuffix(text, "\n") || color.VisibleLen(strings.TrimSuffix(text, "\n")) != 10 { + t.Fatalf("tick %d: expected exactly one strip: %q", tick, text) + } + if tick == 5 && strings.Count(text, ".") != 1 { + t.Fatal("final strip missing ball") + } + } + for tick := 6; tick <= 7; tick++ { + conn.data = nil + g.CasinoTick() + if len(conn.data) != 0 { + t.Fatalf("tick %d: expected silence: %q", tick, conn.data) + } + } + g.CasinoTick() + if !strings.Contains(string(conn.data), "The ball lands in") || g.rouletteSpinning(sess) { + t.Fatal("result did not end animation") + } + sess.ClearPrompt() + conn.data = nil + g.writePrompt(sess) + if len(conn.data) == 0 { + t.Fatal("prompt did not resume") + } +} + +func TestRouletteSpinStrip(t *testing.T) { + for _, mode := range []string{"none", "ansi", "xterm256"} { + for _, unicode := range []bool{false, true} { + for _, ball := range []int{-1, 5} { + s := &casino.RouletteSnapshot{Phase: "playing", SpinFrame: 1, BallPosition: ball, SpinPockets: [10]string{"1", "2", "1", "2", "1", "26", "0", "32", "15", "19"}} + art := renderRouletteSnapshot(s, mode, unicode, 7) + plain := plainRoulette(art) + dots := 0 + if ball >= 0 { + dots = 1 + } + if color.VisibleLen(art) != 10 || strings.Count(plain, ".") != dots || strings.Contains(plain, "\n") { + t.Fatalf("bad strip: %q", art) + } + block := "█" + if !unicode { + block = "#" + } + if strings.Count(plain, block) != 10-dots { + t.Fatalf("bad blocks: %q", plain) + } + if mode != "none" && ball >= 0 && !strings.Contains(art, roulettePaint(mode, ".", 8)) { + t.Fatalf("26 ball is not black: %q", art) + } + } + for _, pocket := range []string{"0", "00", "26", "32"} { + s := &casino.RouletteSnapshot{Phase: "playing", SpinFrame: 5, BallPosition: 4} + s.SpinPockets[4] = pocket + art := renderRouletteSnapshot(s, mode, unicode, 7) + fg, _ := roulettePocketColor(pocket) + if fg == 0 { + fg = 8 + } + if !strings.Contains(art, roulettePaint(mode, ".", fg)) { + t.Fatalf("wrong ball color for %s: %q", pocket, art) + } + } + } + } + if got := renderRouletteSnapshot(&casino.RouletteSnapshot{Phase: "playing"}, "none", true, 7); got != "" { + t.Fatalf("old wheel still shown: %q", got) + } +} |
