def test_skips(self): data = {1: {'exchanges': [ {'type': 'production'}, {'uncertainty type': sa.LognormalUncertainty.id} ]}} # Doesn't raise KeyError for 'amount' data = uncertainify(data)
def test_skip_zero_amounts(self): data = {1: {"exchanges": [{"amount": 0.0}]}} data = uncertainify(data) new_dict = { "amount": 0.0, } self.assertEqual(data[1]["exchanges"][0], new_dict)
def test_factors_valid(self): with self.assertRaises(AssertionError): uncertainify({}, bounds_factor=-1) with self.assertRaises(TypeError): uncertainify({}, bounds_factor="foo") with self.assertRaises(AssertionError): uncertainify({}, sd_factor=-1) with self.assertRaises(TypeError): uncertainify({}, sd_factor="foo")
def test_skip_zero_amounts(self): data = {1: {'exchanges': [ {'amount': 0.} ]}} data = uncertainify(data) new_dict = { 'amount': 0., } self.assertEqual(data[1]['exchanges'][0], new_dict)
def test_uniform(self): data = {1: {"exchanges": [{"amount": 10.0}]}} data = uncertainify(data) new_dict = { "amount": 10.0, "minimum": 9.0, "maximum": 11.0, "uncertainty type": sa.UniformUncertainty.id, } self.assertEqual(data[1]["exchanges"][0], new_dict)
def test_bounds_flipped_negative_amount(self): data = {1: {"exchanges": [{"amount": -10.0}]}} data = uncertainify(data) new_dict = { "amount": -10.0, "minimum": -11.0, "maximum": -9.0, "uncertainty type": sa.UniformUncertainty.id, } self.assertEqual(data[1]["exchanges"][0], new_dict)
def test_normal_unbounded(self): data = {1: {"exchanges": [{"amount": 10.0}]}} data = uncertainify(data, sa.NormalUncertainty, bounds_factor=None) new_dict = { "amount": 10.0, "loc": 10.0, "scale": 1.0, "uncertainty type": sa.NormalUncertainty.id, } self.assertEqual(data[1]["exchanges"][0], new_dict)
def test_skips(self): data = { 1: { "exchanges": [ {"type": "production"}, {"uncertainty type": sa.LognormalUncertainty.id}, ] } } # Doesn't raise KeyError for 'amount' data = uncertainify(data)
def test_normal_bounded(self): data = {1: {"exchanges": [{"amount": 10.0}]}} data = uncertainify(data, sa.NormalUncertainty) new_dict = { "amount": 10.0, "loc": 10.0, "scale": 1.0, "minimum": 9.0, "maximum": 11.0, "uncertainty type": sa.NormalUncertainty.id, } self.assertEqual(data[1]["exchanges"][0], new_dict)
def test_uniform(self): data = {1: {'exchanges': [ {'amount': 10.} ]}} data = uncertainify(data) new_dict = { 'amount': 10., 'minimum': 9., 'maximum': 11., 'uncertainty type': sa.UniformUncertainty.id, } self.assertEqual(data[1]['exchanges'][0], new_dict)
def test_bounds_flipped_negative_amount(self): data = {1: {'exchanges': [ {'amount': -10.} ]}} data = uncertainify(data) new_dict = { 'amount': -10., 'minimum': -11., 'maximum': -9., 'uncertainty type': sa.UniformUncertainty.id, } self.assertEqual(data[1]['exchanges'][0], new_dict)
def test_normal_unbounded(self): data = {1: {'exchanges': [ {'amount': 10.} ]}} data = uncertainify(data, sa.NormalUncertainty, bounds_factor=None) new_dict = { 'amount': 10., 'loc': 10., 'scale': 1., 'uncertainty type': sa.NormalUncertainty.id, } self.assertEqual(data[1]['exchanges'][0], new_dict)
def test_normal_negative_amount(self): data = {1: {'exchanges': [ {'amount': -10.} ]}} data = uncertainify(data, sa.NormalUncertainty) new_dict = { 'amount': -10., 'loc': -10., 'scale': 1., 'minimum': -11., 'maximum': -9., 'uncertainty type': sa.NormalUncertainty.id, } self.assertEqual(data[1]['exchanges'][0], new_dict)
def test_bounds_factor_none_ok(self): uncertainify({}, bounds_factor=None)
def test_wrong_distribution(self): with self.assertRaises(AssertionError): uncertainify({}, sa.LognormalUncertainty)