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
|
package casino
import "testing"
// TestTableConfigRejectsAbsurdMultipliers: authored payout multipliers are
// bounded so a typo cannot silently create an absurd table (and so the
// MulPayout overflow backstop is not the only line of defence).
func TestTableConfigRejectsAbsurdMultipliers(t *testing.T) {
for name, c := range map[string]TableConfig{
"blackjack payout": {ID: "t", Game: GameBlackjack, Blackjack: BlackjackConfig{BlackjackPayout: 15}},
"insurance payout": {ID: "t", Game: GameBlackjack, Blackjack: BlackjackConfig{InsurancePayout: 15}},
"tie payout": {ID: "t", Game: GameBaccarat, Baccarat: BaccaratConfig{TiePayout: 100}},
"banker payout": {ID: "t", Game: GameBaccarat, Baccarat: BaccaratConfig{BankerPayout: 1.5}},
} {
t.Run(name, func(t *testing.T) {
if c.Validate() == nil {
t.Fatalf("accepted an absurd payout multiplier: %+v", c)
}
})
}
// The shipped/default values remain valid.
if err := (TableConfig{ID: "t", Game: GameBaccarat}).Validate(); err != nil {
t.Fatalf("default baccarat table rejected: %v", err)
}
if err := (TableConfig{ID: "t", Game: GameBlackjack}).Validate(); err != nil {
t.Fatalf("default blackjack table rejected: %v", err)
}
}
// TestSlotProfileRejectsDuplicateSymbol: a duplicated id would pay that win
// twice because evaluateSlot matches symbols by id.
func TestSlotProfileRejectsDuplicateSymbol(t *testing.T) {
p := DefaultHuffAndPuffProfile()
p.Symbols = append(p.Symbols, p.Symbols[0])
if err := p.Validate(); err == nil {
t.Fatal("accepted a duplicate slot symbol id")
}
}
// TestSlotProfileRejectsZeroWeight: with no total reel weight weightedSymbol
// can never pick a symbol.
func TestSlotProfileRejectsZeroWeight(t *testing.T) {
p := DefaultHuffAndPuffProfile()
for i := range p.Symbols {
p.Symbols[i].Weight = 0
}
if err := p.Validate(); err == nil {
t.Fatal("accepted a profile with no reel weight")
}
}
// TestSlotProfileRejectsOverlongSymbol: the renderer pads to a fixed 7-cell
// width, so a longer id makes the padding negative and panics.
func TestSlotProfileRejectsOverlongSymbol(t *testing.T) {
p := DefaultHuffAndPuffProfile()
p.Symbols[0].ID = "way-too-long"
if err := p.Validate(); err == nil {
t.Fatal("accepted a symbol id longer than the reel width")
}
}
|