def test_exports(self): """Test outputs post calculation""" # Create model and calculate model = FairModel('Test', self.N_SAMPLES) model.bulk_import_data({ 'Loss Magnitude': { 'constant': 100 }, 'Loss Event Frequency': { 'low': 10, 'mode': 15, 'high': 20 } }) model.calculate_all() # Export results results = model.export_results() self.assertIsInstance(results, pd.DataFrame) self.assertTrue(len(results) == self.N_SAMPLES) # Export json and ensure parse-able json_data = model.to_json() self.assertIsInstance(json_data, str) _ = json.loads(json_data) # Export params params = model.export_params() self.assertIsInstance(params, dict) self.assertTrue(params)
def test_inputs(self): """Check the input methods (leave validation to FairDataInput)""" # Test basic input model = FairModel('Test', self.N_SAMPLES) model.input_data('Loss Magnitude', constant=100) # Test duplicate inputs passed model.input_data('Loss Magnitude', constant=10) # Test bulk_import_data model.bulk_import_data({ 'Loss Magnitude': { 'constant': 100 }, 'Loss Event Frequency': { 'low': 10, 'mode': 15, 'high': 20 } }) # Test import_multi_data model.input_multi_data( 'Secondary Loss', { 'Reputational': { 'Secondary Loss Event Frequency': { 'constant': 4000 }, 'Secondary Loss Event Magnitude': { 'low': 10, 'mode': 20, 'high': 100 }, }, 'Legal': { 'Secondary Loss Event Frequency': { 'constant': 2000 }, 'Secondary Loss Event Magnitude': { 'low': 10, 'mode': 20, 'high': 100 }, } }) # Test input_raw_data model.input_raw_data('Vulnerability', [1] * self.N_SAMPLES) self.assertRaises(FairException, model.input_raw_data, 'Vulnerability', [2] * self.N_SAMPLES) self.assertRaises(FairException, model.input_raw_data, 'Vulnerability', 'abc') model.calculate_all()