-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameconstructor_test.go
137 lines (122 loc) · 3.13 KB
/
gameconstructor_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package game
import (
"testing"
"github.com/minaorangina/shed/deck"
"github.com/minaorangina/shed/internal"
utils "github.com/minaorangina/shed/internal"
"github.com/minaorangina/shed/protocol"
"github.com/stretchr/testify/assert"
)
func TestNewShedNewGame(t *testing.T) {
t.Run("game with no options sets up correctly", func(t *testing.T) {
t.Log("When a new game is created")
playerInfo := fourPlayers()
game, err := NewShed(playerInfo)
utils.AssertNoError(t, err)
t.Log("Then the players are initiated correctly")
utils.AssertTrue(t, len(game.PlayerInfo) > 1)
utils.AssertTrue(t, len(game.ActivePlayers) == len(game.PlayerInfo))
utils.AssertNotEmptyString(t, game.CurrentPlayer.PlayerID)
t.Log("And the game is in the correct gameplay state")
assert.Equal(t, gameInProgress, game.gamePlay)
assert.False(t, game.GameOver())
t.Log("And players' cards are set correctly")
for _, p := range game.PlayerCards {
utils.AssertEqual(t, len(p.UnseenVisibility), 3)
}
for _, info := range playerInfo {
id := info.PlayerID
playerCards := game.PlayerCards[id]
utils.AssertEqual(t, len(playerCards.Hand), 3)
utils.AssertEqual(t, len(playerCards.Seen), 3)
utils.AssertEqual(t, len(playerCards.Unseen), 3)
}
})
}
func TestNewShedExistingGame(t *testing.T) {
shouldSucceed := []struct {
name string
gameOpts func() ShedOpts
}{
{
name: "clear deck stage: fresh",
gameOpts: func() ShedOpts {
d := deck.New()
d.Shuffle()
plrs := twoPlayers()
cards := map[string]*PlayerCards{
plrs[0].PlayerID: {
Hand: d.Deal(3),
Seen: d.Deal(3),
Unseen: d.Deal(3),
},
plrs[1].PlayerID: {
Hand: d.Deal(3),
Seen: d.Deal(3),
Unseen: d.Deal(3),
},
}
return ShedOpts{
Deck: d,
Pile: nil,
PlayerCards: cards,
Players: plrs,
FinishedPlayers: nil,
CurrentPlayer: plrs[0],
Stage: clearDeck,
ExpectedCommand: protocol.PlayHand,
}
},
},
{
name: "clear deck stage: player just played, yet to replenish",
gameOpts: func() ShedOpts {
d := deck.New()
d.Shuffle()
plrs := twoPlayers()
cards := map[string]*PlayerCards{
plrs[0].PlayerID: {
Hand: d.Deal(2),
Seen: d.Deal(3),
Unseen: d.Deal(3),
},
plrs[1].PlayerID: {
Hand: d.Deal(3),
Seen: d.Deal(3),
Unseen: d.Deal(3),
},
}
return ShedOpts{
Deck: d,
Pile: nil,
PlayerCards: cards,
Players: plrs,
FinishedPlayers: nil,
CurrentPlayer: plrs[0],
Stage: clearDeck,
ExpectedCommand: protocol.ReplenishHand,
}
},
},
}
for _, tc := range shouldSucceed {
t.Run(tc.name, func(t *testing.T) {
internal.ShouldNotPanic(t, func() {
ExistingShed(tc.gameOpts())
})
})
}
}
func TestNewShedExistingGameFailures(t *testing.T) {
tt := []struct {
name string
gameOpts func() ShedOpts
}{}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
internal.ShouldPanic(t, func() {
ExistingShed(tc.gameOpts())
})
})
}
}