aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_craps_dice_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-02 17:51:46 -0400
committerhistoria <[not public]>2026-10-02 17:51:46 -0400
commitcac16d1725c46c82a2e62b84c93f7090b2ce0746 (patch)
treee54f6624bdeb47421587656757ef3ce4fd7ebb3f /internal/game/render_craps_dice_test.go
parent4f40f116ba884111c9a66849e620ff9fbc67530a (diff)
downloadthehouseoficarus-cac16d1725c46c82a2e62b84c93f7090b2ce0746.tar.gz
feat: craps table color improvements, die improvements
Diffstat (limited to 'internal/game/render_craps_dice_test.go')
-rw-r--r--internal/game/render_craps_dice_test.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/internal/game/render_craps_dice_test.go b/internal/game/render_craps_dice_test.go
new file mode 100644
index 0000000..e691fd5
--- /dev/null
+++ b/internal/game/render_craps_dice_test.go
@@ -0,0 +1,82 @@
+package game
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "thehouseoficarus/internal/casino"
+ "thehouseoficarus/internal/color"
+)
+
+func TestCrapsDiceTilesAndFallbacks(t *testing.T) {
+ for _, mode := range []string{"xterm256", "ansi", "none", ""} {
+ for _, unicode := range []bool{true, false} {
+ for a := 1; a <= 6; a++ {
+ for b := 0; b <= 6; b++ {
+ art := renderCrapsDice([2]int{a, b}, mode, unicode)
+ plain := plainRoulette(art)
+ rows := strings.Split(strings.TrimSuffix(plain, "\n"), "\n")
+ if len(rows) != 5 {
+ t.Fatal("tile height", rows)
+ }
+ width := 9 // two-column indent and one seven-column die
+ if b != 0 {
+ width += 10
+ }
+ for i, row := range rows {
+ if i == 2 {
+ row = strings.TrimSuffix(row, fmt.Sprintf(" Total: %d", a+b))
+ }
+ if color.VisibleLen(row) != width {
+ t.Fatalf("uneven dice: %q", plain)
+ }
+ }
+ pip := "●"
+ if !unicode {
+ pip = "o"
+ for _, r := range plain {
+ if r > 127 {
+ t.Fatal("Unicode in ASCII fallback")
+ }
+ }
+ }
+ if strings.Count(strings.ReplaceAll(plain, "Total:", ""), pip) != a+b {
+ t.Fatal("incorrect pips", a, b, plain)
+ }
+ if mode == "none" || mode == "" {
+ if strings.Contains(art, "\x1b") || !strings.Contains(plain, "+-----+") {
+ t.Fatal("missing monochrome outline", art)
+ }
+ } else {
+ if !strings.Contains(art, color.BgCode(mode, 15)) || !strings.Contains(art, color.FgCode(mode, 0)) {
+ t.Fatal("missing black-on-white face", art)
+ }
+ if unicode && (!strings.Contains(plain, "▄▄▄▄▄▄▄") || !strings.Contains(plain, "▀▀▀▀▀▀▀")) {
+ t.Fatal("missing block caps", art)
+ }
+ }
+ }
+ }
+ }
+ }
+ for _, dice := range [][2]int{{0, 0}, {-1, 2}, {7, 1}, {1, -1}, {1, 7}} {
+ if renderCrapsDice(dice, "xterm256", true) != "" {
+ t.Fatal("rendered invalid dice", dice)
+ }
+ }
+}
+
+func TestHighPointFeltIncludesSevenPoint(t *testing.T) {
+ for n := 4; n <= 10; n++ {
+ art := plainRoulette(renderHighPointFelt(&casino.CrapsSnapshot{Point: n}, "none", true))
+ if strings.Count(art, "ON ") != 1 {
+ t.Fatalf("point %d missing its puck:\n%s", n, art)
+ }
+ for _, row := range strings.Split(strings.TrimSuffix(art, "\n"), "\n") {
+ if color.VisibleLen(row) != crapsCanvasWidth {
+ t.Fatal("felt width changed")
+ }
+ }
+ }
+}