Commit 959c10c4 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Jérome Perrin

Triangular added to RandomNumberGenerator. Test added for this

parent 185e642f
......@@ -45,7 +45,7 @@ class RandomNumberGenerator(object):
unknownDistribution=True
for key in distribution.keys():
if key in ['Fixed', 'Normal','Exp','Gamma','Logistic','Erlang',
'Geometric','Lognormal','Weibull','Cauchy']:
'Geometric','Lognormal','Weibull','Cauchy', 'Triangular']:
unknownDistribution=False
break
if unknownDistribution:
......@@ -60,7 +60,7 @@ class RandomNumberGenerator(object):
# pop irrelevant keys
for key in distribution.keys():
if key not in ['Fixed', 'Normal','Exp','Gamma','Logistic','Erlang',
'Geometric','Lognormal','Weibull','Cauchy']:
'Geometric','Lognormal','Weibull','Cauchy', 'Triangular']:
distribution.pop(key, None)
self.distribution=distribution
self.distributionType = distribution.keys()[0]
......@@ -138,6 +138,8 @@ class RandomNumberGenerator(object):
return number
else:
continue
elif(self.distributionType=="Triangular"): #if the distribution is Triangular
return G.numpyRnd.random.triangular(left=self.min, right=self.max, mode=self.mean)
else:
raise ValueError("Unknown distribution %r used in %s %s" %
(self.distributionType, self.obj.__class__, self.obj.id))
......
......@@ -56,6 +56,19 @@ class RandomNumberGeneratorTestCase(TestCase):
self.assertTrue(number >= 0)
self.assertTrue(number <= 3)
def testTriangular(self):
rng = RandomNumberGenerator(obj,
distribution={'Triangular':
{
'min':1,
'max':3,
'mean':2}
})
for i in range(10):
number = rng.generateNumber()
self.assertTrue(number >= 1)
self.assertTrue(number <= 3)
def testNormalWrongParameter(self):
rng = RandomNumberGenerator(obj,
distribution={'Normal':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment