2020-06-03 18:12:08 +01:00
|
|
|
package game
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommand_Move(t *testing.T) {
|
|
|
|
world := NewWorld()
|
2020-06-04 21:59:00 +01:00
|
|
|
a := world.SpawnRover()
|
2020-06-03 18:12:08 +01:00
|
|
|
pos := Vector{
|
|
|
|
X: 1.0,
|
|
|
|
Y: 2.0,
|
|
|
|
}
|
|
|
|
|
2020-06-04 21:59:00 +01:00
|
|
|
attribs, err := world.RoverAttributes(a)
|
|
|
|
assert.NoError(t, err, "Failed to get rover attribs")
|
|
|
|
|
|
|
|
err = world.WarpRover(a, pos)
|
2020-06-04 21:17:43 +01:00
|
|
|
assert.NoError(t, err, "Failed to set position for rover")
|
2020-06-03 18:12:08 +01:00
|
|
|
|
2020-06-05 16:37:52 +01:00
|
|
|
bearing := North
|
|
|
|
duration := 1
|
2020-06-04 21:59:00 +01:00
|
|
|
// Try the move command
|
2020-06-06 12:45:45 +01:00
|
|
|
moveCommand := Command{Command: CommandMove, Bearing: bearing.String(), Duration: duration}
|
2020-06-06 14:44:59 +01:00
|
|
|
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to execute move command")
|
2020-06-04 18:54:33 +01:00
|
|
|
|
2020-06-04 21:59:00 +01:00
|
|
|
newpos, err := world.RoverPosition(a)
|
|
|
|
assert.NoError(t, err, "Failed to set position for rover")
|
2020-06-05 16:37:52 +01:00
|
|
|
pos.Add(Vector{0.0, duration * attribs.Speed}) // We should have moved duration*speed north
|
2020-06-04 21:59:00 +01:00
|
|
|
assert.Equal(t, pos, newpos, "Failed to correctly set position for rover")
|
2020-06-03 18:12:08 +01:00
|
|
|
}
|