Write test to check rover has item in inventory
This commit is contained in:
parent
f0d40cc46c
commit
71c2c09270
2 changed files with 18 additions and 0 deletions
|
@ -199,6 +199,18 @@ func (w *World) SetRoverAttributes(id uuid.UUID, attributes RoverAttributes) err
|
|||
}
|
||||
}
|
||||
|
||||
// RoverInventory returns the inventory of a requested rover
|
||||
func (w *World) RoverInventory(id uuid.UUID) ([]Item, error) {
|
||||
w.worldMutex.RLock()
|
||||
defer w.worldMutex.RUnlock()
|
||||
|
||||
if i, ok := w.Rovers[id]; ok {
|
||||
return i.Inventory, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("no rover matching id")
|
||||
}
|
||||
}
|
||||
|
||||
// WarpRover sets an rovers position
|
||||
func (w *World) WarpRover(id uuid.UUID, pos vector.Vector) error {
|
||||
w.worldMutex.Lock()
|
||||
|
@ -260,6 +272,7 @@ func (w *World) RoverStash(id uuid.UUID) (byte, error) {
|
|||
} else {
|
||||
if objects.IsStashable(tile) {
|
||||
r.Inventory = append(r.Inventory, Item{Type: tile})
|
||||
w.Rovers[id] = r
|
||||
if err := w.Atlas.SetTile(r.Pos, objects.Empty); err != nil {
|
||||
return objects.Empty, err
|
||||
} else {
|
||||
|
|
|
@ -164,4 +164,9 @@ func TestWorld_RoverStash(t *testing.T) {
|
|||
tile, err := world.Atlas.GetTile(pos)
|
||||
assert.NoError(t, err, "Failed to get tile")
|
||||
assert.Equal(t, objects.Empty, tile, "Stash failed to remove object from atlas")
|
||||
|
||||
inv, err := world.RoverInventory(a)
|
||||
assert.NoError(t, err, "Failed to get inventory")
|
||||
assert.Equal(t, Item{Type: objects.SmallRock}, inv[0])
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue