public void DiceParser_ParseParensSidesTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("2d(2x3)+2", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("2d(2x3)+2", result.DiceExpression);
            Assert.AreEqual(2, result.Results.Count);
            Assert.AreEqual(6, result.Value);
        }
        public void DiceParser_ParseParensNumDiceTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("(1+3)d8", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("(1+3)d8", result.DiceExpression);
            Assert.AreEqual(4, result.Results.Count);
            Assert.AreEqual(8, result.Value);
        }
        public void DiceParser_ParseConstantOnlyDivideTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("4/2", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("4/2", result.DiceExpression);
            Assert.AreEqual(0, result.Results.Count);
            Assert.AreEqual(2, result.Value);
        }
        public void DiceParser_ParseParensFudgeTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("(10f-2) / (1+1)", this.config, this.roller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("(10f-2)/(1+1)", result.DiceExpression);
            Assert.AreEqual(10, result.Results.Count);
            AssertHelpers.IsWithinRangeInclusive(-5, 5, result.Value);
        }
        public void DiceParser_ParseSimpleDiceTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("3d6", config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("3d6", result.DiceExpression);
            Assert.AreEqual(3, result.Results.Count);
            Assert.AreEqual(6, result.Value);
        }
        public void DiceParser_ParseDicePercentileTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("d%+5", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("d100+5", result.DiceExpression);
            Assert.AreEqual(1, result.Results.Count);
            Assert.AreEqual(7, result.Value);
        }
        public void DiceParser_ParseDiceNegativeConstantTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("-5 + 4d6", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("-5+4d6", result.DiceExpression);
            Assert.AreEqual(4, result.Results.Count);
            Assert.AreEqual(3, result.Value);
        }
        public void DiceParser_ParseDiceMultipleConstantsOrderTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("2+1d20+2+3x3-10", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("2+1d20+2+3x3-10", result.DiceExpression);
            Assert.AreEqual(1, result.Results.Count);
            Assert.AreEqual(5, result.Value);
        }
        public void DiceParser_ParseParensComplex4Test()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("(((2+1d20)+(2+3))x3-10+(3))", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("(((2+1d20)+(2+3))x3-10+(3))", result.DiceExpression);
            Assert.AreEqual(1, result.Results.Count);
            Assert.AreEqual(20, result.Value);
        }
        public void DiceParser_ParseDiceSubractOrderTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("100 - 2d12", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("100-2d12", result.DiceExpression);
            Assert.AreEqual(2, result.Results.Count);
            Assert.AreEqual(96, result.Value);
        }
        public void DiceParser_ParseDiceWithDivideBeforeTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("40 / 1d6", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("40/1d6", result.DiceExpression);
            Assert.AreEqual(1, result.Results.Count);
            Assert.AreEqual(20, result.Value);
        }
        public void DiceParser_ParseDiceWithMultiplyAfterTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("2d8x10", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("2d8x10", result.DiceExpression);
            Assert.AreEqual(2, result.Results.Count);
            Assert.AreEqual(40, result.Value);
        }
        public void DiceParser_ParseDiceWithExplodingNoValueModifierTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("6d6!+2", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("6d6!+2", result.DiceExpression);
            Assert.AreEqual(6, result.Results.Count);
            Assert.AreEqual(14, result.Value);
        }
        public void DiceParser_ParseSingleDieNoSidesTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("d", this.config, this.testRoller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("d", result.DiceExpression);
            Assert.AreEqual(1, result.Results.Count);
            Assert.AreEqual("DiceTerm.d6", result.Results[0].Type);
            Assert.AreEqual(2, result.Value);
        }
Esempio n. 15
0
        public void Dice_RollWithNegativeResultUnboundedTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            IDice dice = new Dice();

            dice.Configuration.HasBoundedResult = false;
            DiceResult result = parser.Parse("d12-3", dice.Configuration, new ConstantDieRoller(1));

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("d12-3", result.DiceExpression);
            Assert.AreEqual(1, result.Results.Count);
            Assert.AreEqual(-2, result.Value);
        }
Esempio n. 16
0
        public void DiceParser_ParseDiceFudgeModifierTest()
        {
            // setup test
            DiceParser parser = new DiceParser();

            // run test
            DiceResult result = parser.Parse("3f+1", this.config, this.roller);

            // validate results
            Assert.IsNotNull(result);
            Assert.AreEqual("3f+1", result.DiceExpression);
            Assert.AreEqual(3, result.Results.Count);
            int sum = 0;

            foreach (TermResult r in result.Results)
            {
                Assert.AreEqual("FudgeDiceTerm.dF", r.Type);
                sum += r.Value;
            }
            Assert.AreEqual(sum + 1, result.Value);
        }
Esempio n. 17
0
        public void Parse_OneDiceTerm_ExpectedExpression()
        {
            DiceExpression diceExpression = _diceParser.Parse("3d6");

            Assert.AreEqual("3d6", diceExpression.ToString());
        }
Esempio n. 18
0
        private async Task OnMessageReceivedAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;     // Ensure the message is from a user/bot

            if (msg == null)
            {
                return;
            }
            if (msg.Author.Id == _client.CurrentUser.Id)
            {
                return;                                              // Ignore self when checking commands
            }
            if (!msg.ToString().StartsWith("~"))
            {
                return;
            }

            var context = new SocketCommandContext(_client, msg);     // Create the command context

            bool   messageChannel = true;
            string response       = "";

            var commands = msg.ToString().Substring(1).Split(' ');

            switch (commands[0].ToLower())
            {
            case "help":
                response      += Help();
                messageChannel = false;
                break;

            case "weather":
            case "w":
                WeatherCommand wc = new WeatherCommand(_rng, _logger);
                response = wc.Generate(commands);
                break;

            case "wildsurge":
            case "ws":
                WildSurgeCommand wcs = new WildSurgeCommand(_rng, _logger);
                response = wcs.Generate(commands);
                break;

            case "npc":
                NPCCommand npcc = new NPCCommand(_rng, _logger);
                response = npcc.Generate(commands);
                break;

            case "injury":
                InjuryCommand injury = new InjuryCommand(_rng, _logger);
                response = injury.Generate(commands);
                break;

            case "madness":
                MadnessCommand madness = new MadnessCommand(_rng, _logger);
                response = madness.Generate(commands);
                break;

            case "bard":
                BardCommand bard = new BardCommand(_rng, _logger);
                response = bard.Generate(commands);
                break;

            default:
                response += "Command not recognized";
                break;
            }

            if (messageChannel)
            {
                await context.Channel.SendMessageAsync(_diceParser.Parse(response));
            }
            else
            {
                await context.User.SendMessageAsync(response);
            }
            await context.Channel.SendMessageAsync("I have sent help to your PMs.");
        }
Esempio n. 19
0
        public void HandlesOneDieTerm()
        {
            DiceExpression diceExpression = _diceParser.Parse("3d6");

            Assert.AreEqual("3d6", diceExpression.ToString());
        }