Fix bug in housing check and add test
This commit is contained in:
@@ -16,14 +16,14 @@ class Housing():
|
|||||||
if world.get_effective_population() + required > pop_space:
|
if world.get_effective_population() + required > pop_space:
|
||||||
raise YallGotHousedException
|
raise YallGotHousedException
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_housing_safe(self, world, thing):
|
def check_housing_safe(self, world, thing):
|
||||||
try:
|
try:
|
||||||
self.check_housing(world, thing)
|
return self.check_housing(world, thing)
|
||||||
except YallGotHousedException:
|
except YallGotHousedException:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -949,3 +949,27 @@ class TestWorld(unittest.TestCase):
|
|||||||
100,
|
100,
|
||||||
200],
|
200],
|
||||||
game.world)
|
game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_production_queue_two_units(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||||
|
game.world._add_building(Buildings.HOUSE, {}, {})
|
||||||
|
|
||||||
|
training = 21
|
||||||
|
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
|
||||||
|
game.play_until(1)
|
||||||
|
self.assertEqual(4, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(training)
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(training + 10)
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(2*training)
|
||||||
|
self.assertEqual(6, game.world.population)
|
||||||
|
|||||||
Reference in New Issue
Block a user