Пример #1
0
        public void TestDieExpression()
        {
            var de = new DiceExpression("1d6");

            Assert.AreEqual(3.5, de.GetExpected());
            Assert.AreEqual(1, de.GetMin());
            Assert.AreEqual(6, de.GetMax());

            de = new DiceExpression("2d6");
            Assert.AreEqual(7, de.GetExpected());
            Assert.AreEqual(2, de.GetMin());
            Assert.AreEqual(12, de.GetMax());

            de = new DiceExpression("1d12");
            Assert.AreEqual(6.5, de.GetExpected());
            Assert.AreEqual(1, de.GetMin());
            Assert.AreEqual(12, de.GetMax());

            de = new DiceExpression("1d6", new Random(0));
            var results = new Dictionary <int, int>()
            {
                { 1, 0 },
                { 2, 0 },
                { 3, 0 },
                { 4, 0 },
                { 5, 0 },
                { 6, 0 }
            };

            for (var i = 0; i < 6000; i++)
            {
                results[(int)de.Roll()]++;
            }

            Assert.LessOrEqual(Math.Abs(results[1] - 1000), 50);
            Assert.LessOrEqual(Math.Abs(results[2] - 1000), 50);
            Assert.LessOrEqual(Math.Abs(results[3] - 1000), 50);
            Assert.LessOrEqual(Math.Abs(results[4] - 1000), 50);
            Assert.LessOrEqual(Math.Abs(results[5] - 1000), 50);
            Assert.LessOrEqual(Math.Abs(results[6] - 1000), 50);
        }