Skip to content

Commit

Permalink
37% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
teelau committed May 15, 2018
1 parent dcbc8b1 commit 1f13bda
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion server/models/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,54 @@ func TestCreatePlayer(t *testing.T) {
testName := "testy"
testColor := "blue"
ws := new(*websocket.Conn)

//Test initialization of player
p := CreatePlayer(testName, testPosition, testColor, *ws)

//Name Assignment
//Test name assignment of player
if p.Name != testName {
t.Error("Error assigning name")
}

//To do: test other initializations
}

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.Position = testPosition1
p.Angle = testAngle1

//Test left control
p.Controls.Left = true
p.UpdatePosition(testHeight1, testWidth1)
if p.Angle != (testAngle1 + 0.1) {
t.Error("Error in left key player control")
}
p.Controls.Left = false
p.Controls.Right = true
p.UpdatePosition(testHeight1, testWidth1)
if p.Angle != (testAngle1) {
t.Error("Error in right key player control or symmetry")
}
p.Controls.Right = false
p.Controls.Up = true
p.UpdatePosition(testHeight1, testWidth1)
if p.Angle != (testAngle1) {
t.Error("Error in up key player control")
}
// if p.Velocity.Dx != PlayerAcceleration {
// t.Error("Error in x velocity calculation")
// }
p.UpdatePosition(testHeight1, testWidth1)

}

func TestKeyDownHandler(t *testing.T) {
p := new(Player)
key := UpKey
Expand Down

0 comments on commit 1f13bda

Please sign in to comment.