Beispiel #1
0
        public void GetChanceTest2()
        {
            int oneChanceAmount  = 0;
            int halfChanceAmount = 0;

            for (int attempt = 1; attempt <= Attempts; attempt++)
            {
                if (RandomUtil.GetChance(0.0f))
                {
                    Assert.Fail("GetChance(0) is true");
                }

                if (RandomUtil.GetChance(-0.23f))
                {
                    Assert.Fail("GetChance(-23) is true.");
                }

                if (!RandomUtil.GetChance(1.0f))
                {
                    Assert.Fail("GetChance(100) is false.");
                }

                if (!RandomUtil.GetChance(1.23f))
                {
                    Assert.Fail("GetChance(123) is false.");
                }

                if (RandomUtil.GetChance(0.01f))
                {
                    oneChanceAmount++;
                }

                if (RandomUtil.GetChance(0.5f))
                {
                    halfChanceAmount++;
                }
            }

            Assert.IsTrue(Mathf.Abs(oneChanceAmount - Attempts / 100) < Attempts / 100, string.Format("oneChanceAmount:{0}", oneChanceAmount));
            Assert.IsTrue(Mathf.Abs(halfChanceAmount - Attempts / 2) < Attempts / 100, "halfChanceAmount:" + halfChanceAmount);
        }