1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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")
}
}
}
}
|