diff options
Diffstat (limited to 'internal/game/render_roulette_test.go')
| -rw-r--r-- | internal/game/render_roulette_test.go | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/internal/game/render_roulette_test.go b/internal/game/render_roulette_test.go index 1cb75ce..d992abf 100644 --- a/internal/game/render_roulette_test.go +++ b/internal/game/render_roulette_test.go @@ -64,14 +64,14 @@ func TestRouletteArtModes(t *testing.T) { } } - layoutArt := renderRouletteLayout(double, mode, unicode) + layoutArt := renderRouletteLayout(double, false, mode, unicode) layout := plainRoulette(layoutArt) rows := strings.Split(layout, "\n") if double { - if !strings.Contains(string([]rune(rows[2])[:7]), "0") || !strings.Contains(string([]rune(rows[6])[:7]), "00") { + if !strings.Contains(string([]rune(rows[1])[:7]), "0") || !strings.Contains(string([]rune(rows[5])[:7]), "00") { t.Fatal("double zero not left of grid", layout) } - } else if !strings.Contains(string([]rune(rows[4])[:7]), "0") { + } else if !strings.Contains(string([]rune(rows[3])[:7]), "0") { t.Fatal("zero not left of grid", layout) } for _, target := range []string{"1to12", "13to24", "25to36", "row1", "row2", "row3", "red", "black", "odd", "even", "low", "high"} { @@ -157,12 +157,12 @@ func TestRouletteWheelGreenPockets(t *testing.T) { // each outside-bet divider. func TestRouletteLayoutConnections(t *testing.T) { for _, double := range []bool{false, true} { - art := plainRoulette(renderRouletteLayout(double, "xterm256", true)) + art := plainRoulette(renderRouletteLayout(double, false, "xterm256", true)) rows := strings.Split(art, "\n") - // rows[7] is the numbered grid's bottom edge, directly above the dozen + // rows[6] is the numbered grid's bottom edge, directly above the dozen // labels. The dozen boundaries and the grid/row-lane joint cross; the // row-bet lane closes with a bottom-right corner. - gridBottom := []rune(rows[7]) + gridBottom := []rune(rows[6]) for _, col := range []int{6, 26, 46, 66} { if gridBottom[col] != '┼' { t.Fatalf("double=%v: grid bottom col %d = %q, want ┼:\n%s", double, col, gridBottom[col], art) @@ -173,15 +173,15 @@ func TestRouletteLayoutConnections(t *testing.T) { } // The row-bet lane is boxed: its separators cross at the grid edge and // close on the right. - for _, idx := range []int{3, 5} { + for _, idx := range []int{2, 4} { sep := []rune(rows[idx]) if sep[66] != '┼' || sep[73] != '┤' { t.Fatalf("double=%v: row lane separator %q lacks box joints:\n%s", double, rows[idx], art) } } - // rows[9] is the dozen boxes' bottom edge: tees point down where the + // rows[8] is the dozen boxes' bottom edge: tees point down where the // even-money dividers sit and crosses pass the dozen dividers through. - dozenBottom := []rune(rows[9]) + dozenBottom := []rune(rows[8]) wantDozen := map[int]rune{6: '├', 16: '┬', 26: '┼', 36: '┬', 46: '┼', 56: '┬', 66: '┤'} for col, want := range wantDozen { if dozenBottom[col] != want { @@ -204,20 +204,20 @@ func TestRouletteLayoutConnections(t *testing.T) { // Unicode mode while ASCII mode stays square. func TestRouletteZeroPanel(t *testing.T) { for _, double := range []bool{false, true} { - colored := renderRouletteLayout(double, "xterm256", true) + colored := renderRouletteLayout(double, false, "xterm256", true) rows := strings.Split(colored, "\n") - // Interior rows 2-6: top numbered row, separator, middle, separator, + // Interior rows 1-5: top numbered row, separator, middle, separator, // bottom numbered row. Each must contain the green background. - for row := 2; row <= 6; row++ { + for row := 1; row <= 5; row++ { if !strings.Contains(rows[row], color.BgCode("xterm256", 2)) { t.Fatalf("double=%v: zero lane row %d is not green:\n%s", double, row, plainRoulette(colored)) } } plainRows := strings.Split(plainRoulette(colored), "\n") - if !strings.HasPrefix(plainRows[1], "╭") || !strings.HasPrefix(plainRows[7], "╰") { + if !strings.HasPrefix(plainRows[0], "╭") || !strings.HasPrefix(plainRows[6], "╰") { t.Fatalf("double=%v: zero panel corners are not rounded:\n%s", double, plainRoulette(colored)) } - ascii := plainRoulette(renderRouletteLayout(double, "none", false)) + ascii := plainRoulette(renderRouletteLayout(double, false, "none", false)) for _, r := range ascii { if r > 127 { t.Fatalf("double=%v: non-ASCII rune %q in ASCII mode", double, r) @@ -226,6 +226,44 @@ func TestRouletteZeroPanel(t *testing.T) { } } +// TestRouletteRacetrackPanel checks that an enabled racetrack adds the call-bet +// panel above the board, names all four call bets and the neighbours bet, and +// keeps the same width and ASCII/Unicode guarantees as the board. +func TestRouletteRacetrackPanel(t *testing.T) { + for _, mode := range []string{"none", "ansi", "xterm256"} { + for _, unicode := range []bool{false, true} { + art := renderRouletteLayout(false, true, mode, unicode) + plain := plainRoulette(art) + for _, want := range []string{"Voisins du Zero", "Tiers du Cylindre", "Orphelins", "Zero Spiel", "Neighbors (9)"} { + if !strings.Contains(plain, want) { + t.Fatalf("mode=%s unicode=%v: missing %q:\n%s", mode, unicode, want, plain) + } + } + for _, line := range strings.Split(art, "\n") { + if color.VisibleLen(line) > 78 { + t.Fatalf("mode=%s unicode=%v: line exceeds terminal width: %q", mode, unicode, plainRoulette(line)) + } + if !unicode { + for _, r := range plainRoulette(line) { + if r > 127 { + t.Fatalf("mode=%s: non-ASCII rune %q in ASCII mode", mode, r) + } + } + } + } + } + } + // The panel comes from the snapshot flag, and a plain board omits it. + snap := &casino.RouletteSnapshot{Phase: "betting", Wheel: casino.WheelOrder(false), Racetrack: true} + if !strings.Contains(plainRoulette(renderRouletteSnapshot(snap, "none", true, 7)), "Voisins du Zero") { + t.Fatal("racetrack snapshot did not draw the panel") + } + snap.Racetrack = false + if strings.Contains(plainRoulette(renderRouletteSnapshot(snap, "none", true, 7)), "Voisins du Zero") { + t.Fatal("plain snapshot drew the racetrack panel") + } +} + func TestRouletteResultSizesAndNeighbors(t *testing.T) { for _, unicode := range []bool{false, true} { for _, size := range []int{1, 5, 7, 9} { |
