def test_cb_one_meas_pres_pass(self): """Test _cost_ben_one with different future""" meas_name = 'Mangroves' meas_val = dict() meas_val['cost'] = (1.3117683608515418e+09, 1) meas_val['risk'] = 4.826231151473135e+10 meas_val['efc'] = None meas_val['risk_transf'] = 0 cb = CostBenefit() cb.present_year = 2018 cb.future_year = 2040 cb.imp_meas_present['no measure'] = dict() cb.imp_meas_present['no measure']['risk'] = 6.51220115756442e+09 cb.imp_meas_present['Mangroves'] = dict() cb.imp_meas_present['Mangroves']['risk'] = 4.850407096284983e+09 cb.imp_meas_present['Mangroves']['risk_transf'] = 0 cb.imp_meas_future['no measure'] = dict() cb.imp_meas_future['no measure']['risk'] = 5.9506659786664024e+10 disc_rates = DiscRates() disc_rates.years = np.arange(2016, 2051) disc_rates.rates = np.ones(disc_rates.years.size) * 0.02 time_dep = cb._time_dependency_array(1) cb._cost_ben_one(meas_name, meas_val, disc_rates, time_dep) self.assertAlmostEqual(cb.benefit[meas_name], 113345027690.81276, places=3) self.assertAlmostEqual(cb.cost_ben_ratio[meas_name], 0.011573232523528404)
def test_cb_one_meas_fut_pass(self): """Test _cost_ben_one with same future""" meas_name = 'Mangroves' meas_val = dict() meas_val['cost'] = (1.3117683608515418e+09, 1) meas_val['risk'] = 4.850407096284983e+09 meas_val['efc'] = None meas_val['risk_transf'] = 0 cb = CostBenefit() cb.present_year = 2018 cb.future_year = 2040 cb.imp_meas_future['no measure'] = dict() cb.imp_meas_future['no measure']['risk'] = 6.51220115756442e+09 disc_rates = DiscRates() disc_rates.years = np.arange(2000, 2051) disc_rates.rates = np.ones(disc_rates.years.size) * 0.02 time_dep = cb._time_dependency_array() cb._cost_ben_one(meas_name, meas_val, disc_rates, time_dep) self.assertAlmostEqual(cb.benefit[meas_name], 3.100583368954022e+10, places=3) self.assertAlmostEqual(cb.cost_ben_ratio[meas_name], 0.04230714690616641)
def test_npv_unaverted_no_pres_pass(self): """ Test _npv_unaverted_impact """ cb = CostBenefit() cb.present_year = 2018 cb.future_year = 2030 risk_future = 1000 disc_rates = DiscRates() disc_rates.years = np.arange(cb.present_year, cb.future_year+1) disc_rates.rates = np.ones(disc_rates.years.size)*0.025 time_dep = np.linspace(0, 1, disc_rates.years.size) res = cb._npv_unaverted_impact(risk_future, disc_rates, time_dep, risk_present=None) self.assertEqual(res, disc_rates.net_present_value(cb.present_year, \ cb.future_year, time_dep * risk_future))