-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
69 lines (54 loc) · 1.32 KB
/
testing.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
package poker
import (
"fmt"
"io"
"testing"
"time"
)
type StubPlayerStore struct {
Scores map[string]int
WinCalls []string
League []Player
}
func (s *StubPlayerStore) GetPlayerScore(name string) int {
score := s.Scores[name]
return score
}
func (s *StubPlayerStore) RecordWin(name string) {
s.WinCalls = append(s.WinCalls, name)
}
func (s *StubPlayerStore) GetLeague() League {
return s.League
}
func AssertPlayerWin(t testing.TB, store *StubPlayerStore, winner string) {
t.Helper()
if len(store.WinCalls) != 1 {
t.Fatalf("got %d calls to RecordWin want %d", len(store.WinCalls), 1)
}
if store.WinCalls[0] != winner {
t.Errorf("did not store correct winner got %q want %q", store.WinCalls[0], winner)
}
}
type ScheduledAlert struct {
At time.Duration
Amount int
}
func (s ScheduledAlert) String() string {
return fmt.Sprintf("%d chips at %v", s.Amount, s.At)
}
type SpyBlindAlerter struct {
Alerts []ScheduledAlert
}
func (s *SpyBlindAlerter) ScheduleAlertAt(at time.Duration, amount int, to io.Writer) {
s.Alerts = append(s.Alerts, ScheduledAlert{at, amount})
}
type GameSpy struct {
StartCalledWith int
FinishCalledWith string
}
func (g *GameSpy) Start(numberOfPlayers int, to io.Writer) {
g.StartCalledWith = numberOfPlayers
}
func (g *GameSpy) Finish(winner string) {
g.FinishCalledWith = winner
}