def setUp(self, mock_check_input) -> None: self.mean: DataInput = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=2.0) self.variance: DataInput = DataInput( input_type=DataInputs.FLORIDA_STDDEV, value=2.0) self.test: LogNormalModel = LogNormalModel(mean=self.mean, variance=self.variance)
class DataInputTest(TestCase): @patch("components.data_input.DataInput.__init__") def setUp(self, mock_init) -> None: mock_init.return_value = None self.test = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=5.6) self.test.value = 5.6 self.test.input_type = DataInputs.FLORIDA_MEAN def tearDown(self) -> None: pass @patch("components.data_input.DataInput.check_float_input") def test___init__(self, mock_check_float_input): test: DataInput = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=5.6) self.assertEqual(5.6, test.value) self.assertEqual(DataInputs.FLORIDA_MEAN, test.input_type) mock_check_float_input.assert_called_once_with() def test_check_float_input(self): self.test.check_float_input() self.test.value = "test" with self.assertRaises(DataInputError) as context: self.test.check_float_input() self.assertEqual( "input value for DataInputs.FLORIDA_MEAN needs to be a float, not a <class 'str'>", str(context.exception))
def setUp(self) -> None: self.variance: DataInput = DataInput( input_type=DataInputs.FLORIDA_STDDEV, value=2.0) self.mean: DataInput = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=2.0) self.test: SimulationYear = SimulationYear(variance=self.variance, mean=self.mean, samples=5)
def test___init__(self, mock_check_float_input): test: DataInput = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=5.6) self.assertEqual(5.6, test.value) self.assertEqual(DataInputs.FLORIDA_MEAN, test.input_type) mock_check_float_input.assert_called_once_with()
def test_check_input(self): self.test.check_input() self.test.landfall_rate = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=2.0) with self.assertRaises(PoissonModelError) as context: self.test.check_input() self.assertEqual( "the self.landfall_rate needs to be a landfall rate not a DataInputs.FLORIDA_MEAN", str(context.exception) )
def simulation_years_factory(florida_mean: float, florida_stddev: float, gulf_mean: float, gulf_stddev: float, gulf_landfall: float, flordia_landfall: float, years: int = 1) -> Dict[str, float]: """ This factory takes the inputs from the command line and packages them in DataInput objects, passing them through to the SimulationYears objects to calculate the averages of the loss over a number of years for each location. :param florida_mean: (float) the mean economic loss of a land falling hurricane in Florida :param florida_stddev: (float) the variance of the economic loss of a land falling hurricane in Florida :param gulf_mean: (float) the mean economic loss of a land falling hurricane in the Gulf :param gulf_stddev: (float) the variance of the economic loss of a land falling hurricane in the Gulf :param gulf_landfall: (float) The annual rate of landfalling hurricanes in the Gulf states :param flordia_landfall: (float) The annual rate of landfalling hurricanes in Florida :param years: (int) number of years for the simulation :return: (Dict[str, float]) the average loss over the years for florida and gulf """ florida_mean: DataInput = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=florida_mean) florida_stddev: DataInput = DataInput(input_type=DataInputs.FLORIDA_STDDEV, value=florida_stddev) gulf_mean: DataInput = DataInput(input_type=DataInputs.GULF_MEAN, value=gulf_mean) gulf_stddev: DataInput = DataInput(input_type=DataInputs.GULF_STDDEV, value=gulf_stddev) flordia_landfall: DataInput = DataInput(input_type=DataInputs.FLORIDA_LANDFALL_RATE, value=flordia_landfall) gulf_landfall: DataInput = DataInput(input_type=DataInputs.GULF_LANDFALL_RATE, value=gulf_landfall) florida_year = SimulationYears(location=Locations.FLORIDA, variance=florida_stddev, mean=florida_mean, landfall_rate=flordia_landfall, years=years) gulf_year = SimulationYears(location=Locations.GULF, variance=gulf_stddev, mean=gulf_mean, landfall_rate=gulf_landfall, years=years) billion = 1000000000 return { "florida average": florida_year.average / billion, "gulf average": gulf_year.average / billion, "total average": ((florida_year.average + gulf_year.average) / 2) / billion }
def setUp(self, mock_init) -> None: mock_init.return_value = None self.test = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=5.6) self.test.value = 5.6 self.test.input_type = DataInputs.FLORIDA_MEAN
def setUp(self, mock__load_years) -> None: self.variance: DataInput = DataInput(input_type=DataInputs.FLORIDA_STDDEV, value=2.0) self.mean: DataInput = DataInput(input_type=DataInputs.FLORIDA_MEAN, value=2.0) self.landfall_rate: DataInput = DataInput(input_type=DataInputs.FLORIDA_LANDFALL_RATE, value=2.0) self.test: SimulationYears = SimulationYears(location=Locations.FLORIDA, variance=self.variance, mean=self.mean, landfall_rate=self.landfall_rate, years=2)
def setUp(self, mock_check_input) -> None: self.landfall_rate: DataInput = DataInput(input_type=DataInputs.FLORIDA_LANDFALL_RATE, value=2.0) self.test: PoissonModel = PoissonModel(landfall_rate=self.landfall_rate)