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