예제 #1
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)
예제 #2
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)
예제 #3
0
파일: tests.py 프로젝트: mstrumeck/cou
 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()
예제 #4
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)
예제 #5
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)
예제 #6
0
 def test_random_choice_home_scenario_pass(self):
     self.r1 = StandardLevelResidentialZone.objects.latest("id")
     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.f.resident_object, None)
     self.assertEqual(self.m.resident_object, None)
     self.assertEqual(
         list(
             StandardLevelResidentialZone.objects.latest(
                 "id").resident.all()), [])
     self.assertEqual(
         RC.list_of_buildings[StandardLevelResidentialZone.objects.latest(
             "id")].people_in_charge,
         0,
     )
     sa.find_home()
     self.save_all_ob_from(RC.list_of_buildings)
     self.save_all_ob_from(RC.citizens_in_city)
     self.m = Citizen.objects.get(id=self.m.id)
     self.f = Citizen.objects.get(id=self.f.id)
     self.assertEqual(
         RootClass(self.city, User.objects.latest("id")).list_of_buildings[
             StandardLevelResidentialZone.objects.latest(
                 "id")].people_in_charge,
         2,
     )
     self.assertNotEqual(
         list(
             StandardLevelResidentialZone.objects.latest(
                 "id").resident.all()), [])
     self.assertEqual(self.f.resident_object, self.r1)
     self.assertEqual(self.m.resident_object, self.r1)
예제 #7
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.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
     self.citizen_instance = self.RC.citizens_in_city[self.citizen]
예제 #8
0
 def setUp(self):
     self.city = City.objects.get(id=1)
     self.user = User.objects.latest("id")
     PoliceStation.objects.create(city=self.city, city_field=Field.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.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
     self.citizen_instance = self.RC.citizens_in_city[self.citizen]
     self.police_strategy = PoliceStrategy(self.RC)
예제 #9
0
 def test_update_year_of_student_pass(self):
     Education.objects.create(
         cur_year_of_learning=0,
         max_year_of_learning=8,
         citizen=self.f,
         name=ELEMENTARY,
     )
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
     self.assertEqual(
         self.RC.citizens_in_city[
             self.f].current_education.cur_year_of_learning, 0)
     self.school.update_year_of_school_for_student(
         self.f, self.RC.citizens_in_city[self.f].current_education)
     self.sa.update_age()
     self.RC.citizens_in_city[self.f].current_education.save()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         self.RC.citizens_in_city[
             self.f].current_education.cur_year_of_learning, 1)
예제 #10
0
 def setUp(self):
     self.city = City.objects.get(id=1)
     self.user = User.objects.latest('id')
     self.r1 = StandardLevelResidentialZone.objects.latest("id")
     Market.objects.create(profile=self.user.profile)
     self.f = Citizen.objects.create(
         city=self.city,
         age=8,
         month_of_birth=2,
         cash=100,
         health=5,
         name="AnonKA",
         surname="FeSurname",
         sex=FEMALE,
         education="None",
         resident_object=self.r1,
     )
     self.school = PrimarySchool.objects.create(
         city=self.city, city_field=Field.objects.latest("id"))
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
예제 #11
0
파일: tests.py 프로젝트: mstrumeck/cou
 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,
     )
예제 #12
0
 def test_gain_knowledge_during_education_process_single_run(self):
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         RC.citizens_in_city[self.m].current_education.effectiveness, 0.0)
     self.assertEqual(
         RC.citizens_in_city[self.s].current_profession.proficiency, 0.5)
     SocialAction(city=self.city, profile=self.user.profile,
                  city_data=RC).run()
     self.assertEqual(
         RC.citizens_in_city[self.s].current_profession.proficiency, 0.52)
     self.assertEqual(
         RC.citizens_in_city[self.m].current_education.effectiveness,
         0.005408)
예제 #13
0
파일: tests.py 프로젝트: mstrumeck/cou
 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,
     )
예제 #14
0
 def test_gain_knowledge_during_education_process_multi_run(self):
     RC = RootClass(self.city, User.objects.latest("id"))
     self.assertEqual(
         RC.citizens_in_city[self.m].current_education.effectiveness, 0.0)
     self.assertEqual(
         RC.citizens_in_city[self.s].current_profession.proficiency, 0.5)
     for x in range(6):
         SocialAction(city=self.city,
                      profile=self.user.profile,
                      city_data=RC).run()
     self.assertEqual(
         RC.citizens_in_city[self.s].current_profession.proficiency,
         0.5660526315789475,
     )
     self.assertEqual(
         RC.citizens_in_city[self.m].current_education.effectiveness,
         0.03429536842105263,
     )
예제 #15
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()
예제 #16
0
 def test_get_criminals(self):
     self.assertEqual(list(self.sa.police_strategy._get_active_criminals()), [])
     self.citizen_instance.change_citizen_into_criminal()
     self.RC = RootClass(self.city, User.objects.latest("id"))
     self.sa = SocialAction(self.city, self.user.profile, self.RC)
     self.assertNotEqual(self.sa.police_strategy._get_active_criminals(), [])
예제 #17
0
class TestEducation(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()
        PrimarySchool.objects.all().delete()

    def setUp(self):
        self.city = City.objects.get(id=1)
        self.user = User.objects.latest('id')
        self.r1 = StandardLevelResidentialZone.objects.latest("id")
        Market.objects.create(profile=self.user.profile)
        self.f = Citizen.objects.create(
            city=self.city,
            age=8,
            month_of_birth=2,
            cash=100,
            health=5,
            name="AnonKA",
            surname="FeSurname",
            sex=FEMALE,
            education="None",
            resident_object=self.r1,
        )
        self.school = PrimarySchool.objects.create(
            city=self.city, city_field=Field.objects.latest("id"))
        self.RC = RootClass(self.city, User.objects.latest("id"))
        self.sa = SocialAction(self.city, self.user.profile, self.RC)

    def test_assign_student_to_school_pass_without_education(self):
        self.assertEqual(self.f.school_object, None)
        self.assertEqual(self.f.education_set.all().count(), 0)
        RC = RootClass(self.city, User.objects.latest("id"))
        self.school.check_for_student_in_city(self.f,
                                              RC.citizens_in_city[self.f])
        self.f.save()
        self.sa.update_age()
        e = Education.objects.get(citizen=self.f)
        self.f = Citizen.objects.get(id=self.f.id)
        self.assertEqual(self.f.school_object, self.school)
        self.assertEqual(e.max_year_of_learning,
                         self.school.years_of_education)
        self.assertEqual(self.f.education_set.all().count(), 1)
        self.assertEqual(e.if_current, True)

    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,
        )

    def test_update_year_of_student_pass(self):
        Education.objects.create(
            cur_year_of_learning=0,
            max_year_of_learning=8,
            citizen=self.f,
            name=ELEMENTARY,
        )
        self.RC = RootClass(self.city, User.objects.latest("id"))
        self.sa = SocialAction(self.city, self.user.profile, self.RC)
        self.assertEqual(
            self.RC.citizens_in_city[
                self.f].current_education.cur_year_of_learning, 0)
        self.school.update_year_of_school_for_student(
            self.f, self.RC.citizens_in_city[self.f].current_education)
        self.sa.update_age()
        self.RC.citizens_in_city[self.f].current_education.save()
        self.RC = RootClass(self.city, User.objects.latest("id"))
        self.assertEqual(
            self.RC.citizens_in_city[
                self.f].current_education.cur_year_of_learning, 1)

    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)
예제 #18
0
파일: tests.py 프로젝트: mstrumeck/cou
class BornChildTests(TestCase):
    fixtures = ["basic_fixture_resources_and_employees.json"]

    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()

    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)

    def test_born_child_success_scenario(self):
        self.user.profile.chance_to_born_baby_percent = 1.00
        self.sa.citizen_data.chance_to_born = (
            self.sa.citizen_data.chance_to_born_baby_calc())
        self.sa.born_child()
        self.assertEqual(Citizen.objects.filter(age=1).count(), 1)
        self.assertEqual(Citizen.objects.all().count(), 3)
        ch = Citizen.objects.latest("id")
        self.assertEqual(ch.father_id, self.m.id)
        self.assertEqual(ch.mother_id, self.f.id)

    def test_born_child_failed_scenario(self):
        self.user.profile.chance_to_born_baby_percent = 0.00
        self.sa.citizen_data.chance_to_born = (
            self.sa.citizen_data.chance_to_born_baby_calc())
        self.sa.born_child()
        self.assertEqual(Citizen.objects.filter(age=0).count(), 0)
        self.assertEqual(Citizen.objects.all().count(), 2)