public void DiceTerm_CalculateResultsChooseDiceTest()
        {
            // setup test
            IExpressionTerm term = new FudgeDiceTerm(5, 3);

            // run test
            IReadOnlyList <TermResult> results = term.CalculateResults(roller);

            // validate results
            Assert.IsNotNull(results);
            Assert.AreEqual(5, results.Count);
            int included = 0;

            foreach (TermResult r in results)
            {
                Assert.IsNotNull(r);
                Assert.AreEqual(1, r.Scalar);
                AssertHelpers.IsWithinRangeInclusive(-1, 1, r.Value);
                Assert.AreEqual("FudgeDiceTerm.dF", r.Type);
                if (r.AppliesToResultCalculation)
                {
                    included++;
                }
            }
            Assert.AreEqual(3, included);
        }
        public void FudgeDiceTerm_CalculateResultsNullDieRollerTest()
        {
            // setup test
            IExpressionTerm term = new FudgeDiceTerm(1);

            // run test
            Assert.ThrowsException <ArgumentNullException>(() => term.CalculateResults(null));

            // validate results
        }
        public void FudgeDiceTerm_ConstructorTest()
        {
            // setup test

            // run test
            IExpressionTerm term = new FudgeDiceTerm(3);

            // validate results
            Assert.IsNotNull(term);
            Assert.IsInstanceOfType(term, typeof(IExpressionTerm));
            Assert.IsInstanceOfType(term, typeof(FudgeDiceTerm));
        }
        public void FudgeDiceTerm_ToStringChooseTest()
        {
            // setup test
            IExpressionTerm term = new FudgeDiceTerm(5, 3);

            // run test
            string result = term.ToString();

            // validate results
            Assert.IsFalse(string.IsNullOrEmpty(result));
            Assert.AreEqual("5fk3", result);
        }
        /// <summary>
        /// Handles the fudge dice operator and its sub-expressions, and returns the result of the
        /// dice rolls in the results list and token value.
        /// </summary>
        /// <param name="results">List of term results</param>
        /// <param name="tokens">String expression to parse</param>
        /// <param name="op">current operator</param>
        /// <param name="dieRoller">Die roller to use</param>
        private void HandleFudgeOperator(List <TermResult> results, List <string> tokens, string op, IDieRoller dieRoller)
        {
            // find the previous and next numbers in the token list
            int opPosition = tokens.IndexOf(op);

            int numDice = int.Parse(tokens[opPosition - 1]);
            int length  = 1;

            // look-ahead to find other dice operators (like the choose-keep/drop operators)
            int?choose = this.ChooseLookAhead(tokens, opPosition, numDice, ref length);

            // create a dice term based on the values
            IExpressionTerm term = new FudgeDiceTerm(numDice, choose);

            // then evaluate the dice term to roll dice and get the result
            this.EvaluateDiceTerm(results, tokens, dieRoller, opPosition, length, term);
        }
        public void DiceTerm_CalculateResultsTest()
        {
            // setup test
            IExpressionTerm term = new FudgeDiceTerm(1);

            // run test
            IReadOnlyList <TermResult> results = term.CalculateResults(roller);

            // validate results
            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Count);
            TermResult r = results.FirstOrDefault();

            Assert.IsNotNull(r);
            Assert.AreEqual(1, r.Scalar);
            AssertHelpers.IsWithinRangeInclusive(-1, 1, r.Value);
            Assert.AreEqual("FudgeDiceTerm.dF", r.Type);
        }