Fully implement the bearing based movement

Instant, and without limit, for now
This commit is contained in:
Marc Di Luzio 2020-06-04 21:59:00 +01:00
parent 0fbad15c01
commit 6461b51c5c
7 changed files with 105 additions and 82 deletions

View file

@ -3,7 +3,6 @@ package game
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
@ -17,10 +16,8 @@ func TestNewWorld(t *testing.T) {
func TestWorld_CreateRover(t *testing.T) {
world := NewWorld()
a := uuid.New()
b := uuid.New()
assert.NoError(t, world.SpawnRover(a), "Failed to spawn")
assert.NoError(t, world.SpawnRover(b), "Failed to spawn")
a := world.SpawnRover()
b := world.SpawnRover()
// Basic duplicate check
if a == b {
@ -30,12 +27,20 @@ func TestWorld_CreateRover(t *testing.T) {
}
}
func TestWorld_RoverAttributes(t *testing.T) {
world := NewWorld()
a := world.SpawnRover()
attribs, err := world.RoverAttributes(a)
assert.NoError(t, err, "Failed to get rover attribs")
assert.NotZero(t, attribs.Sight, "Rover should not be spawned blind")
assert.NotZero(t, attribs.Speed, "Rover should not be spawned unable to move")
}
func TestWorld_DestroyRover(t *testing.T) {
world := NewWorld()
a := uuid.New()
b := uuid.New()
assert.NoError(t, world.SpawnRover(a), "Failed to spawn")
assert.NoError(t, world.SpawnRover(b), "Failed to spawn")
a := world.SpawnRover()
b := world.SpawnRover()
err := world.DestroyRover(a)
assert.NoError(t, err, "Error returned from rover destroy")
@ -50,23 +55,26 @@ func TestWorld_DestroyRover(t *testing.T) {
func TestWorld_GetSetMovePosition(t *testing.T) {
world := NewWorld()
a := uuid.New()
assert.NoError(t, world.SpawnRover(a), "Failed to spawn")
a := world.SpawnRover()
attribs, err := world.RoverAttributes(a)
assert.NoError(t, err, "Failed to get rover attribs")
pos := Vector{
X: 1.0,
Y: 2.0,
}
err := world.SetPosition(a, pos)
err = world.WarpRover(a, pos)
assert.NoError(t, err, "Failed to set position for rover")
newpos, err := world.GetPosition(a)
newpos, err := world.RoverPosition(a)
assert.NoError(t, err, "Failed to set position for rover")
assert.Equal(t, pos, newpos, "Failed to correctly set position for rover")
newpos, err = world.MovePosition(a, pos)
bearing := 0.0
duration := 1.0
newpos, err = world.MoveRover(a, bearing, duration)
assert.NoError(t, err, "Failed to set position for rover")
pos.Add(pos)
pos.Add(Vector{0, attribs.Speed * float64(duration)}) // We should have move one unit of the speed north
assert.Equal(t, pos, newpos, "Failed to correctly move position for rover")
}