diff options
Diffstat (limited to 'internal/game/render_roulette_test.go')
| -rw-r--r-- | internal/game/render_roulette_test.go | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/internal/game/render_roulette_test.go b/internal/game/render_roulette_test.go index 8d9c141..3577ec9 100644 --- a/internal/game/render_roulette_test.go +++ b/internal/game/render_roulette_test.go @@ -27,7 +27,7 @@ func TestRouletteArtModes(t *testing.T) { s := &casino.RouletteSnapshot{DoubleZero: double, Wheel: wheelOrder} for _, phase := range []string{"betting", "playing", "result"} { s.Phase = phase - s.Pockets = [3]string{"26", "0", "32"} + s.Pockets = [5]string{"25", "26", "0", "32", "15"} art := renderRouletteSnapshot(s, mode, unicode, 7) plain := plainRoulette(art) if mode == "xterm256" && unicode && double { @@ -50,15 +50,19 @@ func TestRouletteArtModes(t *testing.T) { } } if mode != "none" { - for _, bg := range []int{0, 1, 2} { + pocketBgs := []int{0, 1, 2} + if phase == "playing" { + pocketBgs = []int{rouletteWheelBlack, 1, 2} + } + for _, bg := range pocketBgs { if !strings.Contains(art, color.BgCode(mode, bg)) { - t.Fatalf("missing pocket background %d", bg) + t.Fatalf("phase=%s missing pocket background %d", phase, bg) } } if !strings.Contains(art, color.FgCode(mode, 15)) || !strings.Contains(art, color.StyleCode("bold")) { t.Fatal("missing bold white text") } - if !strings.HasSuffix(art, color.Reset) { + if !strings.HasSuffix(strings.TrimRight(art, "\n"), color.Reset) { t.Fatal("art leaves terminal colored") } } @@ -117,14 +121,14 @@ func TestRouletteArtModes(t *testing.T) { } } } else { - for _, bg := range []int{0, 1, 2} { + for _, bg := range []int{rouletteWheelBlack, 1, 2} { if !strings.Contains(wheelArt, color.BgCode(mode, bg)) { t.Fatalf("wheel missing pocket background %d", bg) } } } - result := plainRoulette(renderRouletteResult([3]string{"1", "00", "27"}, mode, unicode, 7)) + result := plainRoulette(renderRouletteResult([5]string{"36", "1", "00", "27", "13"}, mode, unicode, 7)) for _, banned := range []string{"PREV", "BALL", "NEXT", "WINNER"} { if strings.Contains(result, banned) { t.Fatalf("result prose %q should be removed:\n%s", banned, result) @@ -267,7 +271,7 @@ func TestRouletteRacetrackPanel(t *testing.T) { func TestRouletteResultSizesAndNeighbors(t *testing.T) { for _, unicode := range []bool{false, true} { for _, size := range []int{1, 5, 7, 9} { - art := plainRoulette(renderRouletteResult([3]string{"1", "00", "27"}, "xterm256", unicode, size)) + art := plainRoulette(renderRouletteResult([5]string{"36", "1", "00", "27", "13"}, "xterm256", unicode, size)) lines := strings.Split(art, "\n") height := max(5, cardRenderSize(unicode, size)) width := height + 2 @@ -275,13 +279,18 @@ func TestRouletteResultSizesAndNeighbors(t *testing.T) { t.Fatalf("size=%d, height=%d want %d", size, len(lines), height) } for _, line := range lines { - if color.VisibleLen(line) != 3*width+2 { + if color.VisibleLen(line) != 5*width+4 { t.Fatalf("unequal pocket widths: %q", line) } } - center := []rune(lines[1]) - if !strings.Contains(string(center[:width]), "1") || !strings.Contains(string(center[width+1:2*width+1]), "00") || !strings.Contains(string(center[2*width+2:]), "27") { - t.Fatal("wrong pocket order", art) + top := plainRoulette(strings.Split(art, "\n")[1]) + last := -1 + for _, pocket := range []string{"36", "1", "00", "27", "13"} { + at := strings.Index(top, pocket) + if at < 0 || at < last { + t.Fatalf("wrong pocket order for %s: %q", pocket, top) + } + last = at } ball := "o" if unicode { @@ -299,7 +308,7 @@ func TestRouletteResultSizesAndNeighbors(t *testing.T) { // bottom row only when color is off. cardRenderSize caps non-Unicode cards at // five rows, so the full nine-row shape is exercised through Unicode. func TestRouletteResultLayout(t *testing.T) { - pockets := [3]string{"1", "10", "27"} // RED, BLACK, RED + pockets := [5]string{"1", "10", "27", "2", "3"} // RED, BLACK, RED, BLACK, RED for _, tc := range []struct { unicode bool size int @@ -537,3 +546,37 @@ func TestRouletteRacetrackSections(t *testing.T) { } } } + +// TestRouletteWheelBlackAndSpacing locks in the visual tweaks: the spinning +// wheel uses a visible dark blue for its black pockets while the betting board +// keeps true black, and the wheel and result graphics get blank line framing. +func TestRouletteWheelBlackAndSpacing(t *testing.T) { + wheelArt := renderRouletteWheel(casino.WheelOrder(false), "xterm256", true) + if !strings.Contains(wheelArt, color.BgCode("xterm256", rouletteWheelBlack)) { + t.Fatal("spinning wheel lost its dark blue black pockets") + } + if strings.Contains(wheelArt, color.BgCode("xterm256", 0)) { + t.Fatal("spinning wheel should not use pure black") + } + board := renderRouletteLayout(false, false, "xterm256", true) + if !strings.Contains(board, color.BgCode("xterm256", 0)) { + t.Fatal("betting board should keep true black pockets") + } + + for _, tc := range []struct { + phase string + want string + }{ + {"playing", renderRouletteWheel(casino.WheelOrder(false), "none", true)}, + {"result", renderRouletteResult([5]string{"25", "26", "0", "32", "15"}, "none", true, 7)}, + } { + s := &casino.RouletteSnapshot{Wheel: casino.WheelOrder(false), Phase: tc.phase, Pockets: [5]string{"25", "26", "0", "32", "15"}} + art := renderRouletteSnapshot(s, "none", true, 7) + if !strings.HasPrefix(art, "\n") || !strings.HasSuffix(art, "\n") { + t.Fatalf("phase=%s: graphic is not blank-line framed: %q", tc.phase, art) + } + if !strings.Contains(art, tc.want) { + t.Fatalf("phase=%s: framed art lost the graphic", tc.phase) + } + } +} |
