Skip to content

Commit

Permalink
feat: add s2 velocity test
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Nov 12, 2023
1 parent 51ac188 commit 50b1819
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/demoinfocs/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,14 @@ type demoInfoProviderMock struct {
tickRate float64
ingameTick int
playersByHandle map[int]*Player
entitiesByHandle map[uint64]st.Entity
playerResourceEntity st.Entity
equipment *Equipment
isSource2 bool
}

func (p demoInfoProviderMock) FindEntityByHandle(handle uint64) st.Entity {
panic("implement me")
return p.entitiesByHandle[handle]
}

func (p demoInfoProviderMock) IsSource2() bool {
Expand Down
25 changes: 25 additions & 0 deletions pkg/demoinfocs/common/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,31 @@ func TestPlayer_Velocity(t *testing.T) {
assert.Equal(t, expected, pl.Velocity())
}

func TestPlayer_VelocityS2(t *testing.T) {
controllerEntity := entityWithProperties([]fakeProp{
{propName: "m_hPlayerPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
})
pawnEntity := entityWithProperties([]fakeProp{
{propName: "m_iHealth", value: st.PropertyValue{Any: int32(100), S2: true}},
})

pl := &Player{
Entity: controllerEntity,
}

demoInfoProvider := demoInfoProviderMock{
isSource2: true,
entitiesByHandle: map[uint64]st.Entity{
1: pawnEntity,
},
}
pl.LastPositions = []r3.Vector{{X: 10, Y: 200, Z: 0}, {X: 20, Y: 300, Z: 0}}
pl.demoInfoProvider = demoInfoProvider

expected := r3.Vector{X: 640, Y: 6400, Z: 0}
assert.Equal(t, expected, pl.Velocity())
}

func TestPlayer_Velocity_EntityNil(t *testing.T) {
pl := new(Player)
pl.demoInfoProvider = s1DemoInfoProvider
Expand Down

0 comments on commit 50b1819

Please sign in to comment.