def test_calc_cb_no_change_pass(self):
        """Test _calc_cost_benefit without present value against reference value"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        cost_ben = CostBenefit()
        cost_ben._calc_impact_measures(hazard, entity.exposures, entity.measures,
            entity.impact_funcs, when='future', risk_func=risk_aai_agg, save_imp=True)

        cost_ben.present_year = 2018
        cost_ben.future_year = 2040
        cost_ben._calc_cost_benefit(entity.disc_rates)

        self.assertEqual(cost_ben.imp_meas_present, dict())
        self.assertEqual(len(cost_ben.imp_meas_future), 5)
        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)

        self.assertEqual(cost_ben.cost_ben_ratio['Mangroves'], 0.04230714690616641)
        self.assertEqual(cost_ben.cost_ben_ratio['Beach nourishment'], 0.06998836431681373)
        self.assertEqual(cost_ben.cost_ben_ratio['Seawall'], 0.2679741183248266)
        self.assertEqual(cost_ben.cost_ben_ratio['Building code'], 0.30286828677985717)

        self.assertEqual(cost_ben.benefit['Mangroves'], 3.100583368954022e+10)
        self.assertEqual(cost_ben.benefit['Beach nourishment'], 2.468981832719974e+10)
        self.assertEqual(cost_ben.benefit['Seawall'], 3.3132973770502796e+10)
        self.assertEqual(cost_ben.benefit['Building code'], 3.0376240767284798e+10)

        self.assertEqual(cost_ben.tot_climate_risk, 1.2150496306913972e+11)
    def test_calc_cb_change_pass(self):
        """Test _calc_cost_benefit with present value against reference value"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        cost_ben = CostBenefit()
        cost_ben._calc_impact_measures(hazard, entity.exposures, entity.measures,
            entity.impact_funcs, when='present', risk_func=risk_aai_agg, save_imp=False)

        ent_future = Entity()
        ent_future.read_excel(ENT_DEMO_FUTURE)
        ent_future.check()

        haz_future = copy.deepcopy(hazard)
        haz_future.intensity.data += 25

        cost_ben._calc_impact_measures(haz_future, ent_future.exposures, ent_future.measures,
            ent_future.impact_funcs, when='future', risk_func=risk_aai_agg, save_imp=False)

        cost_ben.present_year = 2018
        cost_ben.future_year = 2040
        cost_ben._calc_cost_benefit(entity.disc_rates, imp_time_depen=1)

        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)
        self.assertEqual(cost_ben.tot_climate_risk, 5.768659152882021e+11)

        self.assertEqual(cost_ben.imp_meas_present['no measure']['risk'], 6.51220115756442e+09)
        self.assertEqual(cost_ben.imp_meas_present['Mangroves']['risk'], 4.850407096284983e+09)
        self.assertEqual(cost_ben.imp_meas_present['Beach nourishment']['risk'], 5.188921355413834e+09)
        self.assertEqual(cost_ben.imp_meas_present['Seawall']['risk'], 4.736400526119911e+09)
        self.assertEqual(cost_ben.imp_meas_present['Building code']['risk'], 4.884150868173321e+09)

        self.assertEqual(cost_ben.imp_meas_future['no measure']['risk'], 5.9506659786664024e+10)
        self.assertEqual(cost_ben.imp_meas_future['Mangroves']['risk'], 4.826231151473135e+10)
        self.assertEqual(cost_ben.imp_meas_future['Beach nourishment']['risk'], 5.0647250923231674e+10)
        self.assertEqual(cost_ben.imp_meas_future['Seawall']['risk'], 21089567135.7345)
        self.assertEqual(cost_ben.imp_meas_future['Building code']['risk'], 4.462999483999791e+10)

        self.assertAlmostEqual(cost_ben.benefit['Mangroves'], 113345027690.81276)
        self.assertAlmostEqual(cost_ben.benefit['Beach nourishment'], 89444869971.53653)
        self.assertAlmostEqual(cost_ben.benefit['Seawall'], 347977469896.1333)
        self.assertAlmostEqual(cost_ben.benefit['Building code'], 144216478822.05154)

        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Mangroves'], 0.011573232523528404)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Beach nourishment'], 0.01931916274851638)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Seawall'], 0.025515385913577368)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Building code'], 0.06379298728650741)

        self.assertEqual(cost_ben.tot_climate_risk, 576865915288.2021)