2020-06-03 18:12:08 +01:00
|
|
|
package game
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-07-10 00:12:54 +01:00
|
|
|
"github.com/mdiluz/rove/pkg/rove"
|
2020-06-09 18:08:07 +01:00
|
|
|
"github.com/mdiluz/rove/pkg/vector"
|
2020-06-03 18:12:08 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommand_Move(t *testing.T) {
|
2020-06-27 14:48:21 +01:00
|
|
|
world := NewWorld(8)
|
2020-06-07 22:30:03 +01:00
|
|
|
a, err := world.SpawnRover()
|
|
|
|
assert.NoError(t, err)
|
2020-06-09 18:08:07 +01:00
|
|
|
pos := vector.Vector{
|
2020-06-03 18:12:08 +01:00
|
|
|
X: 1.0,
|
|
|
|
Y: 2.0,
|
|
|
|
}
|
|
|
|
|
2020-06-04 21:59:00 +01:00
|
|
|
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-04 21:59:00 +01:00
|
|
|
// Try the move command
|
2020-07-10 00:12:54 +01:00
|
|
|
moveCommand := Command{Command: rove.CommandType_move, Bearing: "N"}
|
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-06 15:52:03 +01:00
|
|
|
// Tick the world
|
2020-06-09 20:44:25 +01:00
|
|
|
world.EnqueueAllIncoming()
|
2020-06-06 15:52:03 +01:00
|
|
|
world.ExecuteCommandQueues()
|
|
|
|
|
2020-06-26 18:22:37 +01:00
|
|
|
newPos, err := world.RoverPosition(a)
|
2020-06-04 21:59:00 +01:00
|
|
|
assert.NoError(t, err, "Failed to set position for rover")
|
2020-06-26 22:26:27 +01:00
|
|
|
pos.Add(vector.Vector{X: 0.0, Y: 1})
|
2020-06-26 18:22:37 +01:00
|
|
|
assert.Equal(t, pos, newPos, "Failed to correctly set position for rover")
|
2020-06-03 18:12:08 +01:00
|
|
|
}
|
2020-07-04 22:42:20 +01:00
|
|
|
|
2020-07-04 22:56:58 +01:00
|
|
|
func TestCommand_Recharge(t *testing.T) {
|
2020-07-04 22:42:20 +01:00
|
|
|
world := NewWorld(8)
|
|
|
|
a, err := world.SpawnRover()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
pos := vector.Vector{
|
|
|
|
X: 1.0,
|
|
|
|
Y: 2.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = world.WarpRover(a, pos)
|
|
|
|
assert.NoError(t, err, "Failed to set position for rover")
|
|
|
|
|
|
|
|
// Move to use up some charge
|
2020-07-10 00:12:54 +01:00
|
|
|
moveCommand := Command{Command: rove.CommandType_move, Bearing: "N"}
|
2020-07-04 22:42:20 +01:00
|
|
|
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to queue move command")
|
|
|
|
|
|
|
|
// Tick the world
|
|
|
|
world.EnqueueAllIncoming()
|
|
|
|
world.ExecuteCommandQueues()
|
|
|
|
|
|
|
|
rover, _ := world.GetRover(a)
|
|
|
|
assert.Equal(t, rover.MaximumCharge-1, rover.Charge)
|
|
|
|
|
2020-07-10 00:12:54 +01:00
|
|
|
chargeCommand := Command{Command: rove.CommandType_recharge}
|
2020-07-04 22:56:58 +01:00
|
|
|
assert.NoError(t, world.Enqueue(a, chargeCommand), "Failed to queue recharge command")
|
2020-07-04 22:42:20 +01:00
|
|
|
|
|
|
|
// Tick the world
|
|
|
|
world.EnqueueAllIncoming()
|
|
|
|
world.ExecuteCommandQueues()
|
|
|
|
|
|
|
|
rover, _ = world.GetRover(a)
|
|
|
|
assert.Equal(t, rover.MaximumCharge, rover.Charge)
|
|
|
|
|
|
|
|
}
|