test UserGameState of freshly started game
parent
aba5225ed2
commit
598cb0684c
|
|
@ -77,6 +77,10 @@ func (games Games) UserName(ctx context.Context, id string) (string, error) {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a KillWord) Empty() bool {
|
||||||
|
return a == (KillWord{})
|
||||||
|
}
|
||||||
|
|
||||||
func (a Assignment) Empty() bool {
|
func (a Assignment) Empty() bool {
|
||||||
return len(a.Public) == 0 && len(a.Private) == 0
|
return len(a.Public) == 0 && len(a.Private) == 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,11 +114,15 @@ func (ugs *UserGameServer) State(ctx context.Context) (UserGameState, error) {
|
||||||
for i := range self.Kills {
|
for i := range self.Kills {
|
||||||
self.Kills[i].KillWord.Points = 0
|
self.Kills[i].KillWord.Points = 0
|
||||||
}
|
}
|
||||||
|
self.KillWords.Assignment.Public = nil
|
||||||
|
self.KillWords.Assignment.Private = nil
|
||||||
|
gameState.Players[ugs.Session.ID] = self
|
||||||
|
|
||||||
for k, v := range gameState.Players {
|
for k, v := range gameState.Players {
|
||||||
if isSelf := k == ugs.Session.ID; isSelf {
|
if isSelf := k == ugs.Session.ID; isSelf {
|
||||||
self.KillWords.Assignment = Assignment{}
|
self.KillWords.Assignment = Assignment{}
|
||||||
} else {
|
} else {
|
||||||
|
v.KillWords.Global = KillWord{}
|
||||||
v.KillWords.Assignee = ""
|
v.KillWords.Assignee = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,16 +71,45 @@ func TestUserGameServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pid := range pids {
|
for _, pid := range pids {
|
||||||
if p, ok := state.Players[pid]; !ok {
|
p, ok := state.Players[pid]
|
||||||
|
if !ok {
|
||||||
t.Error(pid, "not in players")
|
t.Error(pid, "not in players")
|
||||||
} else if p.Empty() {
|
} else if p.Empty() {
|
||||||
t.Error(pid, p)
|
t.Error(pid, p)
|
||||||
|
} else if len(p.Kills) > 0 {
|
||||||
|
t.Error(pid, "has a kill")
|
||||||
|
} else if p.KillWords.Assigned.IsZero() {
|
||||||
|
t.Error("assigned is zero")
|
||||||
}
|
}
|
||||||
|
|
||||||
if isSelf := pid == ugs.Session.ID; isSelf {
|
if isSelf := pid == ugs.Session.ID; isSelf {
|
||||||
t.Error("not impl")
|
if p.KillWords.Global.Word == "" || p.KillWords.Global.Points == 0 {
|
||||||
|
t.Error("self global missing field")
|
||||||
|
}
|
||||||
|
if p.KillWords.Assignee == "" {
|
||||||
|
t.Error("assignee is empty")
|
||||||
|
}
|
||||||
|
if len(p.KillWords.Assignment.Public) > 0 {
|
||||||
|
t.Error("self knows its own public")
|
||||||
|
}
|
||||||
|
if len(p.KillWords.Assignment.Private) > 0 {
|
||||||
|
t.Error("self knows its own private")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Error("not impl")
|
if !p.KillWords.Global.Empty() {
|
||||||
|
t.Error("can see not self global")
|
||||||
|
}
|
||||||
|
if p.KillWords.Assignee != "" {
|
||||||
|
t.Error("can see other player's assignee")
|
||||||
|
}
|
||||||
|
if len(p.KillWords.Assignment.Public) == 0 {
|
||||||
|
t.Error("cannot see other player's public")
|
||||||
|
}
|
||||||
|
if state.Players[ugs.Session.ID].KillWords.Assignee == pid && len(p.KillWords.Assignment.Private) == 0 {
|
||||||
|
t.Error("cannot see assignee's private")
|
||||||
|
} else if state.Players[ugs.Session.ID].KillWords.Assignee != pid && len(p.KillWords.Assignment.Private) > 0 {
|
||||||
|
t.Error("can see not assignee's private")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue