Example #1
0
 def test_chance_to_married_failed_scenario(self):
     self.user.profile.chance_to_marriage_percent = 0.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(
         RootClass(self.city, User.objects.latest("id")).list_of_buildings[
             StandardLevelResidentialZone.objects.latest(
                 "id")].people_in_charge,
         1,
     )
     sa = SocialAction(self.city, self.user.profile,
                       RootClass(self.city, User.objects.latest("id")))
     sa.match_marriages()
     sa.update_age()
     self.assertEqual(self.user.profile.chance_to_marriage_percent, 0.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(m.resident_object,
                      StandardLevelResidentialZone.objects.latest("id"))
     self.assertEqual(f.resident_object, None)
     self.assertEqual(
         RootClass(self.city, User.objects.latest("id")).list_of_buildings[
             StandardLevelResidentialZone.objects.latest(
                 "id")].people_in_charge,
         1,
     )
Example #2
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,
     )
Example #3
0
 def test_random_choice_home_scenario_failed(self):
     self.r1 = StandardLevelResidentialZone.objects.latest("id")
     self.r1.max_population = 0
     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,
     )
     sa = SocialAction(self.city, self.user.profile,
                       RootClass(self.city, User.objects.latest("id")))
     self.assertEqual(self.f.resident_object, None)
     self.assertEqual(self.m.resident_object, None)
     self.assertEqual(
         list(
             StandardLevelResidentialZone.objects.latest(
                 "id").resident.all()), [])
     self.assertEqual(
         RootClass(self.city, User.objects.latest("id")).list_of_buildings[
             StandardLevelResidentialZone.objects.latest(
                 "id")].people_in_charge,
         0,
     )
     sa.find_home()
     self.assertEqual(
         RootClass(self.city, User.objects.latest("id")).list_of_buildings[
             StandardLevelResidentialZone.objects.latest(
                 "id")].people_in_charge,
         0,
     )
     sa.update_age()
     self.assertEqual(
         RootClass(self.city, User.objects.latest("id")).list_of_buildings[
             StandardLevelResidentialZone.objects.latest(
                 "id")].people_in_charge,
         0,
     )
     self.m = Citizen.objects.get(id=self.m.id)
     self.f = Citizen.objects.get(id=self.f.id)
     self.assertEqual(
         list(
             StandardLevelResidentialZone.objects.latest(
                 "id").resident.all()), [])
     self.assertEqual(self.f.resident_object, None)
     self.assertEqual(self.m.resident_object, None)
Example #4
0
 def test_gradudate_school_pass(self):
     self.f.school_object = self.school
     e = Education.objects.create(
         cur_year_of_learning=7,
         max_year_of_learning=8,
         citizen=self.f,
         name=ELEMENTARY,
     )
     self.f.save()
     self.f = Citizen.objects.get(id=self.f.id)
     self.assertEqual(self.f.school_object, self.school)
     self.assertEqual(self.f.edu_title, "None")
     self.school.update_year_of_school_for_student(self.f, e)
     self.f.save()
     e.save()
     self.school.save()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
     self.f = Citizen.objects.get(id=self.f.id)
     e = Education.objects.get(id=e.id)
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(RC.citizens_in_city[self.f].current_education, None)
     self.assertEqual(e.cur_year_of_learning, 8)
     self.assertEqual(e.max_year_of_learning, 8)
     self.assertEqual(self.f.edu_title, ELEMENTARY)
     self.assertEqual(e.if_current, False)
Example #5
0
class TestRootClass(test.TestCase):
    fixtures = ["basic_fixture_resources_and_employees2.json"]

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

    def test_keys_in_dataset(self):
        for x in self.RC.datasets_for_turn_calculation():
            self.assertIn("allocated_resource", x.keys())
            self.assertIn("list_of_source", x.keys())
            self.assertIn("list_without_source", x.keys())

    def test_get_subclasses(self):
        self.assertEqual(
            self.RC.get_subclasses(abstract_class=PowerPlant,
                                   app_label="city_engine"),
            [WindPlant, RopePlant, CoalPlant],
        )
        self.assertEqual(
            self.RC.get_subclasses(abstract_class=Waterworks,
                                   app_label="city_engine"),
            [WaterTower],
        )
Example #6
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)
Example #7
0
 def setUp(self):
     self.city = City.objects.latest("id")
     self.user = User.objects.latest('id')
     self.m = Market.objects.create(profile=self.user.profile)
     self.fire_station = FireStation.objects.create(
         city=self.city, city_field=Field.objects.latest('id'))
     TestHelper(self.city, User.objects.latest("id")).populate_city()
     self.rc = RootClass(self.city, User.objects.latest("id"))
     self.last_citizen = Citizen.objects.latest('id')
     self.fire_strategy = FireStrategy(self.rc)
     self.last_windplant = WindPlant.objects.latest('id')
Example #8
0
 def test_get_quality_of_education_with_phd_employees_only(self):
     rc = RootClass(self.city, User.objects.latest("id"))
     for b in rc.list_of_buildings:
         b.elementary_employee_needed = 0
         b.phd_employee_needed = 5
         b.save()
     TestHelper(self.city, User.objects.latest("id")).populate_city()
     rc = RootClass(self.city, User.objects.latest("id"))
     r = rc.list_of_buildings[self.s]
     self.assertEqual(r.people_in_charge, 25)
     self.assertEqual(r._get_quality_of_education(), 1)
    def test_energy_allocation_with_default_settings(self):
        rc = RootClass(self.city, self.user)
        self.assertEqual(
            len(rc.datasets_for_turn_calculation()[0]["list_without_source"]),
            5)
        self.assertEqual(
            len(rc.datasets_for_turn_calculation()[0]["list_of_source"]), 2)
        ResourceAllocation(self.city, rc).run()
        test_buildings = list(rc.list_of_buildings.values())
        self.assertEqual(test_buildings[3].energy,
                         test_buildings[3].energy_required)
        self.assertEqual(test_buildings[4].energy,
                         test_buildings[4].energy_required)
        self.assertEqual(test_buildings[5].energy,
                         test_buildings[5].energy_required)
        self.assertEqual(test_buildings[6].energy,
                         test_buildings[6].energy_required)

        self.assertEqual(
            rc.datasets_for_turn_calculation()[0]["list_of_source"]
            [0].energy_allocated, 84)
        self.assertEqual(
            rc.datasets_for_turn_calculation()[0]["list_of_source"]
            [1].energy_allocated, 0)

        self.assertEqual(
            rc.datasets_for_turn_calculation()[0]["list_of_source"]
            [0]._get_total_production(), 200)
        self.assertEqual(
            rc.datasets_for_turn_calculation()[0]["list_of_source"]
            [1]._get_total_production(), 200)
Example #10
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)
Example #11
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)
Example #12
0
 def test_buy_with_not_many_money(self):
     mass_on_market = Mass.objects.create(
         size=10, quality=20, market=self.market, price=1.5
     )
     self.fc.cash = 5
     self.fc.save()
     materials = []
     rc = RootClass(city=self.city, user=self.user)
     self.assertEqual(mass_on_market.size, 10)
     self.assertEqual(mass_on_market.quality, 20)
     self.assertEqual(materials, [])
     self.assertEqual(self.fc.cash, 5)
     self.assertEqual(Mass.objects.all().count(), 1)
     rc.companies[self.fc].buy_components(materials)
     rc.market.save_all()
     self.fc.refresh_from_db()
     self.assertEqual(Mass.objects.all().count(), 2)
     self.assertEqual(self.fc.cash, 0.50)
     mass_on_market = Mass.objects.get(id=mass_on_market.id)
     self.assertEqual(mass_on_market.size, 7)
     self.assertEqual(mass_on_market.quality, 20)
     self.assertNotEqual(materials, [])
     self.assertNotEqual(mass_on_market, materials[-1])
     self.assertEqual(materials[-1].size, 3)
     self.assertEqual(materials[-1].quality, 20)
Example #13
0
 def test_buy_mass_with_rest(self):
     mass_on_market = Mass.objects.create(
         size=20, quality=20, market=self.market, price=1.5
     )
     materials = []
     rc = RootClass(city=self.city, user=self.user)
     self.assertEqual(mass_on_market.size, 20)
     self.assertEqual(mass_on_market.quality, 20)
     self.assertEqual(materials, [])
     self.assertEqual(self.fc.cash, 10)
     self.assertEqual(Mass.objects.all().count(), 1)
     rc.companies[self.fc].buy_components(materials)
     rc.market.save_all()
     rc.list_of_workplaces[self.fc].save_all()
     self.fc.refresh_from_db()
     self.assertEqual(Mass.objects.all().count(), 2)
     self.assertEqual(self.fc.cash, 1)
     mass_on_market = Mass.objects.get(id=mass_on_market.id)
     self.assertEqual(mass_on_market.size, 14)
     self.assertEqual(mass_on_market.quality, 20)
     self.assertNotEqual(materials, [])
     for mass in materials:
         self.assertNotEqual(mass_on_market, mass)
         self.assertEqual(mass.size, 6)
         self.assertEqual(mass.quality, 20)
Example #14
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)
Example #15
0
 def test_simulate_fire_in_city(self):
     self.assertEqual(
         len([
             b for b in self.rc.list_of_buildings.values() if b.is_in_fire
         ]), 0)
     self.assertEqual(len(self.rc.list_of_buildings), 7)
     self.assertEqual(Citizen.objects.count(),
                      len(self.rc.citizens_in_city))
     self.assertEqual(Citizen.objects.count(), 40)
     for x in range(3):
         random.choice([
             b for b in self.rc.list_of_buildings.values()
             if not b.is_in_fire and not isinstance(b, TempResidential)
         ]).is_in_fire = True
     with mock.patch('random.random', get_06):
         self.fire_strategy.simulate_fire_in_the_city()
     self.assertEqual(
         len([
             b for b in self.rc.list_of_buildings.values() if b.is_in_fire
         ]), 0)
     self.assertEqual(len(self.rc.list_of_buildings), 4)
     self.assertEqual(Citizen.objects.count(),
                      len(self.rc.citizens_in_city))
     self.assertEqual(Citizen.objects.count(), 40)
     self.assertEqual(
         len(
             RootClass(self.city,
                       User.objects.latest("id")).list_of_buildings),
         len(self.rc.list_of_buildings))
Example #16
0
def turn_calculations(request):
    profile = Profile.objects.get(user_id=request.user.id)
    city = City.objects.get(player=profile)
    data = RootClass(city, request.user, is_turn_calculation=True)
    TurnCalculation(city, data, profile).run()
    # return render(request, 'city_calculation_view.html')
    return HttpResponseRedirect("/main")
Example #17
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)
Example #18
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)
Example #19
0
 def test_conduct_rehabilitation(self):
     self._put_citizens_to_jail(num_of_citizen=3)
     self.rc = RootClass(self.city, User.objects.latest("id"))
     self.temp_prison.conduct_rehabilitation()
     for c in self.temp_prison.prisoners:
         temp_citizen = self.rc.citizens_in_city[c]
         self.assertLess(temp_citizen.current_profession.proficiency, 25)
Example #20
0
 def test_cattle_resoucre_production_with_existing_one(self):
     self.assertEqual(Milk.objects.all().count(), 0)
     c = Cattle.objects.create(farm=self.cf, size=20)
     Milk.objects.create(size=20, quality=81, market=self.market, price=8.24)
     rc = RootClass(city=self.city, user=self.user)
     self.assertEqual(len(rc.market.resources[Milk].instances), 1)
     rc.list_of_workplaces[self.cf].wage_payment(self.city)
     c.resource_production(
         1,
         rc,
         rc.list_of_workplaces[self.cf].workers_costs,
         rc.list_of_workplaces[self.cf]._get_productivity(),
     )
     for x in rc.market.resources[Milk].instances:
         x.save()
     self.assertEqual(len(rc.market.resources[Milk].instances), 1)
     self.assertEqual(Milk.objects.all().count(), 1)
     m = Milk.objects.latest("id")
     self.assertEqual(m.size, 53)
     self.assertEqual(m.quality, 81)
     self.assertEqual(float(m.price), 0.38)
     rc_m = rc.market.resources[Milk].instances[-1]
     self.assertEqual(rc_m.size, 53)
     self.assertEqual(rc_m.quality, 81)
     self.assertEqual(float(round(rc_m.price, 2)), 0.38)
Example #21
0
 def test_family_data_container_two_family(self):
     sr = StandardLevelResidentialZone.objects.latest("id")
     family_p = Family.objects.create(city=self.city)
     family_m = Family.objects.create(city=self.city)
     p = Citizen.objects.create(
         city=self.city,
         age=28,
         month_of_birth=6,
         cash=100,
         health=5,
         name="0",
         surname="1",
         sex=FEMALE,
         education=PHD,
         resident_object=sr,
         family=family_p,
     )
     m = Citizen.objects.create(
         city=self.city,
         age=28,
         month_of_birth=6,
         cash=100,
         health=5,
         name="0",
         surname="2",
         sex=MALE,
         education=ELEMENTARY,
         resident_object=sr,
         family=family_m,
     )
     rc = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(len(rc.families), 2)
     self.assertEqual(rc.families[family_p].members, [p])
     self.assertEqual(rc.families[family_m].members, [m])
Example #22
0
 def test_failed_scenario_male(self):
     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,
         resident_object=self.r1,
     )
     self.assertEqual(self.f.resident_object, None)
     self.assertEqual(self.m.resident_object, self.r1)
     self.assertEqual(self.r1.max_population, 1)
     sa = SocialAction(self.city, self.user.profile,
                       RootClass(self.city, User.objects.latest("id")))
     self.assertEqual(sa.find_place_to_live(self.f, self.m), None)
Example #23
0
 def test_random_choice_scenario(self):
     self.f = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnonKA",
         surname="FeSurname",
         sex=FEMALE,
         resident_object=self.r1,
     )
     self.m = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnON",
         surname="MaSurname",
         sex=MALE,
         resident_object=self.r1,
     )
     sa = SocialAction(self.city, self.user.profile,
                       RootClass(self.city, User.objects.latest("id")))
     self.assertEqual(sa.find_place_to_live(self.m, self.f), self.r1)
Example #24
0
 def test_salary_expectation_calculation_without_residential_object(self):
     s = Citizen.objects.create(
         city=self.city,
         age=18,
         month_of_birth=2,
         cash=100,
         health=5,
         name="0",
         surname="1",
         sex=FEMALE,
         education=COLLEGE,
     )
     Education.objects.create(citizen=s,
                              name=ELEMENTARY,
                              effectiveness=1,
                              if_current=False)
     Education.objects.create(citizen=s,
                              name=COLLEGE,
                              effectiveness=1,
                              if_current=False)
     Profession.objects.create(citizen=s,
                               proficiency=0.5,
                               name="Nauczyciel")
     rc = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(rc.citizens_in_city[s].salary_expectation, 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.ra = ResourceAllocation(city=self.city, data=self.rc)
Example #26
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)
Example #27
0
 def setUp(self):
     self.city = City.objects.get(id=1)
     self.r1 = StandardLevelResidentialZone.objects.latest("id")
     self.user = User.objects.latest('id')
     he_family = Family.objects.create(surname="01", city=self.city)
     she_family = Family.objects.create(surname="02", city=self.city)
     Market.objects.create(profile=self.user.profile)
     self.f = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnonKA",
         surname="01",
         sex=FEMALE,
         resident_object=self.r1,
         family=she_family,
     )
     self.m = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnON",
         surname="02",
         sex=MALE,
         family=he_family,
     )
     self.user.profile.chance_to_marriage_percent = 1.00
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
     self.sa.match_marriages()
Example #28
0
 def setUp(self):
     self.city = City.objects.get(id=1)
     self.user = User.objects.latest('id')
     self.she_family = Family.objects.create(city=self.city, surname="00")
     self.he_family = Family.objects.create(city=self.city, surname="01")
     Market.objects.create(profile=self.user.profile)
     self.f = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="She",
         surname="00",
         sex=FEMALE,
         family=self.she_family,
     )
     self.m = Citizen.objects.create(
         city=self.city,
         age=21,
         month_of_birth=2,
         cash=100,
         health=5,
         name="He",
         surname="01",
         sex=MALE,
         family=self.he_family,
         resident_object=StandardLevelResidentialZone.objects.latest("id"),
     )
     self.RC = RootClass(self.city, User.objects.latest("id"))
Example #29
0
 def test_cattle_resoure_production_with_existing_diffrent(self):
     self.assertEqual(Milk.objects.all().count(), 0)
     c = Cattle.objects.create(farm=self.cf, size=20, price=8.24)
     m1 = Milk.objects.create(size=20, quality=20, market=self.market)
     rc = RootClass(city=self.city, user=self.user)
     self.assertEqual(len(rc.market.resources[Milk].instances), 1)
     self.assertEqual(Milk.objects.all().count(), 1)
     rc.list_of_workplaces[self.cf].wage_payment(self.city)
     c.resource_production(
         1,
         rc,
         rc.list_of_workplaces[self.cf].workers_costs,
         rc.list_of_workplaces[self.cf]._get_productivity(),
     )
     self.assertEqual(len(rc.market.resources[Milk].instances), 2)
     self.assertEqual(Milk.objects.all().count(), 2)
     m = Milk.objects.latest("id")
     self.assertEqual(m.size, 33)
     self.assertEqual(m.quality, 81)
     self.assertEqual(float(m.price), 24.48)
     self.assertEqual(m1.size, 20)
     self.assertEqual(m1.quality, 20)
     self.assertEqual(float(m.price), 24.48)
     rc_m = rc.market.resources[Milk].instances[-1]
     self.assertEqual(rc_m.size, 33)
     self.assertEqual(rc_m.quality, 81)
     self.assertEqual(float(rc_m.price), 24.48)
Example #30
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)