From cac16d1725c46c82a2e62b84c93f7090b2ce0746 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 2 Oct 2026 17:51:46 -0400 Subject: feat: craps table color improvements, die improvements --- internal/game/render_craps_dice_test.go | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 internal/game/render_craps_dice_test.go (limited to 'internal/game/render_craps_dice_test.go') 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") + } + } + } +} -- cgit v1.2.3