aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_felt_precision_test.go
blob: da96d71b1dbcc9fae6d01fa679e6880038800cc3 (plain)
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
package game

import (
	"strings"
	"testing"

	"thehouseoficarus/internal/casino"
)

// The felt is fixed-width art: a commission percentage must not lose its
// trailing zero (0.9 used to trim "10" down to "1").
func TestBaccaratFeltPrintsExactCommission(t *testing.T) {
	cases := map[float64]string{
		0.9:  "10% COMMISSION",
		0.8:  "20% COMMISSION",
		0.95: "5% COMMISSION",
		0.99: "1% COMMISSION",
	}
	for payout, want := range cases {
		cfg := casino.TableConfig{ID: "x", Game: casino.GameBaccarat,
			Baccarat: casino.BaccaratConfig{Variant: casino.BaccaratCommission, BankerPayout: payout}}
		art := renderBaccaratRulesFelt(cfg, "none", false)
		if !strings.Contains(art, want) {
			t.Fatalf("payout %v: missing %q in felt", payout, want)
		}
	}
}

// Bare %g prints shortest-round-trip floats (0.29 -> 28.999999999999996),
// which overruns the fixed-width box borders.
func TestBlackjackFeltPrintsRoundedShuffle(t *testing.T) {
	cfg := casino.TableConfig{ID: "x", Game: casino.GameBlackjack,
		Blackjack: casino.BlackjackConfig{ShuffleAt: 0.29}}
	art := renderBlackjackRulesFelt(cfg, "none", false)
	if !strings.Contains(art, "29% REMAINING") {
		t.Fatalf("missing rounded shuffle value: %s", art)
	}
	if strings.Contains(art, "99999") || strings.Contains(art, "000000") {
		t.Fatalf("float noise leaked into the felt: %s", art)
	}
}