Esempio n. 1
0
    def setUp(self):
        coeffs = StubCoeffs(pregnant_effort=PREGNANT_EFFORT,
                            adult_effort=ADULT_EFFORT,
                            child_1_effort=CHILD_1_EFFORT,
                            child_2_effort=CHILD_2_EFFORT,
                            child_3_effort=CHILD_3_EFFORT,
                            fuelwood_health_loss=10,
                            effort_too_high_health_loss=1,
                            disease_respiratory_health_factor=0.8,
                            disease_respiratory_youth_factor=0.2,
                            disease_waterborne_health_factor=0.8,
                            disease_waterborne_latrine_factor=0.2,
                            disease_waterborne_waterpump_factor=0.2,
                            disease_malaria_health_factor=0.2,
                            disease_malaria_bednet_factor=0.2,
                            disease_respiratory_propane_factor=1.5,
                            base_infection_rate=1,
                            precipitation_infection_modifier=0.2,
                            avg_precipitation=10,
                            bednet_infection_modifier=0.2,
                            disease_malaria_sir_factor=0.2,
                            chance_of_getting_the_flu=0,
                            )

        self.kodjo = Person(name="Kodjo", gender="Male", age=15, health=100,
                            education=12, pregnant=False, sick="",
                            schooling_state="adult", coeffs=coeffs,
                            tc=StubTC())
        self.kodjo.tc.override = 1
Esempio n. 2
0
class TestPerson(unittest.TestCase):
    def setUp(self):
        coeffs = StubCoeffs(pregnant_effort=PREGNANT_EFFORT,
                            adult_effort=ADULT_EFFORT,
                            child_1_effort=CHILD_1_EFFORT,
                            child_2_effort=CHILD_2_EFFORT,
                            child_3_effort=CHILD_3_EFFORT,
                            fuelwood_health_loss=10,
                            effort_too_high_health_loss=1,
                            disease_respiratory_health_factor=0.8,
                            disease_respiratory_youth_factor=0.2,
                            disease_waterborne_health_factor=0.8,
                            disease_waterborne_latrine_factor=0.2,
                            disease_waterborne_waterpump_factor=0.2,
                            disease_malaria_health_factor=0.2,
                            disease_malaria_bednet_factor=0.2,
                            disease_respiratory_propane_factor=1.5,
                            base_infection_rate=1,
                            precipitation_infection_modifier=0.2,
                            avg_precipitation=10,
                            bednet_infection_modifier=0.2,
                            disease_malaria_sir_factor=0.2,
                            chance_of_getting_the_flu=0,
                            )

        self.kodjo = Person(name="Kodjo", gender="Male", age=15, health=100,
                            education=12, pregnant=False, sick="",
                            schooling_state="adult", coeffs=coeffs,
                            tc=StubTC())
        self.kodjo.tc.override = 1

    def tearDown(self):
        self.kodjo = None

    def test_init(self):
        assert self.kodjo.name == "Kodjo"
        assert self.kodjo.age == 15
        assert not self.kodjo.sick

    def test_increment_decrement_health(self):
        self.kodjo.health = 100
        self.kodjo.decrement_health(50)
        assert self.kodjo.health == 50
        self.kodjo.increment_health(10)
        assert self.kodjo.health == 60
        self.kodjo.increment_health(50)
        assert self.kodjo.health == 100
        self.kodjo.decrement_health(0)
        assert self.kodjo.health == 100
        self.kodjo.decrement_health(200)
        assert self.kodjo.health == 0

        self.kodjo.health = 100

    def test_visit_doctor(self):
        self.kodjo.health = 50
        self.kodjo.sick = "pneumonia+malaria"

        self.kodjo.visit_doctor()
        assert not self.kodjo.sick
        assert self.kodjo.health == 75.0

        self.kodjo.health = 100
        self.kodjo.visit_doctor()
        assert not self.kodjo.sick
        assert self.kodjo.health == 100.0

    def test_starve(self):
        self.kodjo.health = 100
        self.kodjo.coeffs.subsistence = 500
        self.kodjo.starve(250)
        assert self.kodjo.health == 50.0
        self.kodjo.health = 100
        self.kodjo.starve(500)
        assert self.kodjo.health == 100.0

    def test_dehydrate(self):
        self.kodjo.health = 100
        family_water_needs = 100.0
        amount_water = 50.0
        population = 2.0
        self.kodjo.dehydrate(family_water_needs, amount_water, population)
        assert self.kodjo.health == 50.0
        self.kodjo.health = 100
        self.kodjo.dehydrate(family_water_needs, family_water_needs,
                             population)
        assert self.kodjo.health == 100.0
        self.kodjo.dehydrate(family_water_needs, family_water_needs, 0)

    def test_maximum_effort(self):

        assert self.kodjo.maximum_effort() == ADULT_EFFORT
        self.kodjo.pregnant = True
        assert self.kodjo.maximum_effort() == PREGNANT_EFFORT
        self.kodjo.pregnant = False
        self.kodjo.age = 1
        assert self.kodjo.maximum_effort() == CHILD_1_EFFORT
        self.kodjo.age = 5
        assert self.kodjo.maximum_effort() == CHILD_2_EFFORT
        self.kodjo.age = 10
        assert self.kodjo.maximum_effort() == CHILD_3_EFFORT
        self.kodjo.age = 15
        assert self.kodjo.maximum_effort() == ADULT_EFFORT

    def test_is_infant(self):
        assert self.kodjo.is_infant() is False
        self.kodjo.age = 5
        assert self.kodjo.is_infant() is False
        self.kodjo.age = 4
        assert self.kodjo.is_infant() is True
        self.kodjo.age = 15

    def test_productivity(self):
        self.kodjo.education = 24
        self.kodjo.health = 100
        assert self.kodjo.productivity() == 150
        # should drop proportionally to health
        self.kodjo.health = 50
        assert self.kodjo.productivity() == 75
        self.kodjo.health = 25
        assert self.kodjo.productivity() == 37.5
        # proportional to education
        self.kodjo.health = 100
        self.kodjo.education = 6
        assert self.kodjo.productivity() == 75
        # infants are not productive
        self.kodjo.age = 4
        assert self.kodjo.productivity() == 0
        # drops off with age over 50
        self.kodjo.age = 51
        self.kodjo.education = 24
        for (i, age) in enumerate(range(51, 75)):
            self.kodjo.age = age
            # convert to int since it eventually gets far enough out that
            # floating point conversions aren't reliable
            assert int(self.kodjo.productivity()) == int(.95 **
                                                         (i + 1) * 150.0)
        self.kodjo.age = 15

    def test_check_sick(self):
        state = StubState(epidemic=False,
                          stove=True,
                          improved_stove=False,
                          sanitation=True,
                          water_pump=True,
                          owned_items=[],
                          population=1,
                          village_infected_pop=0,
                          village_population=1000,
                          precipitation=10,
                          )
        self.kodjo.coeffs.resting_health_gain = 2
        self.kodjo.sick = ""
        self.kodjo.check_sick(state)
        assert not self.kodjo.sick, self.kodjo.sick
        self.kodjo.age = 4
        self.kodjo.check_sick(state)
        assert not self.kodjo.sick
        state.epidemic = True
        self.kodjo.coeffs.illness_chance_coeff = 0.0
        self.kodjo.check_sick(state)
        assert not self.kodjo.sick

        self.kodjo.health = 80.0
        self.kodjo.effort = 0
        self.kodjo.sick = ""
        self.kodjo.check_sick(state)
        assert not self.kodjo.sick

        self.kodjo.coeffs.illness_chance_coeff = 10000.0
        self.kodjo.health = 1.0
        self.kodjo.tc.override = 10
        self.kodjo.check_sick(state)
        assert self.kodjo.sick

    def test_update_schooling_state(self):
        self.kodjo.schooling_state = "adult"
        self.kodjo.update_schooling_state(False)
        assert self.kodjo.schooling_state == "adult"

    def test_update_education(self):
        self.kodjo.schooling_state = "adult"
        self.kodjo.education = 12
        self.kodjo.update_education()
        assert self.kodjo.education == 12
        self.kodjo.schooling_state = "under 5"
        self.kodjo.update_education()
        assert self.kodjo.education == 12
        self.kodjo.schooling_state = "enrolled in primary"
        self.kodjo.update_education()
        assert self.kodjo.education == 13

    def test_average_health_over_past_three_turns(self):
        assert self.kodjo.average_health_over_past_three_turns() == 100
        self.kodjo.health_t3 = 0.0
        assert self.kodjo.average_health_over_past_three_turns() == 200.0 / 3.0

    def test_make_pregnant(self):
        self.kodjo.make_pregnant()
        assert self.kodjo.pregnant is False
        self.kodjo.name = 'Fatou'
        self.kodjo.make_pregnant()
        assert self.kodjo.pregnant is False
        self.kodjo.age = 25
        self.kodjo.make_pregnant()
        assert self.kodjo.pregnant is True

    def test_is_dead(self):
        self.kodjo.coeffs.death_threshold_1 = 50
        self.kodjo.coeffs.death_threshold_2 = 60
        assert self.kodjo.is_dead() is False
        self.kodjo.health = 55
        self.kodjo.health_t1 = 5
        self.kodjo.health_t2 = 5
        assert self.kodjo.is_dead() is True