--- /dev/null
+import unittest
+
+import probability.Distribution
+
+
+class DistributionTest(unittest.TestCase):
+
+ def testSampledValuesWithinComponentBounds(self):
+ """
+ Create a distribution from the sum of two uniforms, and make
+ sure that the values sampled from the sum lie in the interval
+ (min1+min2, max1+max2).
+ """
+ min1 = 0.1515
+ max1 = 22
+ min2 = 14
+ max2 = 100
+
+ ud1 = probability.Distribution.Uniform(min1, max1)
+ ud2 = probability.Distribution.Uniform(min2, max2)
+ distro = ud1 + ud2
+
+ for x in range(0,1000):
+ s = distro.sample()
+ self.assertTrue(s >= (min1+min2))
+ self.assertTrue(s <= (max1+max2))
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(DistributionTest))
+ return suite
--- /dev/null
+import unittest
+
+import probability.Distribution
+
+
+class UniformDistributionTest(unittest.TestCase):
+
+ def testBoundsOrdered(self):
+ """
+ The constructor for Uniform() takes two numbers, 'a' and 'b'
+ which provide the upper and lower bounds for the
+ distribution. The constructor should place the lesser of the
+ two in self.min, and the greater in self.max.
+ """
+ ud = probability.Distribution.Uniform(0,0)
+ self.assertTrue(ud.min == 0)
+ self.assertTrue(ud.max == 0)
+
+ ud = probability.Distribution.Uniform(0,10)
+ self.assertTrue(ud.min == 0)
+ self.assertTrue(ud.max == 10)
+
+ ud = probability.Distribution.Uniform(0.558, 0.23)
+ self.assertTrue(ud.min == 0.23)
+ self.assertTrue(ud.max == 0.558)
+
+
+ def testSampledValuesWithinBounds(self):
+ """
+ Sample the distribution a few times, and make sure the values
+ we get are within the (min,max) we supplied.
+ """
+ ud = probability.Distribution.Uniform(0.558, 0.23)
+ for x in range(0,1000):
+ s = ud.sample()
+ self.assertTrue(s >= ud.min)
+ self.assertTrue(s <= ud.max)
+
+
+ def testKnownCdfValues(self):
+ """
+ The CDF of a uniform distribution is easy to calculate.
+ Check a few known values.
+ """
+ ud = probability.Distribution.Uniform(0, 1)
+ delta = 0.1
+ for i in range(0,11):
+ x = i*delta
+ self.assertEqual(x, ud.cdf(x))
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(UniformDistributionTest))
+ return suite