diff --git a/tests/test.py b/tests/test.py index a69d5ed..2d7ca78 100644 --- a/tests/test.py +++ b/tests/test.py @@ -92,6 +92,39 @@ class TestWorld(unittest.TestCase): self.assertResourcesMatch([150, new_wood, 100, 200], game.world) + def test_wood_stale_camp(self): + game = Gameplay() + + wood_amount_per_camp = 1000 + + wood_rate_times_60 = 23.4 + wood_rate_decrease = 0.85 + slow_wood_rate_times_60 = wood_rate_times_60*wood_rate_decrease + + game.world._add_building(Buildings.LUMBERCAMP, {}, {}) + game.assign_villager(1, Tasks.IDLE, Tasks.WOOD) + + game.play_until(60) + new_wood = 200 + wood_rate_times_60 + self.assertResourcesMatch([200, new_wood, 100, 200], game.world) + + camp_expires = 60*wood_amount_per_camp/wood_rate_times_60 + + game.play_until(camp_expires) + new_wood = 200 + wood_rate_times_60*(camp_expires/60) + self.assertResourcesMatch([200, new_wood, 100, 200], game.world) + self.assertResourcesMatch([200, + 200 + wood_amount_per_camp, + 100, + 200], + game.world) + + game.play_until(camp_expires + 60) + new_wood += slow_wood_rate_times_60 + + self.assertResourcesMatch([200, new_wood, 100, 200], game.world) + + def test_good_villager_task_assign(self): game = Gameplay() game.assign_villager(5, Tasks.IDLE, Tasks.SHEEP) @@ -136,6 +169,18 @@ class TestWorld(unittest.TestCase): self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings) + def test_build_lumber_camp_three_villagers(self): + lc_build_time = 35 + lc_build_time_three_vils = 3*lc_build_time/(3 + 2) + + game = Gameplay() + game.build(0, Buildings.LUMBERCAMP, [Tasks.IDLE]*3, [Tasks.IDLE]*3) + game.play_until(lc_build_time_three_vils - 1) + self.assertTrue(Buildings.LUMBERCAMP not in game.world.buildings) + game.play_until(lc_build_time_three_vils) + self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings) + + def test_building_adds_gatherable(self): lc_build_time = 35 @@ -973,3 +1018,108 @@ class TestWorld(unittest.TestCase): game.play_until(2*training) self.assertEqual(6, game.world.population) + + + def test_production_queue_new_building(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(10) + game.world._add_building(Buildings.BARRACKS, {}, {}) + + game.play_until(training) + self.assertEqual(5, game.world.population) + + game.play_until(training + 10) + self.assertEqual(6, game.world.population) + + + def test_production_queue_new_housing(self): + game = Gameplay() + + game.world._add_building(Buildings.BARRACKS, {}, {}) + game.set_housed_is_error(0, False) + + training = 21 + + game.queue_unit(0, Units.MILITIA) + game.queue_unit(0, Units.MILITIA) + + game.play_until(3*training) + self.assertEqual(5, game.world.population) + + game.world._add_building(Buildings.HOUSE, {}, {}) + game.play_until(4*training) + self.assertEqual(6, game.world.population) + + + def test_research_bit_axe(self): + game = Gameplay() + + game.world.age = Ages.FEUDAL + + wood_amount_per_camp = 1000 + + wood_rate_times_60 = 23.4 + bit_axe_mult = 1.2 + wood_rate_times_60 *= bit_axe_mult + + bit_axe_time = 25 + + wood_rate_decrease = 0.85 + slow_wood_rate_times_60 = wood_rate_times_60*wood_rate_decrease + + game.world._add_building(Buildings.LUMBERCAMP, {}, {}) + game.queue_research(0, Research.DOUBLEBITAXE) + + game.assign_villager(bit_axe_time, Tasks.IDLE, Tasks.WOOD) + + game.play_until(bit_axe_time + 60) + new_wood = 150 + wood_rate_times_60 + self.assertResourcesMatch([100, new_wood, 100, 200], game.world) + + camp_duration = 60*wood_amount_per_camp/wood_rate_times_60 + + game.play_until(bit_axe_time + camp_duration) + new_wood = 150 + wood_rate_times_60*(camp_duration/60) + self.assertResourcesMatch([100, new_wood, 100, 200], game.world) + self.assertResourcesMatch([100, + 150 + wood_amount_per_camp, + 100, + 200], + game.world) + + game.play_until(bit_axe_time + camp_duration + 60) + new_wood += slow_wood_rate_times_60 + + self.assertResourcesMatch([100, new_wood, 100, 200], game.world) + + + def test_research_bit_axe_partial_start(self): + game = Gameplay() + + wood_rate_times_60 = 23.4 + bit_axe_mult = 1.2 + + bit_axe_time = 25 + + game.world.age = Ages.FEUDAL + game.world._add_building(Buildings.LUMBERCAMP, {}, {}) + + game.assign_villager(0, Tasks.IDLE, Tasks.WOOD) + game.queue_research(35, Research.DOUBLEBITAXE) + + game.play_until(60) + new_wood = 150 + wood_rate_times_60 + self.assertResourcesMatch([100, new_wood, 100, 200], game.world) + + game.play_until(120) + new_wood = 150 + wood_rate_times_60*(1 + bit_axe_mult) + self.assertResourcesMatch([100, new_wood, 100, 200], game.world)