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") } } } }