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
|
// WarpRover sets an rovers position
|
||||||
func (w *World) WarpRover(id uuid.UUID, pos vector.Vector) error {
|
func (w *World) WarpRover(id uuid.UUID, pos vector.Vector) error {
|
||||||
w.worldMutex.Lock()
|
w.worldMutex.Lock()
|
||||||
|
@ -260,6 +272,7 @@ func (w *World) RoverStash(id uuid.UUID) (byte, error) {
|
||||||
} else {
|
} else {
|
||||||
if objects.IsStashable(tile) {
|
if objects.IsStashable(tile) {
|
||||||
r.Inventory = append(r.Inventory, Item{Type: tile})
|
r.Inventory = append(r.Inventory, Item{Type: tile})
|
||||||
|
w.Rovers[id] = r
|
||||||
if err := w.Atlas.SetTile(r.Pos, objects.Empty); err != nil {
|
if err := w.Atlas.SetTile(r.Pos, objects.Empty); err != nil {
|
||||||
return objects.Empty, err
|
return objects.Empty, err
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -164,4 +164,9 @@ func TestWorld_RoverStash(t *testing.T) {
|
||||||
tile, err := world.Atlas.GetTile(pos)
|
tile, err := world.Atlas.GetTile(pos)
|
||||||
assert.NoError(t, err, "Failed to get tile")
|
assert.NoError(t, err, "Failed to get tile")
|
||||||
assert.Equal(t, objects.Empty, tile, "Stash failed to remove object from atlas")
|
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