Ejemplo n.º 1
0
 def setUp(self):
     self.city = City.objects.latest("id")
     self.user = User.objects.latest('id')
     Market.objects.create(profile=self.user.profile)
     TestHelper(self.city, self.user).populate_city()
     self.RC = RootClass(self.city, self.user)
     self.TM = TrashManagement(self.RC)
Ejemplo n.º 2
0
 def test_probability_of_become_a_criminal_with_huge_pollutions_and_trash(
         self):
     self.assertGreater(
         self.temp_citizen._probability_of_become_a_criminal(), 1.2)
     TrashManagement(self.RC).generate_trash()
     TrashManagement(self.RC).generate_trash()
     with mock.patch(
             'citizen_engine.temp_models.TempCitizen._get_sum_of_pollutions',
             mock.Mock(return_value=2)):
         self.assertLess(
             self.temp_citizen._probability_of_become_a_criminal(), 0.35)
Ejemplo n.º 3
0
 def setUp(self):
     self.city = City.objects.latest("id")
     self.wind_plant = WindPlant.objects.latest("id")
     self.water_tower = WaterTower.objects.latest("id")
     self.user = User.objects.latest('id')
     Market.objects.create(profile=self.user.profile)
     self.td_instance = TradeDistrict.objects.create(
         city=self.city, city_field=Field.objects.latest("id"))
     fc = FoodCompany.objects.create(cash=10,
                                     trade_district=self.td_instance)
     TestHelper(self.city, self.user).populate_city()
     self.rc = RootClass(self.city, User.objects.latest("id"))
     self.td = self.rc.list_of_trade_districts[self.td_instance]
     self.trash_management = TrashManagement(data=self.rc)
     self.collect_garbage = CollectGarbage(city=self.city, data=self.rc)
     self.fc = self.rc.companies[fc]
Ejemplo n.º 4
0
 def test_of_collect_garbage_with_save_trash_to_another_turn(self):
     DumpingGround.objects.update(current_space_for_trash=0)
     dumping_ground = DumpingGround.objects.latest("id")
     self.assertEqual(dumping_ground.current_space_for_trash, 0)
     self.RC = RootClass(self.city, self.user)
     self.assertEqual(Trash.objects.count(), 0)
     self.assertEqual(
         sum([
             len(b.temp_trash) for b in self.RC.list_of_buildings.values()
         ]), 0)
     for x in range(10):
         TrashManagement(data=self.RC).generate_trash()
     self.assertEqual(Trash.objects.count(), 0)
     self.assertEqual(
         sum([
             len(b.temp_trash) for b in self.RC.list_of_buildings.values()
         ]), 60)
     CollectGarbage(city=self.city, data=self.RC).run()
     TurnCalculation(city=self.city,
                     data=self.RC,
                     profile=self.user.profile).save_all()
     self.assertEqual(Trash.objects.count(), 30)
     self.assertEqual(
         sum([
             len(b.temp_trash) for b in self.RC.list_of_buildings.values()
         ]), 30)
     dumping_ground = DumpingGround.objects.latest("id")
     self.assertGreater(dumping_ground.current_space_for_trash, 10)
Ejemplo n.º 5
0
 def setUp(self):
     self.city = City.objects.latest("id")
     self.wind_plant = WindPlant.objects.latest("id")
     self.water_tower = WaterTower.objects.latest("id")
     self.user = User.objects.latest('id')
     Market.objects.create(profile=self.user.profile)
     TestHelper(self.city, self.user).populate_city()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.trash_management = TrashManagement(data=self.RC)
     self.collect_garbage = CollectGarbage(city=self.city, data=self.RC)
Ejemplo n.º 6
0
class CityStatsTests(test.TestCase):
    fixtures = ["basic_fixture_resources_and_employees.json"]

    def tearDown(self):
        Citizen.objects.all().delete()
        Profession.objects.all().delete()
        Education.objects.all().delete()
        Family.objects.all().delete()
        Market.objects.all().delete()

    def setUp(self):
        self.city = City.objects.latest("id")
        self.user = User.objects.latest('id')
        Market.objects.create(profile=self.user.profile)
        TestHelper(self.city, self.user).populate_city()
        self.RC = RootClass(self.city, self.user)
        self.TM = TrashManagement(self.RC)

    def test_generate_trash_except_dumping_ground(self):
        dg = DumpingGround.objects.create(
            city=self.city, city_field=Field.objects.latest('id'))
        result = []
        for trash in dg.trash.values():
            result.append(trash)
        self.assertEqual(result, [])

        self.TM.generate_trash()

        for trash in dg.trash.values():
            result.append(trash)
        self.assertEqual(result, [])

    def test_generate_trash(self):
        self.assertEqual(
            sum([
                len(b.temp_trash) for b in self.RC.list_of_buildings.values()
            ]), 0)
        self.TM.generate_trash()
        self.assertEqual(
            sum([
                len(b.temp_trash) for b in self.RC.list_of_buildings.values()
            ]), 5)

    def test_update_time(self):
        self.TM.generate_trash()
        for building in self.RC.list_of_buildings:
            for trash in building.trash.values("time"):
                self.assertEqual(trash["time"], 0)
        self.TM.update_trash_time()
        for building in self.RC.list_of_buildings:
            for trash in building.trash.values("time"):
                self.assertEqual(trash["time"], 1)
Ejemplo n.º 7
0
 def test_collect_trash_by_temp_model(self):
     self.rc = RootClass(self.city, self.user)
     TrashManagement(data=self.rc).generate_trash()
     dg = DumpingGround.objects.latest("id")
     temp_dumping_ground = self.rc.list_of_buildings[dg]
     wp = self.rc.list_of_buildings[WindPlant.objects.latest('id')]
     self.assertNotEqual(wp.temp_trash, [])
     self.assertEqual(temp_dumping_ground.current_capacity, 0)
     temp_dumping_ground.collect_trash(wp)
     self.assertNotEqual(temp_dumping_ground.current_capacity, 0)
     self.assertEqual(wp.temp_trash, [])
Ejemplo n.º 8
0
 def setUp(self):
     self.city = City.objects.get(id=1)
     self.user = User.objects.latest("id")
     Market.objects.create(profile=self.user.profile)
     TestHelper(self.city, User.objects.latest("id")).populate_city()
     self.citizen = WindPlant.objects.last().employee.last()
     self.education = Education.objects.create(
         citizen=self.citizen, name=COLLEGE, effectiveness=0.8, if_current=False
     )
     self.RC = RootClass(self.city, User.objects.latest("id"))
     TrashManagement(data=self.RC).generate_trash()
     self.citizen_instance = self.RC.citizens_in_city[self.citizen]
Ejemplo n.º 9
0
    def test_max_capacity_of_dumping_ground(self):
        self.rc = RootClass(self.city, self.user)
        TrashManagement(data=self.rc).generate_trash()
        dg = DumpingGround.objects.latest("id")
        temp_dumping_ground = self.rc.list_of_buildings[dg]
        self.assertEqual(
            int(temp_dumping_ground._get_total_employees_capacity()), 166)

        temp_dumping_ground.people_in_charge = 10
        temp_dumping_ground.productivity = 0.66
        self.assertEqual(
            int(temp_dumping_ground._get_total_employees_capacity()), 333)

        temp_dumping_ground.people_in_charge = 2
        temp_dumping_ground.productivity = 0.10
        self.assertEqual(
            int(temp_dumping_ground._get_total_employees_capacity()), 66)
Ejemplo n.º 10
0
 def test_list_of_trash_for_building(self):
     Trash.objects.all().delete()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         self.RC.list_of_buildings[WindPlant.objects.latest(
             "id")].temp_trash, [])
     self.assertEqual(
         self.RC.list_of_buildings[WaterTower.objects.latest(
             "id")].temp_trash, [])
     TrashManagement(data=self.RC).generate_trash()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         self.RC.list_of_buildings[WindPlant.objects.latest(
             "id")].temp_trash, [])
     self.assertEqual(
         self.RC.list_of_buildings[WaterTower.objects.latest(
             "id")].temp_trash, [])
     self.assertEqual(
         self.RC.list_of_buildings[DumpingGround.objects.latest(
             "id")].temp_trash, [])
Ejemplo n.º 11
0
 def run(self):
     SocialAction(self.city, self.profile, self.data).run()
     ResourceAllocation(self.city, self.data).run()
     self.fire_strategy.calculate_probability_of_fire_among_the_all_buildings(
     )
     self.fire_strategy.simulate_fire_in_the_city()
     self.police_strategy.apply_crime_prevention_in_city()
     self.police_strategy.calculate_criminals_vs_police_in_city()
     self.health_of_population_action()
     self.health_care_actions()
     self.prisons_actions()
     TrashManagement(self.data).run()
     CollectGarbage(self.city, self.data).run()
     self.financial_actions()
     self.collect_mass()
     self.execute_maintenance()
     self.update_build_status()
     self.update_harvest_status()
     self.update_breeding_status()
     self.trade_district_actions()
     self.save_all()
Ejemplo n.º 12
0
class TestTrashAllocation(test.TestCase):
    fixtures = ["basic_fixture_resources_and_employees2.json"]

    def tearDown(self):
        Citizen.objects.all().delete()
        Profession.objects.all().delete()
        Education.objects.all().delete()
        Family.objects.all().delete()
        Market.objects.all().delete()

    def setUp(self):
        self.city = City.objects.latest("id")
        self.wind_plant = WindPlant.objects.latest("id")
        self.water_tower = WaterTower.objects.latest("id")
        self.user = User.objects.latest('id')
        Market.objects.create(profile=self.user.profile)
        self.td_instance = TradeDistrict.objects.create(
            city=self.city, city_field=Field.objects.latest("id"))
        fc = FoodCompany.objects.create(cash=10,
                                        trade_district=self.td_instance)
        TestHelper(self.city, self.user).populate_city()
        self.rc = RootClass(self.city, User.objects.latest("id"))
        self.td = self.rc.list_of_trade_districts[self.td_instance]
        self.trash_management = TrashManagement(data=self.rc)
        self.collect_garbage = CollectGarbage(city=self.city, data=self.rc)
        self.fc = self.rc.companies[fc]

    def test_is_trade_district_in_rc(self):
        self.assertEqual(len(self.rc.list_of_trade_districts), 1)

    def test_is_trade_district_contain_any_company(self):
        self.assertEqual(len(self.rc.companies), 1)
        self.assertEqual(
            len(self.rc.list_of_trade_districts[self.td_instance].companies),
            1)
        self.assertEqual(
            id(list(self.rc.companies.values())[0]),
            id(
                list(self.rc.list_of_trade_districts[
                    self.td_instance].companies.values())[0]))

    def test_is_trade_district_also_generate_trash(self):
        self.assertEqual(
            len(self.rc.list_of_trade_districts[self.td_instance].temp_trash),
            0)
        self.trash_management.generate_trash()
        self.assertEqual(
            len(self.rc.list_of_trade_districts[self.td_instance].temp_trash),
            1)

    def test_is_trade_district_pass_resources_to_companies(self):
        self.assertEqual(self.td.water, 0)
        self.assertEqual(self.td.water_required, 10)
        self.assertEqual(self.td.energy, 0)
        self.assertEqual(self.td.energy_required, 20)
        self.assertEqual(self.fc.water, 0)
        self.assertEqual(self.fc.water_required, 10)
        self.assertEqual(self.fc.energy, 0)
        self.assertEqual(self.fc.energy_required, 20)
        ResourceAllocation(self.city, self.rc).run()
        self.assertEqual(self.td.water, 10)
        self.assertEqual(self.td.water_required, 10)
        self.assertEqual(self.td.energy, 20)
        self.assertEqual(self.td.energy_required, 20)
        self.assertEqual(self.fc.water, 10)
        self.assertEqual(self.fc.water_required, 10)
        self.assertEqual(self.fc.energy, 20)
        self.assertEqual(self.fc.energy_required, 20)

    def test_trade_district_trash_generation(self):
        self.assertEqual(len(self.td.temp_trash), 0)
        self.trash_management.generate_trash()
        self.assertEqual(len(self.td.companies), 1)
        self.assertEqual(len(self.td.temp_trash), 1)
        tt = self.td.temp_trash.pop()
        self.assertEqual(tt.size, 0.8)