test game state after some kills
parent
8d73f97c3a
commit
fc899056e0
|
|
@ -120,10 +120,14 @@ func (ugs *UserGameServer) State(ctx context.Context) (UserGameState, error) {
|
|||
|
||||
for k, v := range gameState.Players {
|
||||
if isSelf := k == ugs.Session.ID; isSelf {
|
||||
self.KillWords.Assignment = Assignment{}
|
||||
v.KillWords.Assignment = Assignment{}
|
||||
} else {
|
||||
v.KillWords.Global = KillWord{}
|
||||
v.KillWords.Assignee = ""
|
||||
for i := range v.Kills {
|
||||
v.Kills[i].Victim = ""
|
||||
v.Kills[i].KillWord.Word = ""
|
||||
}
|
||||
}
|
||||
|
||||
if assignedToSomeoneElse := self.KillWords.Assignee != k; assignedToSomeoneElse {
|
||||
|
|
|
|||
|
|
@ -132,7 +132,80 @@ func TestUserGameServer(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("after kills", func(t *testing.T) {
|
||||
t.Error("not impl")
|
||||
state, err := ugs.State(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !state.Started {
|
||||
t.Error("not started after kills")
|
||||
}
|
||||
|
||||
if !state.Completed.IsZero() {
|
||||
t.Error("completed after kills")
|
||||
}
|
||||
|
||||
for _, pid := range pids {
|
||||
p, ok := state.Players[pid]
|
||||
if !ok {
|
||||
t.Error(pid, "not in players")
|
||||
} else if p.Empty() {
|
||||
t.Error(pid, p)
|
||||
} else if p.KillWords.Assigned.IsZero() {
|
||||
t.Error("assigned is zero")
|
||||
}
|
||||
|
||||
if isSelf := pid == ugs.Session.ID; isSelf {
|
||||
if len(p.Kills) == 0 {
|
||||
t.Error("self never got a kill")
|
||||
} else if kill := p.Kills[0]; kill.Timestamp.IsZero() {
|
||||
t.Errorf("kill has no timestamp")
|
||||
} else if kill.Victim == "" {
|
||||
t.Errorf("kill has no victim")
|
||||
} else if kill.KillWord.Points != 0 {
|
||||
t.Errorf("know points of own kill")
|
||||
} else if kill.KillWord.Word == "" {
|
||||
t.Errorf("dont know own kill word")
|
||||
}
|
||||
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 {
|
||||
if len(p.Kills) == 0 {
|
||||
} else if kill := p.Kills[0]; kill.Timestamp.IsZero() {
|
||||
t.Errorf("kill has no timestamp")
|
||||
} else if kill.Victim != "" {
|
||||
t.Errorf("know other's victim")
|
||||
} else if kill.KillWord.Points == 0 {
|
||||
t.Errorf("other's kill has no points")
|
||||
} else if kill.KillWord.Word != "" {
|
||||
t.Errorf("know other's kill word")
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("completed", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue