Ejemplo n.º 1
0
 def test_skips(self):
     data = {1: {'exchanges': [
         {'type': 'production'},
         {'uncertainty type': sa.LognormalUncertainty.id}
     ]}}
     # Doesn't raise KeyError for 'amount'
     data = uncertainify(data)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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")
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def test_skips(self):
     data = {
         1: {
             "exchanges": [
                 {"type": "production"},
                 {"uncertainty type": sa.LognormalUncertainty.id},
             ]
         }
     }
     # Doesn't raise KeyError for 'amount'
     data = uncertainify(data)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 def test_bounds_factor_none_ok(self):
     uncertainify({}, bounds_factor=None)
Ejemplo n.º 15
0
 def test_wrong_distribution(self):
     with self.assertRaises(AssertionError):
         uncertainify({}, sa.LognormalUncertainty)