From fc899056e02348c27746ee4801d0abba265c466f Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sun, 15 Dec 2024 13:13:03 -0700 Subject: [PATCH] test game state after some kills --- cmd/server/usergameserver.go | 6 ++- cmd/server/usergameserver_test.go | 75 ++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/cmd/server/usergameserver.go b/cmd/server/usergameserver.go index 856a5a6..12d9f55 100644 --- a/cmd/server/usergameserver.go +++ b/cmd/server/usergameserver.go @@ -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 { diff --git a/cmd/server/usergameserver_test.go b/cmd/server/usergameserver_test.go index 34bd093..be69fb8 100644 --- a/cmd/server/usergameserver_test.go +++ b/cmd/server/usergameserver_test.go @@ -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) {