Fix bug in housing check and add test

This commit is contained in:
Nate Bowman
2026-11-16 19:19:26 -05:00
parent 1b9266ff09
commit 0780fec1fb
2 changed files with 27 additions and 3 deletions

View File

@@ -16,14 +16,14 @@ class Housing():
if world.get_effective_population() + required > pop_space:
raise YallGotHousedException
return True
def check_housing_safe(self, world, thing):
try:
self.check_housing(world, thing)
return self.check_housing(world, thing)
except YallGotHousedException:
return False
else:
return True
def __init__(self):

View File

@@ -949,3 +949,27 @@ class TestWorld(unittest.TestCase):
100,
200],
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)