Exemple #1
0
        public virtual void Test(double tolerance)
        {
            double p1 = _dist.CDF(_a[2]);

            Assert.AreEqual(_a[3], p1, Math.Abs(_a[3] * tolerance), "Unexpected result of CDF");

            double d1 = _dist.PDF(_a[2]);

            Assert.AreEqual(_a[4], d1, Math.Abs(_a[4] * tolerance), "Unexpected result of PDF");

            int len  = 1000000;
            int suml = 0;

            for (int i = 0; i < len; i++)
            {
                if (_dist.NextDouble() <= _a[2])
                {
                    suml++;
                }
            }
            double p1_tested  = suml / (double)len;
            double confidence = BinomialDistribution.CDF(suml, _a[3], len);

            Assert.Greater(confidence, 0.01, string.Format("Unexpected result of distribution of generated values : outside (left) the 1% confidence limits, expected p={0}, actual p={1}, confidence={2}", _a[3], p1_tested, confidence));
            Assert.Less(confidence, 0.99, string.Format("Unexpected result of distribution of generated values : outside (right) the 1% confidence limits, expected p={0}, actual p={1}, confidence={2}", _a[3], p1_tested, confidence));
        }