Exemple #1
0
 def test_for_find_better_job(self):
     RC = RootClass(self.city, User.objects.latest("id"))
     citizen = RC.citizens_in_city[self.s]
     self.assertEqual(citizen.instance.workplace_object, None)
     CitizenWorkEngine(RC, self.city).human_resources_allocation()
     for c in RC.citizens_in_city:
         c.save()
     cwo = citizen.instance.workplace_object
     elementary_vacancies_before = RC.list_of_workplaces[
         cwo].elementary_vacancies
     self.assertEqual(Profession.objects.all().count(), 3)
     self.assertEqual(Profession.objects.filter(if_current=True).count(), 3)
     self.assertNotEqual(citizen.instance.workplace_object, None)
     school = PrimarySchool.objects.create(
         city=self.city,
         city_field=Field.objects.latest("id"),
         if_under_construction=False,
     )
     RC = RootClass(self.city, User.objects.latest("id"))
     CitizenWorkEngine(RC, self.city).human_resources_allocation()
     self.assertEqual(
         RC.list_of_workplaces[cwo].elementary_vacancies,
         elementary_vacancies_before + 1,
     )
     for c in RC.citizens_in_city:
         c.save()
         [p.save() for p in RC.citizens_in_city[c].professions]
     self.assertEqual(Profession.objects.all().count(), 4)
     self.assertEqual(Profession.objects.filter(if_current=True).count(), 3)
     self.assertEqual(
         Profession.objects.filter(if_current=False).count(), 1)
     citizen = RC.citizens_in_city[self.s]
     self.assertEqual(citizen.instance.workplace_object, school)
Exemple #2
0
 def test_wage_payment_for_one_person_pass_with_two_education(self):
     Education.objects.create(citizen=self.s,
                              name=ELEMENTARY,
                              effectiveness=1,
                              if_current=False)
     Education.objects.create(citizen=self.s,
                              name=COLLEGE,
                              effectiveness=1,
                              if_current=False)
     Profession.objects.create(citizen=self.s,
                               proficiency=0.4,
                               name="Nauczyciel",
                               education=COLLEGE)
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(self.city.cash, 1000000.00)
     self.assertEqual(RC.citizens_in_city[self.s].instance.cash, 100)
     self.assertEqual(RC.list_of_workplaces[self.school].workers_costs, 0)
     CitizenWorkEngine(RC, self.city).wage_payment_in_all_workplaces()
     self.assertEqual(
         round(RC.list_of_workplaces[self.school].workers_costs), 226)
     self.assertEqual(int(self.city.cash), 999773)
     self.assertEqual(int(RC.citizens_in_city[self.s].instance.cash), 326)
     self.assertEqual(
         round(
             RC.citizens_in_city[
                 self.s].get_wage_avg_all_edu_effectiveness(), 2), 0.33)
     self.assertEqual(
         RC.citizens_in_city[self.s].get_avg_all_edu_effectiveness(), 1)
Exemple #3
0
 def run(self):
     self.match_marriages()
     self.born_child()
     self.find_home()
     CitizenWorkEngine(self.city_data, self.city).human_resources_allocation()
     self.launch_school()
     self.update_age()
Exemple #4
0
 def test_failed_scenario(self):
     self.f.resident_object = None
     self.m.resident_object = None
     self.s.resident_object = None
     RC = RootClass(self.city, User.objects.latest("id"))
     self.save_all_ob_from(RC.citizens_in_city)
     self.assertEqual(self.f.workplace_object, None)
     self.assertEqual(self.m.workplace_object, None)
     self.assertEqual(self.s.workplace_object, None)
     RC = RootClass(self.city, User.objects.latest("id"))
     CitizenWorkEngine(RC, self.city).human_resources_allocation()
     self.save_all_ob_from(RC.citizens_in_city)
     self.assertEqual(self.f.workplace_object, None)
     self.assertEqual(self.m.workplace_object, None)
     self.assertEqual(self.s.workplace_object, None)
Exemple #5
0
 def test_gain_knowledge_without_education_failed(self):
     Education.objects.create(citizen=self.s,
                              name=ELEMENTARY,
                              effectiveness=1,
                              if_current=False)
     Education.objects.create(citizen=self.s,
                              name=COLLEGE,
                              effectiveness=1,
                              if_current=False)
     Profession.objects.create(citizen=self.s,
                               proficiency=0.5,
                               name="Nauczyciel",
                               education=COLLEGE)
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(RC.citizens_in_city[self.m].current_education, None)
     self.assertEqual(
         RC.citizens_in_city[self.s].current_profession.proficiency, 0.5)
     CitizenWorkEngine(RC, self.city).human_resources_allocation()
     self.assertEqual(RC.citizens_in_city[self.m].current_education, None)
     self.assertEqual(
         RC.citizens_in_city[self.s].current_profession.proficiency, 0.52)
Exemple #6
0
 def test_work_engine_for_specific_degree(self):
     school = PrimarySchool.objects.create(
         city=self.city,
         city_field=Field.objects.latest("id"),
         if_under_construction=False,
     )
     self.assertEqual(school.employee.count(), 0)
     self.assertEqual(Profession.objects.all().count(), 0)
     self.assertEqual(self.s.workplace_object, None)
     self.assertEqual(self.f.workplace_object, None)
     self.assertEqual(self.m.workplace_object, None)
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         len(RC.list_of_workplaces[school].all_people_in_building), 0)
     self.assertEqual(
         RC.list_of_workplaces[school].college_vacancies,
         school.college_employee_needed,
     )
     CitizenWorkEngine(RC, self.city).human_resources_allocation()
     self.save_all_ob_from(RC.citizens_in_city)
     self.s = Citizen.objects.get(id=self.s.id)
     self.f = Citizen.objects.get(id=self.f.id)
     self.m = Citizen.objects.get(id=self.m.id)
     self.assertEqual(self.s.workplace_object, school)
     self.assertEqual(school.employee.count(), 1)
     self.assertEqual(school.employee.last(), self.s)
     self.assertEqual(Profession.objects.all().count(), 3)
     self.assertNotEqual(self.m.workplace_object, None)
     self.assertNotEqual(self.f.workplace_object, None)
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         len(RC.list_of_workplaces[school].all_people_in_building), 1)
     self.assertEqual(
         RC.list_of_workplaces[school].college_vacancies,
         school.college_employee_needed - 1,
     )