Skip to content

Commit

Permalink
fix redeclarations
Browse files Browse the repository at this point in the history
  • Loading branch information
teelau committed May 24, 2018
1 parent a148f0a commit d7b5d28
Showing 1 changed file with 0 additions and 100 deletions.
100 changes: 0 additions & 100 deletions server/models/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,106 +168,6 @@ func TestHitjunk(t *testing.T) {
})
}
}

func TestUpdatePosition(t *testing.T) {
//Mock player and info
testHeight1 := 10.0
testWidth1 := 20.0
testAngle1 := 0.0
testPosition1 := Position{5, 5}
p := new(Player)
p.Angle = 0
p.Position = centerPos
rangeAngle := 2
testCases := []struct {
description string
playerVelocity Velocity
playerPosition Position
playerAngle float64
}{
{"Not moving", Velocity{0, 0}, centerPosPlayerTest, 0},
{"Max velocity", Velocity{math.Sqrt(MaxVelocity), math.Sqrt(MaxVelocity)}, centerPosPlayerTest, 0},
{"Moving N", Velocity{5, 0}, centerPosPlayerTest, 0},
{"Moving E", Velocity{0, 5}, centerPosPlayerTest, 0},
{"Moving S", Velocity{-5, 0}, centerPosPlayerTest, 0},
{"Moving W", Velocity{0, -5}, centerPosPlayerTest, 0},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
p := new(Player)
p.Velocity = tc.playerVelocity
p.Position = tc.playerPosition
p.Angle = tc.playerAngle

p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
//Test max velocity
if p.Velocity.magnitude() > MaxVelocity {
t.Error("Error calculating max velocity")
}
//Test directional controls
//Left
p.Controls.Left = true
for i := 0; i < rangeAngle; i++ {
prevAngle := p.Angle
p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
if (p.Angle - prevAngle) != 0.1 {
t.Error("Error calculating left control")
}
}
p.Controls.Left = false
p.Controls.Right = true
//Right
for i := 0; i < rangeAngle; i++ {
prevAngle := p.Angle
p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
if (p.Angle - prevAngle) != -0.1 {
t.Error("Error calculating right control")
}
}
p.Controls.Left = true
//Both
for i := 0; i < rangeAngle; i++ {
prevAngle := p.Angle
p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
if p.Angle != prevAngle {
t.Error("Error calculating both controls")
}
}
p.Controls.Left = false
p.Controls.Right = false
//Up
//Friction
prevMagnitude := p.Velocity.magnitude()
p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
if p.Velocity.magnitude() > prevMagnitude {
t.Error("Error calculating friction")
}
})

//Test friction and accelerate
t.Run(tc.description, func(t *testing.T) {
p := new(Player)
p.Velocity = tc.playerVelocity
p.Position = tc.playerPosition
p.Angle = tc.playerAngle
//Test Friction
prevMagnitude := p.Velocity.magnitude()
p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
if p.Velocity.magnitude() > prevMagnitude {
t.Error("Error calculating friction")
}

// p.Controls.Up = true
// //Test Accelerate
// prevMagnitude = p.Velocity.magnitude()
// p.UpdatePosition(testHeightPlayerTest, testWidthPlayerTest)
// if p.Velocity.magnitude() < prevMagnitude {
// t.Error("Error calculating acceleration")
// }
})
}
}

func TestHitjunk(t *testing.T) {
testCases := []struct {
description string
Expand Down

0 comments on commit d7b5d28

Please sign in to comment.