Exemple #1
0
 def setUp(self):
     coeffs = StubCoeffs(adult_effort=ADULT_EFFORT,
                         primary_school_effort=PRIMARY_SCHOOL_EFFORT,
                         secondary_school_effort=SECONDARY_SCHOOL_EFFORT,
                         secondary_school_cost=1,
                         recovery_rate0=1, recovery_rate1=1,
                         recovery_rate2=1,
                         recovery_rate3=1,
                         market_items=['stove', 'bednet',
                                       'high_yield_seeds', 'propane',
                                       'fertilizer'],
                         market_sell_prices=[10, 5, 1, 10, 5],
                         market_purchase_prices=[10, 5, 1, 10, 5],
                         death_rate=1,
                         mortality0=1, mortality1=1, birth_rate=1,
                         mortality2=1,
                         fish_k=2500, effort_coeff=0.042,
                         avg_fishing_yield=900,
                         maize_productivity_exponent=0.9,
                         avg_maize_yield=1000,
                         cotton_productivity_exponent=0.9,
                         avg_cotton_yield=1000,
                         avg_wood_yield=80, wood_k=7500,
                         avg_water_yield=250,
                         avg_small_business_yield=50, wood_fuel_coeff=3.5,
                         avg_family_size=4,
                         propane_fuel_coeff=5.0,
                         fish_growth_rate=1.2, forest_growth_rate=1.01,
                         energy_req=18, subsistence=500,
                         maize_cal_coeff=25, fish_cal_coeff=26.5,
                         w_subsistence=30,
                         fuelwood_health_loss=2.0,
                         effort_too_high_health_loss=1.0,
                         death_threshold_1=0.0,
                         death_threshold_2=10.0,
                         wood_price=10.0, cotton_export_units=100,
                         maize_export_units=100,
                         maize_price=10,
                         cotton_price=100, savings_rate=0.2,
                         health_increment=4.0,
                         min_precipitation=100,
                         precipitation_infection_modifier=0,
                         max_precipitation=400,
                         avg_precipitation=200,
                         soil_depletion=0.5,
                         school_meals_calories=5.0,
                         effort_fuel_wood=1,
                         transport_cost_road=10.0,
                         transport_cost_no_road=100.0,
                         doctor_visit_cost=30.0,
                         enable_NGO_offers=True,
                         road_subsidy_year=5,
                         other_subsidy_year=10,
                         drought_threshold=100.0,
                         no_droughts_before=2,
                         starting_year=2007,
                         enable_epidemic=True,
                         no_epidemics_before=10,
                         enable_free_bednets=True,
                         free_bednet_year=30,
                         productivity_effort_coeff=0.2,
                         fishing_effort_coeff=0.042,
                         wood_effort_coeff=0.042,
                         food_cost=20.0,
                         dragnet_coeff=2.0,
                         fish_stock_warn_threshold=0.33,
                         wood_stock_warn_threshold=0.33,
                         available_improvements=['a', 'b', 'road'],
                         improvement_prices=[1, 2, 10],
                         small_business_depreciation_rate=0.2,
                         small_business_productivity_effect=1,
                         small_business_road_effect=1,
                         small_business_electricity_effect=1,
                         small_business_drought_effect=1,
                         small_business_epidemic_effect=1,
                         small_business_diminishing_return=1,
                         microfinance_base_interest=0.02,
                         microfinance_min_balance=100.0,
                         microfinance_repay_period=8,
                         microfinance_drought_effect=1,
                         microfinance_epidemic_effect=1,
                         health_nutrition_coeff=1.0,
                         health_clinic_coeff=1.0,
                         health_power_coeff=1.0,
                         health_sickness_coeff=1.0,
                         )
     kodjo = Person(name="Kodjo", gender="Male", age=15, health=100,
                    education=12, pregnant=False, sick="",
                    schooling_state="adult", coeffs=coeffs, tc=StubTC())
     state = StubState(expenditure=0, income=0, tons_to_market=0,
                       initial_population=0, cash=500,
                       population=2, total_effort=0, fertilizer=False,
                       people=[kodjo], health_t1=['Kodjo|100'],
                       health_t2=['Kodjo|100'], health_t3=['Kodjo|100'],
                       names=['Kodjo'], genders=['Male'], ages=[16],
                       health=[100], education=[12], pregnant=[False],
                       sick=[""], schooling_state=['adult'],
                       efforts=[12, 12], year=2007,
                       doctor=[], sell_items=['', "stove|1"],
                       purchase_items=['', 'bednet|1'],
                       try_for_child=False, enroll=[],
                       improvements=[], village_infected_pop=0,
                       clinic=1.0, electricity=1.0, village_population=500,
                       fish_stock=5000, effort_fishing=2,
                       effort_farming=12, effort_fuel_wood=4,
                       effort_water=9,
                       boat=False, fishing_limit=0, fertilizer_t1=True,
                       season=True, fertilizer_last_turn=True,
                       soil_health=1, irrigation=False,
                       crops=['Maize', 'Maize', 'Maize', 'Maize'],
                       wood_stock=1000.0, wood_limit=0,
                       effort_small_business=0,
                       improved_stove=False, food_to_buy=0,
                       meals=False, water_pump=False, stove=False,
                       epidemic=False,
                       cost_to_market=0, tax_rate=0.0, fund=0,
                       owned_items=['stove'],
                       road=False, sanitation=False,
                       amount_water=50, user_messages=[], precipitation=0.0,
                       family_needs=1.0, amount_calories=0.0, wood_fuel=0.0,
                       wood_k=500, high_yield_seeds=False,
                       avg_productivity=1.0,
                       drought=False,
                       amount_propane=0,
                       propane_fuel=0,
                       subsistence_met=True,
                       calorie_allocation=[500, 500],
                       deaths=0,
                       died=[],
                       died_reasons=[],
                       dragnet=False,
                       bednet_ages=[2],
                       u_points=0,
                       small_business_capital=0,
                       small_business_investment=0,
                       microfinance_balance=0.0,
                       microfinance_borrow=0.0,
                       microfinance_current_interest_rate=0.0,
                       microfinance_interest_rate=0.0,
                       microfinance_amount_due=0.0,
                       microfinance_amount_paid=0.0,
                       microfinance_max_borrow=0.0,
                       )
     tc = StubTC()
     self.turn = Turn(state, coeffs, tc)
Exemple #2
0
class TestTurn(unittest.TestCase):
    def setUp(self):
        coeffs = StubCoeffs(adult_effort=ADULT_EFFORT,
                            primary_school_effort=PRIMARY_SCHOOL_EFFORT,
                            secondary_school_effort=SECONDARY_SCHOOL_EFFORT,
                            secondary_school_cost=1,
                            recovery_rate0=1, recovery_rate1=1,
                            recovery_rate2=1,
                            recovery_rate3=1,
                            market_items=['stove', 'bednet',
                                          'high_yield_seeds', 'propane',
                                          'fertilizer'],
                            market_sell_prices=[10, 5, 1, 10, 5],
                            market_purchase_prices=[10, 5, 1, 10, 5],
                            death_rate=1,
                            mortality0=1, mortality1=1, birth_rate=1,
                            mortality2=1,
                            fish_k=2500, effort_coeff=0.042,
                            avg_fishing_yield=900,
                            maize_productivity_exponent=0.9,
                            avg_maize_yield=1000,
                            cotton_productivity_exponent=0.9,
                            avg_cotton_yield=1000,
                            avg_wood_yield=80, wood_k=7500,
                            avg_water_yield=250,
                            avg_small_business_yield=50, wood_fuel_coeff=3.5,
                            avg_family_size=4,
                            propane_fuel_coeff=5.0,
                            fish_growth_rate=1.2, forest_growth_rate=1.01,
                            energy_req=18, subsistence=500,
                            maize_cal_coeff=25, fish_cal_coeff=26.5,
                            w_subsistence=30,
                            fuelwood_health_loss=2.0,
                            effort_too_high_health_loss=1.0,
                            death_threshold_1=0.0,
                            death_threshold_2=10.0,
                            wood_price=10.0, cotton_export_units=100,
                            maize_export_units=100,
                            maize_price=10,
                            cotton_price=100, savings_rate=0.2,
                            health_increment=4.0,
                            min_precipitation=100,
                            precipitation_infection_modifier=0,
                            max_precipitation=400,
                            avg_precipitation=200,
                            soil_depletion=0.5,
                            school_meals_calories=5.0,
                            effort_fuel_wood=1,
                            transport_cost_road=10.0,
                            transport_cost_no_road=100.0,
                            doctor_visit_cost=30.0,
                            enable_NGO_offers=True,
                            road_subsidy_year=5,
                            other_subsidy_year=10,
                            drought_threshold=100.0,
                            no_droughts_before=2,
                            starting_year=2007,
                            enable_epidemic=True,
                            no_epidemics_before=10,
                            enable_free_bednets=True,
                            free_bednet_year=30,
                            productivity_effort_coeff=0.2,
                            fishing_effort_coeff=0.042,
                            wood_effort_coeff=0.042,
                            food_cost=20.0,
                            dragnet_coeff=2.0,
                            fish_stock_warn_threshold=0.33,
                            wood_stock_warn_threshold=0.33,
                            available_improvements=['a', 'b', 'road'],
                            improvement_prices=[1, 2, 10],
                            small_business_depreciation_rate=0.2,
                            small_business_productivity_effect=1,
                            small_business_road_effect=1,
                            small_business_electricity_effect=1,
                            small_business_drought_effect=1,
                            small_business_epidemic_effect=1,
                            small_business_diminishing_return=1,
                            microfinance_base_interest=0.02,
                            microfinance_min_balance=100.0,
                            microfinance_repay_period=8,
                            microfinance_drought_effect=1,
                            microfinance_epidemic_effect=1,
                            health_nutrition_coeff=1.0,
                            health_clinic_coeff=1.0,
                            health_power_coeff=1.0,
                            health_sickness_coeff=1.0,
                            )
        kodjo = Person(name="Kodjo", gender="Male", age=15, health=100,
                       education=12, pregnant=False, sick="",
                       schooling_state="adult", coeffs=coeffs, tc=StubTC())
        state = StubState(expenditure=0, income=0, tons_to_market=0,
                          initial_population=0, cash=500,
                          population=2, total_effort=0, fertilizer=False,
                          people=[kodjo], health_t1=['Kodjo|100'],
                          health_t2=['Kodjo|100'], health_t3=['Kodjo|100'],
                          names=['Kodjo'], genders=['Male'], ages=[16],
                          health=[100], education=[12], pregnant=[False],
                          sick=[""], schooling_state=['adult'],
                          efforts=[12, 12], year=2007,
                          doctor=[], sell_items=['', "stove|1"],
                          purchase_items=['', 'bednet|1'],
                          try_for_child=False, enroll=[],
                          improvements=[], village_infected_pop=0,
                          clinic=1.0, electricity=1.0, village_population=500,
                          fish_stock=5000, effort_fishing=2,
                          effort_farming=12, effort_fuel_wood=4,
                          effort_water=9,
                          boat=False, fishing_limit=0, fertilizer_t1=True,
                          season=True, fertilizer_last_turn=True,
                          soil_health=1, irrigation=False,
                          crops=['Maize', 'Maize', 'Maize', 'Maize'],
                          wood_stock=1000.0, wood_limit=0,
                          effort_small_business=0,
                          improved_stove=False, food_to_buy=0,
                          meals=False, water_pump=False, stove=False,
                          epidemic=False,
                          cost_to_market=0, tax_rate=0.0, fund=0,
                          owned_items=['stove'],
                          road=False, sanitation=False,
                          amount_water=50, user_messages=[], precipitation=0.0,
                          family_needs=1.0, amount_calories=0.0, wood_fuel=0.0,
                          wood_k=500, high_yield_seeds=False,
                          avg_productivity=1.0,
                          drought=False,
                          amount_propane=0,
                          propane_fuel=0,
                          subsistence_met=True,
                          calorie_allocation=[500, 500],
                          deaths=0,
                          died=[],
                          died_reasons=[],
                          dragnet=False,
                          bednet_ages=[2],
                          u_points=0,
                          small_business_capital=0,
                          small_business_investment=0,
                          microfinance_balance=0.0,
                          microfinance_borrow=0.0,
                          microfinance_current_interest_rate=0.0,
                          microfinance_interest_rate=0.0,
                          microfinance_amount_due=0.0,
                          microfinance_amount_paid=0.0,
                          microfinance_max_borrow=0.0,
                          )
        tc = StubTC()
        self.turn = Turn(state, coeffs, tc)

    def tearDown(self):
        self.turn = None

    def test_calc_maximum_effort(self):
        assert self.turn.calc_maximum_effort() == 2

    def test_transport_cost_per_ton(self):
        self.turn.state.road = True
        self.turn.transport_cost_per_ton()
        self.turn.state.road = False
        self.turn.transport_cost_per_ton()

    def test_reset(self):
        self.turn.state.expenditure = 300
        self.turn.state.income = 20
        self.turn.reset()
        assert self.turn.state.expenditure == 0
        assert self.turn.state.income == 0

    def test_is_game_over(self):
        self.turn.state.population = 10
        self.turn.state.cash = 100
        assert self.turn.is_game_over() is False
        self.turn.state.population = 0
        assert self.turn.is_game_over() is True
        self.turn.state.population = 10
        self.turn.state.cash = -200
        assert self.turn.is_game_over() is True

    def test_is_everyone_dead(self):
        self.turn.state.population = 10
        assert self.turn.is_everyone_dead() is False
        self.turn.state.population = 0
        assert self.turn.is_everyone_dead() is True

    def test_is_debt_too_high(self):
        self.turn.state.cash = 100
        assert self.turn.is_debt_too_high() is False
        self.turn.state.cash = -101
        assert self.turn.is_debt_too_high() is True

    def test_sell_items(self):
        pass

    def test_purchase_items(self):
        self.turn.purchase_items()
        self.turn.state.purchase_items.append('high_yield_seeds|1')
        self.turn.state.purchase_items.append('propane|1')
        self.turn.state.purchase_items.append('fertilizer|1')
        self.turn.purchase_items()

    def test_check_purchase_price(self):
        pass

    def test_check_sell_price(self):
        pass

    def test_update_points(self):
        pass

    def test_calc_family_avg_health(self):
        self.turn.state.people = []
        assert self.turn.calc_family_avg_health() == 0

    def test_calc_school_effort(self):
        pass

    def test_calc_school_cost(self):
        pass

    def test_family_improvements_count(self):
        pass

    def test_village_improvements_count(self):
        pass

    def test_update_population_count(self):
        pass

    def test_doctor(self):
        self.turn.state.doctor = ['kodjo']
        self.turn.doctor()

    def test_pregnancy(self):
        self.turn.state.try_for_child = True
        self.turn.pregnancy()

    def test_education(self):
        pass

    def test_children(self):
        self.turn.children()
        fatou = Person(name="Fatou", gender="Female", age=24, health=100,
                       education=12,
                       pregnant=True, sick="", schooling_state="adult",
                       coeffs=self.turn.coeffs, tc=self.turn.tc)
        self.turn.coeffs.child_names = ['bart']
        self.turn.coeffs.child_genders = ['Male']
        self.turn.state.births = 0
        self.turn.state.people.append(fatou)
        self.turn.state.try_for_child = False
        self.turn.children()
        assert fatou.pregnant is False

    def test_update_finances(self):
        pass

    def test_determine_cash(self):
        pass

    def test_increment_time(self):
        pass

    def test_age_people(self):
        pass

    def test_check_drought(self):
        self.turn.state.drought = False
        self.turn.state.year = 2007
        self.turn.coeffs.starting_year = 2007
        self.turn.state.irrigation = False
        self.turn.coeffs.chance_of_drought = .5
        self.turn.check_drought()
        assert self.turn.state.drought is True
        self.turn.state.year = 2010
        self.turn.state.irrigation = True
        self.turn.check_drought()
        assert self.turn.state.drought is False

    def test_rand_n(self):
        r = rand_n(self.turn.tc, 5)
        assert r == 0

    def test_check_epidemic(self):
        pass

    def test_check_final_health(self):
        self.turn.check_final_health()
        self.turn.state.people[0].health = 0
        self.turn.check_final_health()

    def test_check_sick(self):
        pass

    def test_check_stove(self):
        pass

    def test_update_yield(self):
        pass

    def test_t_boat(self):
        pass

    def test_t_fert(self):
        pass

    def test_t_irr(self):
        self.turn.state.irrigation = True
        self.turn.coeffs.irrigation_coeff = 5
        assert self.turn.t_irr() == self.turn.coeffs.irrigation_coeff

    def test_t_drought(self):
        pass

    def test_update_soil_health(self):
        self.turn.update_soil_health()
        assert self.turn.state.soil_health == 1.0
        self.turn.state.fertilizer = False
        self.turn.state.fertilizer_t1 = False
        self.turn.state.fertilizer_t2 = False
        self.turn.update_soil_health()
        assert self.turn.state.soil_health < 1.0

    def test_calc_amount_fish(self):
        pass

    def test_update_amount_fish(self):
        pass

    def test_wood_coeff(self):
        assert self.turn.calc_wood_coeff() == 1000.0 / 7500.0
        self.turn.state.wood_stock = 10000
        assert self.turn.calc_wood_coeff() == 1

    def test_update_wood_coeff(self):
        self.turn.update_wood_coeff()

    def test_calc_fish_coeff(self):
        print(self.turn.calc_fish_coeff())
        print(self.turn.state.fish_stock)
        print(self.turn.coeffs.fish_k)
        assert self.turn.calc_fish_coeff() == 1
        self.turn.state.fish_stock = -10
        assert self.turn.calc_fish_coeff() == 0
        self.turn.state.fish_stock = 200.0
        print(self.turn.calc_fish_coeff())
        assert self.turn.calc_fish_coeff() == 200.0 / 2500.0

    def test_update_fish_coeff(self):
        pass

    def test_percent_maize(self):
        assert self.turn.percent_maize() == 1
        self.turn.state.crops = ["Maize", "Maize", "Maize", "Cotton"]
        assert self.turn.percent_maize() == .75
        self.turn.state.crops = ["Cotton", "Cotton", "Cotton", "Cotton"]
        assert self.turn.percent_maize() == 0

    def test_percent_cotton(self):
        assert self.turn.percent_cotton() == 0
        self.turn.state.crops = ["Maize", "Maize", "Maize", "Cotton"]
        assert self.turn.percent_cotton() == .25
        self.turn.state.crops = ["Cotton", "Cotton", "Cotton", "Cotton"]
        assert self.turn.percent_cotton() == 1

    def test_calc_amount_cotton(self):
        assert self.turn.calc_amount_cotton() == 0
        self.turn.state.crops = ["Cotton", "Cotton", "Cotton", "Cotton"]
        amt = self.turn.calc_amount_cotton()
        assert amt > 2088.0 and amt < 2089.0

    def test_update_amount_cotton(self):
        pass

    def test_update_amount_maize(self):
        pass

    def test_calc_amount_wood(self):
        pass

    def test_update_amount_wood(self):
        self.turn.update_amount_wood()
        assert self.turn.state.amount_wood >= 0
        self.turn.state.wood_limit = 10
        self.turn.state.wood_stock = 10000
        self.turn.update_amount_wood()
        assert self.turn.state.amount_wood == self.turn.state.wood_limit

    def test_calc_amount_water(self):
        pass

    def test_update_amount_water(self):
        pass

    def test_calc_small_business_income(self):
        pass

    def test_update_small_business_income(self):
        pass

    def test_convert_calories(self):
        pass

    def test_convert_fuel(self):
        pass

    def test_is_enough_wood(self):
        pass

    def test_calc_energy_req(self):
        pass

    def test_calc_amount_calories(self):
        pass

    def test_school_meal_calories(self):
        assert self.turn.school_meal_calories() == 0
        self.turn.state.meals = True
        self.turn.state.people[0].schooling_state = "enrolled in primary"
        assert self.turn.school_meal_calories() > 0

    def test_amount_calories(self):
        pass

    def test_is_subsistence_met(self):
        pass

    def test_is_water_subsistence_met(self):
        pass

    def test_calc_family_needs(self):
        pass

    def test_calc_family_water_needs(self):
        pass

    def test_update_family_water_needs(self):
        pass

    def test_calories_above_subsistence(self):
        pass

    def test_excess_wood(self):
        pass

    def test_starve(self):
        self.turn.starve()

    def test_dehydrate(self):
        pass

    def test_num_infants(self):
        pass

    def test_total_productivity(self):
        pass

    def test_num_non_infants(self):
        pass

    def test_calc_avg_productivity(self):
        pass

    def test_update_avg_productivity(self):
        pass

    def test_determine_income(self):
        pass

    def test_hire_wagon(self):
        pass

    def test_sell_food(self):
        self.turn.state.food_to_sell = 10
        self.turn.sell_food()

    def test_sell_wood(self):
        pass

    def test_sell_cotton(self):
        self.turn.state.amount_cotton = 100
        (price, tons_to_market) = self.turn.sell_cotton()
        print(price)
        print(tons_to_market)
        print(self.turn.coeffs.cotton_price)
        assert price == 10
        assert tons_to_market == 0.1
        self.turn.coeffs.cotton_price = 200
        (price, tons_to_market) = self.turn.sell_cotton()
        assert price == 20
        assert tons_to_market == 0.1

    def test_food_cost(self):
        assert self.turn.food_cost() == 20
        self.turn.state.meals = True
        assert self.turn.food_cost() == 20 * 1.2