-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_playerName_test.go
152 lines (117 loc) · 3.95 KB
/
test_playerName_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"strings"
"testing"
"github.com/gin-gonic/gin"
)
//////////////////////////////////////////////////////////////////////////////////////////
// TESTS
//////////////////////////////////////////////////////////////////////////////////////////
func TestAllHumanPlayersSameName(t *testing.T) {
table, _ := createTestTable(0, 0)
names := [...]string{"aaaaaaaa", "abaaaaaa", "aabaaaaa", "aaabaaaa", "aaaabaaa", "aaaaabaa"}
newNames := [...]string{"aaaaaaaa", "abaaaaaa", "aabaaa z", "aaabaa y", "aaaaba x", "aaaaab w"}
players := make([]string, 6)
for i := 0; i < 6; i++ {
players[i] = "/?player=" + names[i] + table
}
// Each player joines in turn
for i := 0; i < 6; i++ {
state := c(players[i], apiState).(*GameState)
// Spec's state should show round = 1
if !strings.EqualFold(state.Players[0].Name, newNames[i]) {
t.Fatal("Expect player", i+1, "name", state.Players[0].Name, "to be "+newNames[i])
}
}
}
func TestGameEndMessageWith1Winner(t *testing.T) {
_, players := createTestTable(0, 4)
// 4 Players join game to max out server with bots
for _, player := range players {
c(player, apiState)
}
// All players ready up
for _, player := range players {
c(player, apiReady)
}
// Start game with state call of first player
c(players[0], apiState)
// Play out game to with single winner
state := c(players[0]+"&skipToEnd=1", apiState).(*GameState)
// Expect game to be overxw
if !strings.HasPrefix(state.Prompt, "p1 won") {
t.Fatal("Expect game over message to match:", state.Prompt)
}
}
func TestGameEndMessageWith2WayTie(t *testing.T) {
_, players := createTestTable(0, 4)
// 4 Players join game to max out server with bots
for _, player := range players {
c(player, apiState)
}
// All players ready up
for _, player := range players {
c(player, apiReady)
}
// Start game with state call of first player
c(players[0], apiState)
// Play out game to with single winner
state := c(players[0]+"&skipToEnd=2", apiState).(*GameState)
// Expect game to be overxw
if !strings.HasPrefix(state.Prompt, "p1 and p2 tied") {
t.Fatal("Expect game over message to match:", state.Prompt)
}
}
func TestGameEndMessageWith3WayTie(t *testing.T) {
_, players := createTestTable(0, 4)
// 4 Players join game to max out server with bots
for _, player := range players {
c(player, apiState)
}
// All players ready up
for _, player := range players {
c(player, apiReady)
}
// Start game with state call of first player
c(players[0], apiState)
// Play out game to with single winner
state := c(players[0]+"&skipToEnd=3", apiState).(*GameState)
// Expect game to be overxw
if !strings.HasPrefix(state.Prompt, "3 players tied") {
t.Fatal("Expect game over message to match:", state.Prompt)
}
}
func TestPlayerPOV(t *testing.T) {
_, players := createTestTable(2, 4)
// 4 Players join game
for _, player := range players {
c(player, apiState)
}
// All players ready up
for _, player := range players {
c(player, apiReady)
}
// Check all player's pov is of player 1
for _, player := range players {
state := c(player+"&pov=p1", apiState).(*GameState)
if state.Players[0].id != "p1" {
t.Fatal("Expect first player name to be p2:", state.Players[0].Name)
}
if !strings.HasPrefix(state.Prompt, "p") {
t.Fatal("Expect prompt to be pN's turn:", state.Prompt)
}
}
// Check player move time is >0
state := c(players[0]+"&pov=p1", apiState).(*GameState)
if state.MoveTime == 0 {
t.Fatal("Expected p1's move time to be >0:", state.MoveTime)
}
// Move for player 1
state = c(players[0]+"&pov=p1", apiScore, []gin.Param{{Key: "index", Value: "0"}}).(*GameState)
if state.ActivePlayer != 1 {
t.Fatal("Expected active player to be p2 (1):", state.ActivePlayer)
}
if state.MoveTime == 0 {
t.Fatal("Expected p2's move time to be >0:", state.MoveTime)
}
}