Add a test for the repair command
This commit is contained in:
parent
3bfc91b8f6
commit
8a8a27ab47
1 changed files with 38 additions and 1 deletions
|
@ -3,6 +3,7 @@ package rove
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/mdiluz/rove/pkg/maths"
|
||||||
"github.com/mdiluz/rove/proto/roveapi"
|
"github.com/mdiluz/rove/proto/roveapi"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -76,7 +77,43 @@ func TestCommand_Stash(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommand_Repair(t *testing.T) {
|
func TestCommand_Repair(t *testing.T) {
|
||||||
// TODO: Test the repair command
|
w := NewWorld(8)
|
||||||
|
name, err := w.SpawnRover()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
info, err := w.GetRover(name)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, info.MaximumIntegrity, info.Integrity)
|
||||||
|
|
||||||
|
// Put a blocking rock to the north
|
||||||
|
w.Atlas.SetObject(info.Pos.Added(maths.Vector{X: 0, Y: 1}), Object{Type: roveapi.Object_RockLarge})
|
||||||
|
|
||||||
|
// Try and move and make sure we're blocked
|
||||||
|
newpos, err := w.TryMoveRover(name, roveapi.Bearing_North)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, info.Pos, newpos)
|
||||||
|
|
||||||
|
// Check we're damaged
|
||||||
|
info, err = w.GetRover(name)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, info.MaximumIntegrity-1, info.Integrity)
|
||||||
|
|
||||||
|
// Stash a repair object
|
||||||
|
w.Atlas.SetObject(info.Pos, Object{Type: roveapi.Object_RockSmall})
|
||||||
|
obj, err := w.RoverStash(name)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, roveapi.Object_RockSmall, obj)
|
||||||
|
|
||||||
|
// Enqueue the repair and tick
|
||||||
|
err = w.Enqueue(name, &roveapi.Command{Command: roveapi.CommandType_repair})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
w.Tick()
|
||||||
|
|
||||||
|
// Check we're repaired
|
||||||
|
info, err = w.GetRover(name)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, info.MaximumIntegrity, info.Integrity)
|
||||||
|
assert.Equal(t, 0, len(info.Inventory))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommand_Broadcast(t *testing.T) {
|
func TestCommand_Broadcast(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue