public void TestKeepDropModifier()
        {
            var de = new DiceExpression("4d6dl1", new RandomMock());

            Assert.AreEqual(9, de.Roll());
            Assert.AreEqual(12.2, de.GetExpected(), 0.15);

            de = new DiceExpression("4d6kl1", new RandomMock());
            Assert.AreEqual(1, de.Roll());
            Assert.AreEqual(1.8, de.GetExpected(), 0.15);

            de = new DiceExpression("4d6dh1", new RandomMock());
            Assert.AreEqual(6, de.Roll());
            Assert.AreEqual(8.8, de.GetExpected(), 0.15);

            de = new DiceExpression("4d6kh1", new RandomMock());
            Assert.AreEqual(4, de.Roll());
            Assert.AreEqual(5.2, de.GetExpected(), 0.15);

            de = new DiceExpression("4d6dl2", new RandomMock());
            Assert.AreEqual(7, de.Roll());

            de = new DiceExpression("4d6kl2", new RandomMock());
            Assert.AreEqual(3, de.Roll());

            de = new DiceExpression("4d6dh2", new RandomMock());
            Assert.AreEqual(3, de.Roll());

            de = new DiceExpression("4d6kh2", new RandomMock());
            Assert.AreEqual(7, de.Roll());


            de = new DiceExpression("4d6kl2", new Random());
            var exp = de.GetExpected(10000);

            Console.WriteLine(exp);
            Assert.AreEqual(4.66, exp, 0.05);

            de  = new DiceExpression("4d6kh2", new Random());
            exp = de.GetExpected(10000);
            Console.WriteLine(exp);
            Assert.AreEqual(9.34, exp, 0.05);
        }
Exemplo n.º 2
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);
        }