public void IntervalTest()
        {
            var target = new UniformDiscreteDistribution(-10, 10);

            for (int k = -15; k < 15; k++)
            {
                double expected = target.ProbabilityMassFunction(k);

                double a = target.DistributionFunction(k);
                double b = target.DistributionFunction(k - 1);
                double c = a - b;

                Assert.AreEqual(expected, c, 1e-15);
                Assert.AreEqual(c, target.DistributionFunction(k - 1, k), 1e-15);
            }
        }
        public void ConstructorTest()
        {
            // Create an uniform (discrete) distribution in [2, 6]
            var dist = new UniformDiscreteDistribution(a: 2, b: 6);

            // Common measures
            double mean   = dist.Mean;     // 4.0
            double median = dist.Median;   // 4.0
            double var    = dist.Variance; // 1.3333333333333333

            // Cumulative distribution functions
            double cdf  = dist.DistributionFunction(k: 2);              // 0.2
            double ccdf = dist.ComplementaryDistributionFunction(k: 2); // 0.8

            // Probability mass functions
            double pmf1 = dist.ProbabilityMassFunction(k: 4);    // 0.2
            double pmf2 = dist.ProbabilityMassFunction(k: 5);    // 0.2
            double pmf3 = dist.ProbabilityMassFunction(k: 6);    // 0.2
            double lpmf = dist.LogProbabilityMassFunction(k: 2); // -1.6094379124341003

            // Quantile function
            int icdf1 = dist.InverseDistributionFunction(p: 0.17); // 2
            int icdf2 = dist.InverseDistributionFunction(p: 0.46); // 4
            int icdf3 = dist.InverseDistributionFunction(p: 0.87); // 6

            // Hazard (failure rate) functions
            double hf  = dist.HazardFunction(x: 4);           // 0.5
            double chf = dist.CumulativeHazardFunction(x: 4); // 0.916290731874155

            // String representation
            string str = dist.ToString(CultureInfo.InvariantCulture); // "U(x; a = 2, b = 6)"

            Assert.AreEqual(4.0, mean);
            Assert.AreEqual(4.0, median);
            Assert.AreEqual(1.3333333333333333, var);
            Assert.AreEqual(0.916290731874155, chf, 1e-10);
            Assert.AreEqual(0.2, cdf);
            Assert.AreEqual(0.2, pmf1);
            Assert.AreEqual(0.2, pmf2);
            Assert.AreEqual(0.2, pmf3);
            Assert.AreEqual(-1.6094379124341003, lpmf);
            Assert.AreEqual(0.5, hf);
            Assert.AreEqual(0.8, ccdf);
            Assert.AreEqual(2, icdf1);
            Assert.AreEqual(4, icdf2);
            Assert.AreEqual(6, icdf3);
            Assert.AreEqual("U(x; a = 2, b = 6)", str);

            var range1 = dist.GetRange(0.95);
            var range2 = dist.GetRange(0.99);
            var range3 = dist.GetRange(0.01);

            Assert.AreEqual(2, range1.Min);
            Assert.AreEqual(6, range1.Max);
            Assert.AreEqual(2.0, range2.Min);
            Assert.AreEqual(6, range2.Max);
            Assert.AreEqual(2.0, range3.Min);
            Assert.AreEqual(6, range3.Max);
        }