Exemplo n.º 1
0
 def test_calculate_maintanance_cost(self):
     self.assertEqual(
         TurnCalculation(
             self.city, self.data, self.user.profile
         ).calculate_maintenance_cost(),
         40,
     )
Exemplo n.º 2
0
 def test_health_care_actions(self):
     self.assertEqual(Disease.objects.count(), 1)
     self.assertEqual(
         Disease.objects.count(),
         sum([len(c.diseases) for c in self.rc.citizens_in_city.values()]))
     self.assertEqual(self.temp_clinic.water, 0)
     self.assertEqual(self.temp_clinic.energy, 0)
     productivity_before = (sum([
         b.employee_productivity()
         for b in self.rc.list_of_buildings.values()
         if not isinstance(b.instance, Residential)
     ]))
     TurnCalculation(self.city, self.rc, self.user.profile).run()
     self.rc = RootClass(self.city, User.objects.latest("id"))
     self.temp_clinic = self.rc.list_of_buildings[self.clinic]
     self.assertEqual(
         Disease.objects.count(),
         sum([len(c.diseases) for c in self.rc.citizens_in_city.values()]))
     self.assertLessEqual(
         sum([len(c.diseases) for c in self.rc.citizens_in_city.values()]),
         15)
     self.assertLessEqual(Disease.objects.count(), 15)
     self.assertLess(
         sum([
             b.employee_productivity()
             for b in self.rc.list_of_buildings.values()
             if not isinstance(b.instance, Residential)
         ]), productivity_before)
Exemplo n.º 3
0
 def test_if_right_homless_was_selected(self):
     self.r1 = StandardLevelResidentialZone.objects.latest("id")
     self.r1.max_population = 1
     self.r1.save()
     self.f = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnonKA",
         surname="FeSurname",
         sex=FEMALE,
     )
     self.m = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnON",
         surname="MaSurname",
         sex=MALE,
     )
     RC = RootClass(self.city, User.objects.latest("id"))
     sa = SocialAction(self.city, self.user.profile, RC)
     self.assertEqual(self.r1.resident.count(), 0)
     sa.find_home()
     TurnCalculation(self.city, RC, self.user.profile).save_all()
     self.assertEqual(self.r1.resident.count(), 1)
Exemplo n.º 4
0
 def test_assign_student_to_school_pass_with_education(self):
     Education.objects.create(
         citizen=self.f,
         name=ELEMENTARY,
         effectiveness=0.5,
         cur_year_of_learning=4,
         max_year_of_learning=8,
         if_current=False,
     )
     self.assertEqual(self.f.school_object, None)
     self.assertEqual(self.f.education_set.all().count(), 1)
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(RC.citizens_in_city[self.f].current_education, None)
     self.school.check_for_student_in_city(self.f,
                                           RC.citizens_in_city[self.f])
     TurnCalculation(self.city, RC, self.user.profile).save_all()
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(self.f.school_object, self.school)
     self.assertEqual(self.f.education_set.all().count(), 1)
     self.assertNotEqual(RC.citizens_in_city[self.f].current_education,
                         None)
     self.assertEqual(
         RC.citizens_in_city[self.f].current_education.if_current, True)
     self.assertEqual(
         RC.citizens_in_city[self.f].current_education.max_year_of_learning,
         self.school.years_of_education,
     )
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_temp_prison_in_turn_calculation(self):
        temp_citizens = Citizen.objects.all()[:3]
        temp_prison = self.rc.list_of_buildings.get(self.prison)
        for c in temp_citizens:
            temp_citizen = self.rc.citizens_in_city[c]
            temp_citizen.change_citizen_into_criminal()
            temp_citizen.current_profession.proficiency = 0.25
            temp_citizen.current_profession.save()
            temp_prison.put_criminal_to_jail(temp_citizen)

        self.rc = RootClass(self.city, User.objects.latest("id"))
        self.temp_prison = self.rc.list_of_buildings[self.prison]

        self.assertEqual(self.temp_prison.water_required, 19)
        self.assertEqual(self.temp_prison.energy_required, 29)
        self.assertEqual(self.temp_prison.num_of_prisoners, 3)
        total_proficiency_before = (sum([
            x.current_profession.proficiency
            for x in self.temp_prison.prisoners
        ]))
        TurnCalculation(self.city, self.rc, self.user.profile).run()
        self.assertLess(
            sum([
                x.current_profession.proficiency
                for x in self.temp_prison.prisoners
            ]), total_proficiency_before)
        self.assertGreater(self.temp_prison.energy, 0)
        self.assertEqual(self.temp_prison.num_of_prisoners, 3)
Exemplo n.º 7
0
 def test(self):
     self.user.profile.current_turn = 2
     self.user.profile.save()
     self.assertEqual(self.m.age, 21)
     self.assertEqual(self.f.age, 21)
     self.sa.update_age()
     TurnCalculation(self.city, self.RC, self.user.profile).save_all()
     self.m = Citizen.objects.get(id=self.m.id)
     self.f = Citizen.objects.get(id=self.f.id)
     self.assertEqual(self.m.age, 22)
     self.assertEqual(self.f.age, 22)
Exemplo n.º 8
0
    def test_is_police_strategy_works_within_turn_calculation(self):
        for c in [
                c for c in self.rc.citizens_in_city.values()
                if not isinstance(c.instance.workplace_object, Prison)
        ][:5]:
            c.change_citizen_into_criminal()
        self.assertEqual(
            sum([
                c.instance.cash for c in self.rc.citizens_in_city.values()
                if c.current_profession.name == CRIMINAL
            ]), 0)
        self.assertEqual(int(self.city.cash), 1000000)
        self.assertEqual(
            sum([
                c.current_profession.proficiency
                for c in self.rc.citizens_in_city.values()
                if c.current_profession.name == CRIMINAL
            ]), 0)
        self.assertEqual(self.temp_prison.num_of_prisoners, 0)
        self.assertEqual(
            int(
                sum([
                    b.criminal_prevention
                    for b in self.rc.list_of_buildings.values()
                ])), 0)

        self.assertEqual(self.temp_police_station.water, 0)
        self.assertEqual(self.temp_police_station.energy, 0)

        TurnCalculation(self.city, self.rc, self.user.profile).run()

        temp_police_station = self.rc.list_of_buildings[self.police_station]
        self.assertNotEqual(temp_police_station.energy, 0)

        self.assertEqual(
            int(
                sum([
                    b.criminal_prevention
                    for b in self.rc.list_of_buildings.values()
                ])), 8)
        self.assertNotEqual(int(self.city.cash), 1000000)
        self.assertLess(
            sum([
                c.current_profession.proficiency
                for c in self.rc.citizens_in_city.values()
                if c.current_profession.name == CRIMINAL
            ]), 0.15)
        self.rc = RootClass(self.city, User.objects.latest("id"))
        self.temp_prison = self.rc.list_of_buildings[self.p]
        self.assertIn(self.temp_prison.num_of_prisoners, [3, 4, 5])
Exemplo n.º 9
0
 def test_financial_action(self):
     sr = StandardLevelResidentialZone.objects.latest("id")
     family = Family.objects.create(city=self.city)
     p = Citizen.objects.create(
         city=self.city,
         age=28,
         month_of_birth=6,
         cash=50,
         health=5,
         name="0",
         surname="1",
         sex=MALE,
         education=PHD,
         resident_object=sr,
         family=family,
     )
     m = Citizen.objects.create(
         city=self.city,
         age=28,
         month_of_birth=6,
         cash=70,
         health=5,
         name="0",
         surname="2",
         sex=FEMALE,
         education=ELEMENTARY,
         resident_object=sr,
         family=family,
     )
     p.partner_id = m.id
     m.partner_id = p.id
     p.save()
     m.save()
     data = RootClass(city=self.city, user=User.objects.latest("id"))
     tc = TurnCalculation(self.city, data, self.user.profile)
     tc.financial_actions()
Exemplo n.º 10
0
    def test_employee_allocation(self):
        self.city = City.objects.latest("id")
        self.user = User.objects.latest('id')
        Market.objects.create(profile=self.user.profile)
        self.RC = RootClass(self.city, self.user)
        self.RA = ResourceAllocation(city=self.city, data=self.RC)

        for build in self.RC.list_of_workplaces:
            self.assertEqual(build.employee.count(), 0)

        for x in range(8):
            TurnCalculation(
                city=self.city, data=self.RC, profile=self.user.profile
            ).run()

        for build in self.RC.list_of_workplaces:
            self.assertLessEqual(
                build.employee.count(), build.elementary_employee_needed
            )
Exemplo n.º 11
0
 def test_chance_to_married_succed_scenario(self):
     self.user.profile.chance_to_marriage_percent = 1.00
     m = Citizen.objects.get(id=self.m.id)
     f = Citizen.objects.get(id=self.f.id)
     self.assertEqual(m.partner_id, 0)
     self.assertEqual(f.partner_id, 0)
     self.assertEqual(f.family, self.she_family)
     self.assertEqual(m.family, self.he_family)
     self.assertEqual(m.resident_object,
                      StandardLevelResidentialZone.objects.latest("id"))
     self.assertEqual(f.resident_object, None)
     self.assertEqual(
         self.RC.list_of_buildings[StandardLevelResidentialZone.objects.
                                   latest("id")].people_in_charge,
         1,
     )
     self.assertEqual(len(self.RC.families), 2)
     sa = SocialAction(self.city, self.user.profile, self.RC)
     sa.match_marriages()
     TurnCalculation(self.city, self.RC, self.user.profile).save_all()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(len(self.RC.families), 1)
     self.assertEqual(self.user.profile.chance_to_marriage_percent, 1.00)
     m = Citizen.objects.get(id=self.m.id)
     f = Citizen.objects.get(id=self.f.id)
     self.assertEqual(m.partner_id, f.id)
     self.assertEqual(f.partner_id, m.id)
     self.assertEqual(f.family, m.family)
     self.assertEqual(f.resident_object,
                      StandardLevelResidentialZone.objects.latest("id"))
     self.assertEqual(m.resident_object,
                      StandardLevelResidentialZone.objects.latest("id"))
     self.assertEqual(
         self.RC.list_of_buildings[StandardLevelResidentialZone.objects.
                                   latest("id")].people_in_charge,
         2,
     )
Exemplo n.º 12
0
    def test_breed_update(self):
        data = RootClass(city=self.city, user=self.user)
        tc = TurnCalculation(
            city=self.city, data=data, profile=self.user.profile
        )

        self.assertEqual(Cattle.objects.all().count(), 0)
        self.assertEqual(Milk.objects.all().count(), 0)
        self.cf.buy_cattle(20, data)
        self.assertEqual(Milk.objects.count(), 0)
        self.assertEqual(Cattle.objects.count(), 1)
        data.list_of_workplaces[self.cf].wage_payment(self.city)

        tc.update_breeding_status()
        tc.save_all()
        self.assertEqual(len(data.market.resources[Milk].instances), 1)
        self.assertEqual(Milk.objects.count(), 1)
        self.assertEqual(Milk.objects.latest("id").size, 33)
        self.assertEqual(data.market.resources[Milk].instances[-1].size, 33)
        self.assertEqual(data.market.resources[Milk].instances[-1].quality, 81)
        self.assertEqual(Milk.objects.latest("id").quality, 81)
        self.assertEqual(Cattle.objects.count(), 1)

        tc.update_breeding_status()
        tc.save_all()
        self.assertEqual(Cattle.objects.count(), 1)
        self.assertEqual(Milk.objects.latest("id").size, 66)
        self.assertEqual(Milk.objects.latest("id").quality, 81)
        self.assertEqual(Milk.objects.count(), 1)
        self.assertEqual(len(data.market.resources[Milk].instances), 1)
        self.assertEqual(data.market.resources[Milk].instances[-1].size, 66)
        self.assertEqual(data.market.resources[Milk].instances[-1].quality, 81)

        tc.update_breeding_status()
        tc.save_all()
        self.assertEqual(Cattle.objects.count(), 1)
        self.assertEqual(Milk.objects.latest("id").size, 99)
        self.assertEqual(Milk.objects.latest("id").quality, 81)
        self.assertEqual(Milk.objects.count(), 1)
        self.assertEqual(len(data.market.resources[Milk].instances), 1)
        self.assertEqual(data.market.resources[Milk].instances[-1].size, 99)
        self.assertEqual(data.market.resources[Milk].instances[-1].quality, 81)
Exemplo n.º 13
0
 def test_police_strategy_in_turn_calculation(self):
     rc = RootClass(self.city, User.objects.latest("id"))
     tc = TurnCalculation(self.city, rc, self.user.profile)
     self.assertIsNotNone(tc.police_strategy)
Exemplo n.º 14
0
 def test_turn_calculation_run(self):
     TestHelper(self.city, User.objects.latest("id")).populate_city()
     rc = RootClass(self.city, User.objects.latest("id"))
     tc = TurnCalculation(self.city, rc, self.user.profile)
     tc.run()