@@ -54,108 +54,128 @@ func TestGameState_Participants(t *testing.T) {
5454}
5555
5656func TestParticipants_All (t * testing.T ) {
57- gs := newGameState ()
5857 pl := newPlayer ()
59- gs .playersByUserID [0 ] = pl
58+ ptcps := Participants {
59+ playersByUserID : map [int ]* common.Player {0 : pl },
60+ }
6061
61- allPlayers := gs . Participants () .All ()
62+ allPlayers := ptcps .All ()
6263
6364 assert .ElementsMatch (t , []* common.Player {pl }, allPlayers )
6465}
6566
6667func TestParticipants_Playing (t * testing.T ) {
67- gs := newGameState ()
68-
6968 terrorist := newPlayer ()
7069 terrorist .Team = common .TeamTerrorists
71- gs .playersByUserID [0 ] = terrorist
7270 ct := newPlayer ()
7371 ct .Team = common .TeamCounterTerrorists
74- gs .playersByUserID [1 ] = ct
7572 unassigned := newPlayer ()
7673 unassigned .Team = common .TeamUnassigned
77- gs .playersByUserID [2 ] = unassigned
7874 spectator := newPlayer ()
7975 spectator .Team = common .TeamSpectators
80- gs .playersByUserID [3 ] = spectator
8176 def := newPlayer ()
82- gs .playersByUserID [4 ] = def
8377
84- playing := gs .Participants ().Playing ()
78+ ptcps := Participants {
79+ playersByUserID : map [int ]* common.Player {
80+ 0 : terrorist ,
81+ 1 : ct ,
82+ 2 : unassigned ,
83+ 3 : spectator ,
84+ 4 : def ,
85+ },
86+ }
87+
88+ playing := ptcps .Playing ()
8589
8690 assert .Len (t , playing , 2 )
8791 assert .ElementsMatch (t , []* common.Player {terrorist , ct }, playing )
8892}
8993
9094func TestParticipants_TeamMembers (t * testing.T ) {
91- gs := newGameState ()
92-
9395 terrorist := newPlayer ()
9496 terrorist .Team = common .TeamTerrorists
95- gs .playersByUserID [0 ] = terrorist
9697 ct := newPlayer ()
9798 ct .Team = common .TeamCounterTerrorists
98- gs .playersByUserID [1 ] = ct
9999 unassigned := newPlayer ()
100100 unassigned .Team = common .TeamUnassigned
101- gs .playersByUserID [2 ] = unassigned
102101 spectator := newPlayer ()
103102 spectator .Team = common .TeamSpectators
104- gs .playersByUserID [3 ] = spectator
105103 def := newPlayer ()
106- gs .playersByUserID [4 ] = def
107104
108- cts := gs .Participants ().TeamMembers (common .TeamCounterTerrorists )
105+ ptcps := Participants {
106+ playersByUserID : map [int ]* common.Player {
107+ 0 : terrorist ,
108+ 1 : ct ,
109+ 2 : unassigned ,
110+ 3 : spectator ,
111+ 4 : def ,
112+ },
113+ }
114+
115+ cts := ptcps .TeamMembers (common .TeamCounterTerrorists )
109116
110117 assert .ElementsMatch (t , []* common.Player {ct }, cts )
111118}
112119
113120func TestParticipants_FindByHandle (t * testing.T ) {
114- gs := newGameState ()
115-
116121 pl := newPlayer ()
117122 pl .Team = common .TeamTerrorists
118- gs .playersByEntityID [3000 & entityHandleIndexMask ] = pl
119123
120- found := gs .Participants ().FindByHandle (3000 )
124+ ptcps := Participants {
125+ playersByEntityID : map [int ]* common.Player {
126+ 3000 & entityHandleIndexMask : pl ,
127+ },
128+ }
129+
130+ found := ptcps .FindByHandle (3000 )
121131
122132 assert .Equal (t , pl , found )
123133}
124134
125135func TestParticipants_FindByHandle_InvalidEntityHandle (t * testing.T ) {
126- gs := newGameState ()
127-
128136 pl := newPlayer ()
129137 pl .Team = common .TeamTerrorists
130- gs .playersByEntityID [invalidEntityHandle & entityHandleIndexMask ] = pl
138+ ptcps := Participants {
139+ playersByEntityID : map [int ]* common.Player {
140+ invalidEntityHandle & entityHandleIndexMask : pl ,
141+ },
142+ }
131143
132- found := gs . Participants () .FindByHandle (invalidEntityHandle )
144+ found := ptcps .FindByHandle (invalidEntityHandle )
133145
134146 assert .Nil (t , found )
135147}
136148
137149func TestParticipants_Connected_SuppressNoEntity (t * testing.T ) {
138- gs := newGameState ()
139150 pl := newPlayer ()
140- gs .playersByUserID [0 ] = pl
141151 pl2 := common .NewPlayer (0 , func () int { return 0 })
142152 pl2 .IsConnected = true
143- gs .playersByUserID [1 ] = pl2
144153
145- allPlayers := gs .Participants ().Connected ()
154+ ptcps := Participants {
155+ playersByUserID : map [int ]* common.Player {
156+ 0 : pl ,
157+ 1 : pl2 ,
158+ },
159+ }
160+
161+ allPlayers := ptcps .Connected ()
146162
147163 assert .ElementsMatch (t , []* common.Player {pl }, allPlayers )
148164}
149165
150166func TestParticipants_Connected_SuppressNotConnected (t * testing.T ) {
151- gs := newGameState ()
152167 pl := newPlayer ()
153- gs .playersByUserID [0 ] = pl
154168 pl2 := newPlayer ()
155169 pl2 .IsConnected = false
156- gs .playersByUserID [1 ] = pl2
157170
158- allPlayers := gs .Participants ().Connected ()
171+ ptcps := Participants {
172+ playersByUserID : map [int ]* common.Player {
173+ 0 : pl ,
174+ 1 : pl2 ,
175+ },
176+ }
177+
178+ allPlayers := ptcps .Connected ()
159179
160180 assert .ElementsMatch (t , []* common.Player {pl }, allPlayers )
161181}
0 commit comments