rove/pkg/game/command_test.go
Marc Di Luzio 7ababb79f6 Migrate to gRPC rather than REST with swagger
Will also be adding in a RESTful endpoint to the server as well so it can consume both types
2020-06-12 22:51:18 +01:00

38 lines
1 KiB
Go

package game
import (
"testing"
"github.com/mdiluz/rove/pkg/vector"
"github.com/stretchr/testify/assert"
)
func TestCommand_Move(t *testing.T) {
world := NewWorld(2, 8)
a, err := world.SpawnRover()
assert.NoError(t, err)
pos := vector.Vector{
X: 1.0,
Y: 2.0,
}
attribs, err := world.RoverAttributes(a)
assert.NoError(t, err, "Failed to get rover attribs")
err = world.WarpRover(a, pos)
assert.NoError(t, err, "Failed to set position for rover")
var duration = 1
// Try the move command
moveCommand := Command{Command: CommandMove, Bearing: "N", Duration: duration}
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to execute move command")
// Tick the world
world.EnqueueAllIncoming()
world.ExecuteCommandQueues()
newatributes, err := world.RoverAttributes(a)
assert.NoError(t, err, "Failed to set position for rover")
pos.Add(vector.Vector{X: 0.0, Y: int(duration) * int(attribs.Speed)}) // We should have moved duration*speed north
assert.Equal(t, pos, newatributes.Pos, "Failed to correctly set position for rover")
}