Skip to content

Commit 50b1819

Browse files
committed
feat: add s2 velocity test
1 parent 51ac188 commit 50b1819

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pkg/demoinfocs/common/common_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,14 @@ type demoInfoProviderMock struct {
213213
tickRate float64
214214
ingameTick int
215215
playersByHandle map[int]*Player
216+
entitiesByHandle map[uint64]st.Entity
216217
playerResourceEntity st.Entity
217218
equipment *Equipment
218219
isSource2 bool
219220
}
220221

221222
func (p demoInfoProviderMock) FindEntityByHandle(handle uint64) st.Entity {
222-
panic("implement me")
223+
return p.entitiesByHandle[handle]
223224
}
224225

225226
func (p demoInfoProviderMock) IsSource2() bool {

pkg/demoinfocs/common/player_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,31 @@ func TestPlayer_Velocity(t *testing.T) {
428428
assert.Equal(t, expected, pl.Velocity())
429429
}
430430

431+
func TestPlayer_VelocityS2(t *testing.T) {
432+
controllerEntity := entityWithProperties([]fakeProp{
433+
{propName: "m_hPlayerPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
434+
})
435+
pawnEntity := entityWithProperties([]fakeProp{
436+
{propName: "m_iHealth", value: st.PropertyValue{Any: int32(100), S2: true}},
437+
})
438+
439+
pl := &Player{
440+
Entity: controllerEntity,
441+
}
442+
443+
demoInfoProvider := demoInfoProviderMock{
444+
isSource2: true,
445+
entitiesByHandle: map[uint64]st.Entity{
446+
1: pawnEntity,
447+
},
448+
}
449+
pl.LastPositions = []r3.Vector{{X: 10, Y: 200, Z: 0}, {X: 20, Y: 300, Z: 0}}
450+
pl.demoInfoProvider = demoInfoProvider
451+
452+
expected := r3.Vector{X: 640, Y: 6400, Z: 0}
453+
assert.Equal(t, expected, pl.Velocity())
454+
}
455+
431456
func TestPlayer_Velocity_EntityNil(t *testing.T) {
432457
pl := new(Player)
433458
pl.demoInfoProvider = s1DemoInfoProvider

0 commit comments

Comments
 (0)