-
Notifications
You must be signed in to change notification settings - Fork 1
/
engine_test.go
103 lines (100 loc) · 2.33 KB
/
engine_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
package sh
import (
"testing"
)
func TestGameStart(t *testing.T) {
g := Game{
Players: []Player{
Player{ID: "1", Ready: true},
Player{ID: "2", Ready: true},
Player{ID: "3", Ready: true},
Player{ID: "4", Ready: true},
Player{ID: "5", Ready: true},
}}
e := PlayerEvent{
BaseEvent: BaseEvent{
Type: TypePlayerReady,
},
Player: Player{ID: "5", Ready: true},
}
events, err := g.Engine(e)
if err != nil {
t.Fatal(err)
}
updateEventFound := false
for _, e := range events {
if e.GetType() == TypeGameUpdate {
ge := e.(GameEvent)
updateEventFound = true
//Every player should have an assigned role
allHaveParty := true
allHaveRoles := true
for _, p := range ge.Game.Players {
if p.Party == "" {
allHaveParty = false
}
if p.Role == "" {
allHaveRoles = false
}
}
if !allHaveParty {
t.Fatal("Not all players have party")
}
if !allHaveRoles {
t.Fatal("Not all players have a role")
}
//Should be 11+6 policies in the draw pile
if len(ge.Game.Draw) != 17 {
t.Fatal("Not 17 policies")
}
//Should be a nextPresident defined
if ge.Game.NextPresidentID == "" {
t.Fatal("No Next President defined")
}
}
}
if !updateEventFound {
t.Fatal("No Game update event")
}
}
func TestVeto(t *testing.T) {
g := Game{
ID: "1",
Secret: "secret",
State: GameStateStarted,
Players: []Player{
Player{ID: "1", Party: PartyLiberal, Role: RoleLiberal},
Player{ID: "2", Party: PartyLiberal, Role: RoleLiberal},
Player{ID: "3", Party: PartyLiberal, Role: RoleLiberal},
Player{ID: "4", Party: PartyFascist, Role: RoleFascist},
Player{ID: "5", Party: PartyFascist, Role: RoleHitler},
},
PreviousPresidentID: "4",
PreviousChancellorID: "5",
NextPresidentID: "2",
ElectionTracker: 2,
Liberal: 4,
Fascist: 5,
Draw: []string{"draw", "draw", "draw"},
Discard: []string{"discard"},
Round: Round{
ID: 10,
PresidentID: "1",
ChancellorID: "2",
Policies: []string{PolicyFascist},
State: RoundStateLegislating,
},
}
e := PlayerLegislateEvent{
BaseEvent: BaseEvent{Type: TypePlayerLegislate},
PlayerID: "1",
Veto: true,
}
events, err := g.Engine(e)
if err != nil {
t.Fatal(err)
}
for _, e := range events {
t.Log(e)
}
}