rove/pkg/game/command_test.go

37 lines
946 B
Go
Raw Normal View History

package game
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCommand_Move(t *testing.T) {
world := NewWorld()
a := world.SpawnRover()
pos := 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")
bearing := North
duration := 1
// Try the move command
2020-06-06 12:45:45 +01:00
moveCommand := Command{Command: CommandMove, Bearing: bearing.String(), Duration: duration}
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to execute move command")
2020-06-06 15:52:03 +01:00
// Tick the world
world.ExecuteCommandQueues()
newpos, err := world.RoverPosition(a)
assert.NoError(t, err, "Failed to set position for rover")
pos.Add(Vector{0.0, duration * attribs.Speed}) // We should have moved duration*speed north
assert.Equal(t, pos, newpos, "Failed to correctly set position for rover")
}