Add a test to check daytime and rover recharge

This commit is contained in:
Marc Di Luzio 2020-07-07 21:30:51 +01:00
parent 3ba7652c74
commit 254957cde5

View file

@ -313,3 +313,40 @@ func TestWorld_Charge(t *testing.T) {
} }
} }
func TestWorld_Daytime(t *testing.T) {
world := NewWorld(1)
a, err := world.SpawnRover()
assert.NoError(t, err)
// Remove rover charge
rover := world.Rovers[a]
rover.Charge = 0
world.Rovers[a] = rover
// Try and recharge, should work
world.RoverRecharge(a)
assert.Equal(t, 1, world.Rovers[a].Charge)
// Loop for half the day
for i := 0; i < world.TicksPerDay/2; i++ {
assert.True(t, world.Daytime())
world.ExecuteCommandQueues()
}
// Remove rover charge again
rover = world.Rovers[a]
rover.Charge = 0
world.Rovers[a] = rover
// Try and recharge, should fail
world.RoverRecharge(a)
assert.Equal(t, 0, world.Rovers[a].Charge)
// Loop for half the day
for i := 0; i < world.TicksPerDay/2; i++ {
assert.False(t, world.Daytime())
world.ExecuteCommandQueues()
}
}