@@ -4,9 +4,11 @@ import (
44 "testing"
55 "time"
66
7+ "github.com/golang/geo/r3"
78 "github.com/stretchr/testify/assert"
89
910 st "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/sendtables"
11+ stfake "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/sendtables/fake"
1012)
1113
1214func TestPlayerActiveWeapon (t * testing.T ) {
@@ -206,6 +208,36 @@ func TestPlayer_IsAirborne(t *testing.T) {
206208 assert .True (t , pl .IsAirborne ())
207209}
208210
211+ func TestPlayer_IsDucking (t * testing.T ) {
212+ pl := playerWithProperty ("localdata.m_Local.m_bDucking" , st.PropertyValue {IntVal : 0 })
213+
214+ assert .False (t , pl .IsDucking ())
215+
216+ pl = playerWithProperty ("localdata.m_Local.m_bDucking" , st.PropertyValue {IntVal : 1 })
217+
218+ assert .True (t , pl .IsDucking ())
219+ }
220+
221+ func TestPlayer_HasDefuseKit (t * testing.T ) {
222+ pl := playerWithProperty ("m_bHasDefuser" , st.PropertyValue {IntVal : 0 })
223+
224+ assert .False (t , pl .HasDefuseKit ())
225+
226+ pl = playerWithProperty ("m_bHasDefuser" , st.PropertyValue {IntVal : 1 })
227+
228+ assert .True (t , pl .HasDefuseKit ())
229+ }
230+
231+ func TestPlayer_HasHelmet (t * testing.T ) {
232+ pl := playerWithProperty ("m_bHasHelmet" , st.PropertyValue {IntVal : 0 })
233+
234+ assert .False (t , pl .HasHelmet ())
235+
236+ pl = playerWithProperty ("m_bHasHelmet" , st.PropertyValue {IntVal : 1 })
237+
238+ assert .True (t , pl .HasHelmet ())
239+ }
240+
209241func TestPlayer_IsControllingBot_NilEntity (t * testing.T ) {
210242 pl := new (Player )
211243
@@ -250,6 +282,107 @@ func TestPlayer_ControlledBot(t *testing.T) {
250282 assert .Same (t , dave , pl .ControlledBot ())
251283}
252284
285+ func TestPlayer_Armor (t * testing.T ) {
286+ pl := playerWithProperty ("m_ArmorValue" , st.PropertyValue {IntVal : 95 })
287+
288+ assert .Equal (t , 95 , pl .Armor ())
289+ }
290+
291+ func TestPlayer_Money (t * testing.T ) {
292+ pl := playerWithProperty ("m_iAccount" , st.PropertyValue {IntVal : 800 })
293+
294+ assert .Equal (t , 800 , pl .Money ())
295+ }
296+
297+ func TestPlayer_ViewDirectionX (t * testing.T ) {
298+ pl := playerWithProperty ("m_angEyeAngles[1]" , st.PropertyValue {FloatVal : 180 })
299+
300+ assert .Equal (t , float32 (180 ), pl .ViewDirectionX ())
301+ }
302+
303+ func TestPlayer_ViewDirectionY (t * testing.T ) {
304+ pl := playerWithProperty ("m_angEyeAngles[0]" , st.PropertyValue {FloatVal : 15 })
305+
306+ assert .Equal (t , float32 (15 ), pl .ViewDirectionY ())
307+ }
308+
309+ func TestPlayer_Position (t * testing.T ) {
310+ entity := new (stfake.Entity )
311+ pos := r3.Vector {X : 1 , Y : 2 , Z : 3 }
312+
313+ entity .On ("Position" ).Return (pos )
314+
315+ pl := & Player {Entity : entity }
316+
317+ assert .Equal (t , pos , pl .Position ())
318+ }
319+
320+ func TestPlayer_Position_EntityNil (t * testing.T ) {
321+ pl := new (Player )
322+
323+ assert .Empty (t , pl .Position ())
324+ }
325+
326+ func TestPlayer_Velocity (t * testing.T ) {
327+ entity := new (stfake.Entity )
328+ entity .On ("PropertyValueMust" , "localdata.m_vecVelocity[0]" ).Return (st.PropertyValue {FloatVal : 1 })
329+ entity .On ("PropertyValueMust" , "localdata.m_vecVelocity[1]" ).Return (st.PropertyValue {FloatVal : 2 })
330+ entity .On ("PropertyValueMust" , "localdata.m_vecVelocity[2]" ).Return (st.PropertyValue {FloatVal : 3 })
331+
332+ pl := & Player {Entity : entity }
333+
334+ expected := r3.Vector {X : 1 , Y : 2 , Z : 3 }
335+ assert .Equal (t , expected , pl .Velocity ())
336+ }
337+
338+ func TestPlayer_Velocity_EntityNil (t * testing.T ) {
339+ pl := new (Player )
340+
341+ assert .Empty (t , pl .Velocity ())
342+ }
343+
344+ func TestPlayer_ClanTag (t * testing.T ) {
345+ pl := playerWithResourceProperty ("m_szClan" , st.PropertyValue {StringVal : "SuperClan" })
346+
347+ assert .Equal (t , "SuperClan" , pl .ClanTag ())
348+ }
349+
350+ func TestPlayer_Ping (t * testing.T ) {
351+ pl := playerWithResourceProperty ("m_iPing" , st.PropertyValue {IntVal : 45 })
352+
353+ assert .Equal (t , 45 , pl .Ping ())
354+ }
355+
356+ func TestPlayer_Score (t * testing.T ) {
357+ pl := playerWithResourceProperty ("m_iScore" , st.PropertyValue {IntVal : 10 })
358+
359+ assert .Equal (t , 10 , pl .Score ())
360+ }
361+
362+ func TestPlayer_Kills (t * testing.T ) {
363+ pl := playerWithResourceProperty ("m_iKills" , st.PropertyValue {IntVal : 5 })
364+
365+ assert .Equal (t , 5 , pl .Kills ())
366+ }
367+
368+ func TestPlayer_Deaths (t * testing.T ) {
369+ pl := playerWithResourceProperty ("m_iDeaths" , st.PropertyValue {IntVal : 2 })
370+
371+ assert .Equal (t , 2 , pl .Deaths ())
372+ }
373+
374+ func TestPlayer_Assists (t * testing.T ) {
375+ pl := playerWithResourceProperty ("m_iAssists" , st.PropertyValue {IntVal : 3 })
376+
377+ assert .Equal (t , 3 , pl .Assists ())
378+ }
379+
380+ func TestPlayer_MVPs (t * testing.T ) {
381+ pl := playerWithResourceProperty ("m_iMVPs" , st.PropertyValue {IntVal : 4 })
382+
383+ assert .Equal (t , 4 , pl .MVPs ())
384+ }
385+
253386func TestPlayer_SteamID32 (t * testing.T ) {
254387 pl := & Player {SteamID64 : 76561198012952267 }
255388
@@ -263,3 +396,12 @@ func newPlayer(tick int) *Player {
263396func playerWithProperty (propName string , value st.PropertyValue ) * Player {
264397 return & Player {Entity : entityWithProperty (propName , value )}
265398}
399+
400+ func playerWithResourceProperty (propName string , value st.PropertyValue ) * Player {
401+ return & Player {
402+ EntityID : 1 ,
403+ demoInfoProvider : demoInfoProviderMock {
404+ playerResourceEntity : entityWithProperty (propName + ".001" , value ),
405+ },
406+ }
407+ }
0 commit comments