aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/slots_test.go
blob: 22e39bfa143d6429f4446c627227eab51f191f5a (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
42
43
44
package casino

import "testing"

func TestCalculateRTPUsesLongestWayOnly(t *testing.T) {
	profile := SlotProfile{
		Rows: 3, Reels: 5, Ways: 243,
		Symbols:         []SlotSymbol{{ID: "x", Weight: 1, Payout: map[int]float64{3: 1, 4: 2, 5: 3}}},
		FreeSpinTrigger: "scatter", FreeSpinCount: 8,
	}
	if got := CalculateRTP(profile); got != 3 {
		t.Fatalf("RTP = %v, want 3", got)
	}
}

func TestValidateRTP(t *testing.T) {
	profile := SlotProfile{Rows: 3, Reels: 5, Ways: 243, TargetRTP: 3,
		Symbols: []SlotSymbol{{ID: "x", Weight: 1, Payout: map[int]float64{5: 3}}}}
	if err := ValidateRTP(profile, 0.000001); err != nil {
		t.Fatal(err)
	}
}

func TestScaleToRTP(t *testing.T) {
	profile := ScaleToRTP(DefaultHuffAndPuffProfile(), 0.97)
	if err := ValidateRTP(profile, 0.000000001); err != nil {
		t.Fatal(err)
	}
}

func TestEvaluateSlotReportsWinningWays(t *testing.T) {
	profile := SlotProfile{Rows: 3, Reels: 5, Ways: 243,
		Symbols: []SlotSymbol{{ID: "x", Weight: 1, Payout: map[int]float64{5: 2}}}}
	grid := [3][5]string{}
	for row := range grid {
		for reel := range grid[row] {
			grid[row][reel] = "x"
		}
	}
	payout, wins := evaluateSlot(grid, 10, profile)
	if payout != 20 || len(wins) != 1 || wins[0].Ways != 243 || wins[0].Length != 5 {
		t.Fatalf("payout=%v wins=%+v", payout, wins)
	}
}