Ejemplo n.º 1
0
        [TestMethod()] // Test based on random probability - random failures
        public void TestGaussianFloat()
        {
            float dev     = (float)1.0;
            float epsilon = 0.01f;

            int ntry = 100000;

            float[] values = new float[ntry];
            for (int i = 0; i < ntry; i++)
            {
                values[i] = RandomNumbersTool.GaussianFloat(dev);
            }

            // no get the sd of the values
            float mean = 0.0f;

            for (int i = 0; i < ntry; i++)
            {
                mean += values[i];
            }
            mean = mean / ntry;

            float sd = 0.0f;

            for (int i = 0; i < ntry; i++)
            {
                sd += (values[i] - mean) * (values[i] - mean);
            }
            sd = (float)Math.Sqrt(sd / (ntry - 1));
            Assert.IsTrue(sd >= (dev - epsilon) && sd <= (dev + epsilon), "Estimated SD does not match to 2 decimal places");
        }
Ejemplo n.º 2
0
        public void TestRandomDouble()
        {
            double random = RandomNumbersTool.RandomDouble();

            Assert.IsTrue(random >= 0.0);
            Assert.IsTrue(random <= 1.0);
        }
Ejemplo n.º 3
0
        public void TestRandomLong()
        {
            long random = RandomNumbersTool.RandomLong();

            Assert.IsTrue(random >= 0L);
            Assert.IsTrue(random <= 1L);
        }
Ejemplo n.º 4
0
        [TestMethod()] // Test based on random probability - random failures
        public void TestGaussianDouble()
        {
            double dev     = 2.0;
            double epsilon = 0.01;
            int    ntry    = 100000;

            double[] values = new double[ntry];
            for (int i = 0; i < ntry; i++)
            {
                values[i] = RandomNumbersTool.GaussianDouble(dev);
            }

            // no get the sd of the values
            double mean = 0;

            for (int i = 0; i < ntry; i++)
            {
                mean += values[i];
            }
            mean = mean / ntry;

            double sd = 0;

            for (int i = 0; i < ntry; i++)
            {
                sd += (values[i] - mean) * (values[i] - mean);
            }
            sd = Math.Sqrt(sd / (ntry - 1));
            Assert.IsTrue(sd >= (dev - epsilon) && sd <= (dev + epsilon), "Estimated SD does not match to 2 decimal places");
        }
Ejemplo n.º 5
0
        public void TestRandomFloat()
        {
            float random = RandomNumbersTool.RandomFloat();

            Assert.IsTrue(random >= 0.0);
            Assert.IsTrue(random <= 1.0);
        }
Ejemplo n.º 6
0
        public void TestRandomLong_long_long()
        {
            long lower_limit = 2L;
            long upper_limit = 4L;
            long random      = RandomNumbersTool.RandomLong(lower_limit, upper_limit);

            Assert.IsTrue(random >= lower_limit);
            Assert.IsTrue(random <= upper_limit);
        }
Ejemplo n.º 7
0
        public void TestRandomFloat_float_float()
        {
            float lower_limit = (float)2.0;
            float upper_limit = (float)4.0;
            float random      = RandomNumbersTool.RandomFloat(lower_limit, upper_limit);

            Assert.IsTrue(random >= lower_limit);
            Assert.IsTrue(random <= upper_limit);
        }
Ejemplo n.º 8
0
        public void TestRandomDouble_double_double()
        {
            double lower_limit = 2.0;
            double upper_limit = 4.0;
            double random      = RandomNumbersTool.RandomDouble(lower_limit, upper_limit);

            Assert.IsTrue(random >= lower_limit);
            Assert.IsTrue(random <= upper_limit);
        }
Ejemplo n.º 9
0
        [TestMethod()] // Test based on random probability - random failures
        public void TestFlipCoin()
        {
            int    ntry   = 1000000;
            double p      = 0.5;
            int    ntrue  = 0;
            int    nfalse = 0;

            for (int i = 0; i < ntry; i++)
            {
                if (RandomNumbersTool.FlipCoin(p))
                {
                    ntrue += 1;
                }
                else
                {
                    nfalse += 1;
                }
            }
            Assert.AreEqual(0.5, (double)ntrue / ntry, 0.01);
            Assert.AreEqual(0.5, (double)nfalse / ntry, 0.01);
        }
Ejemplo n.º 10
0
        [TestMethod()] // Test based on random probability - random failures
        public void TestExponentialDouble()
        {
            double mean    = 1.0f;
            double epsilon = 0.01f;
            int    ntry    = 100000;

            double[] values = new double[ntry];

            for (int i = 0; i < ntry; i++)
            {
                values[i] = RandomNumbersTool.ExponentialDouble(mean);
            }

            // no get the mean of the values
            double m = 0.0f;

            for (int i = 0; i < ntry; i++)
            {
                m += values[i];
            }
            m = m / ntry;

            Assert.IsTrue(m >= (mean - epsilon) && m <= (mean + epsilon), "Estimated mean does not match to 2 decimal places " + m);
        }
Ejemplo n.º 11
0
        public void TestRandomBoolean()
        {
            bool random = RandomNumbersTool.RandomBoolean();

            Assert.IsTrue(random || !random);
        }
Ejemplo n.º 12
0
        public void TestRandomInt()
        {
            int random = RandomNumbersTool.RandomInt();

            Assert.IsTrue(random == 0 || random == 1);
        }
Ejemplo n.º 13
0
        public void TestRandomInt_int_int()
        {
            int random = RandomNumbersTool.RandomInt(0, 5);

            Assert.IsTrue(random == 0 || random == 1 || random == 2 || random == 3 || random == 4 || random == 5);
        }