-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexas_holdem_test.go
86 lines (68 loc) · 2.2 KB
/
texas_holdem_test.go
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
83
84
85
86
package poker_test
import (
"fmt"
"io/ioutil"
"testing"
"time"
poker "github.com/ljones140/golang-player-webserver"
)
func TestGame_Start(t *testing.T) {
t.Run("it schedules alerts on a game for 5 players", func(t *testing.T) {
blindAlerter := &poker.SpyBlindAlerter{}
game := poker.NewTexasHoldem(blindAlerter, dummyPlayerStore)
game.Start(5, ioutil.Discard)
cases := []poker.ScheduledAlert{
{At: 0 * time.Second, Amount: 100},
{At: 10 * time.Minute, Amount: 200},
{At: 20 * time.Minute, Amount: 300},
{At: 30 * time.Minute, Amount: 400},
{At: 40 * time.Minute, Amount: 500},
{At: 50 * time.Minute, Amount: 600},
{At: 60 * time.Minute, Amount: 800},
{At: 70 * time.Minute, Amount: 1000},
{At: 80 * time.Minute, Amount: 2000},
{At: 90 * time.Minute, Amount: 4000},
{At: 100 * time.Minute, Amount: 8000},
}
checkSchedulingCases(cases, t, blindAlerter)
})
t.Run("it schedules alert on a game for 7 players", func(t *testing.T) {
blindAlerter := &poker.SpyBlindAlerter{}
game := poker.NewTexasHoldem(blindAlerter, dummyPlayerStore)
game.Start(7, ioutil.Discard)
cases := []poker.ScheduledAlert{
{At: 0 * time.Second, Amount: 100},
{At: 12 * time.Minute, Amount: 200},
{At: 24 * time.Minute, Amount: 300},
{At: 36 * time.Minute, Amount: 400},
}
checkSchedulingCases(cases, t, blindAlerter)
})
}
func TestGame_Finish(t *testing.T) {
store := &poker.StubPlayerStore{}
game := poker.NewTexasHoldem(dummyBlindAlerter, store)
winner := "Ruth"
game.Finish(winner)
poker.AssertPlayerWin(t, store, winner)
}
func checkSchedulingCases(cases []poker.ScheduledAlert, t *testing.T, blindAlerter *poker.SpyBlindAlerter) {
for i, want := range cases {
t.Run(fmt.Sprint(want), func(t *testing.T) {
if len(blindAlerter.Alerts) <= i {
t.Fatalf("alert %d was not scheduled %v", i, blindAlerter.Alerts)
}
got := blindAlerter.Alerts[i]
assertScheduledAlert(t, got, want)
})
}
}
func assertScheduledAlert(t *testing.T, got, want poker.ScheduledAlert) {
t.Helper()
if got.Amount != want.Amount {
t.Errorf("got amount %d, want %d", got.Amount, want.Amount)
}
if got.At != want.At {
t.Errorf("got scheduled time of %v, want %v", got.At, want.At)
}
}