public void Evaluate_SymbolExpression_Correctly()
        {
            //Demonstrates how to evaluate a general expression by deferring the loading of values from a data source.

            //Arrange
            string expression = "a +- (b + c) --d";
            var    dataSource = new Dictionary <string, int>
            {
                { "a", 2 }, { "b", 3 }, { "c", -4 }, { "d", 5 }
            };
            var evaluator = new IntEvaluator();

            evaluator.ValueForToken = token =>
            {
                if (dataSource.ContainsKey(token.Value))
                {
                    return(dataSource[token.Value]);
                }
                else
                {
                    return(evaluator.GetValueDefaultAccessor()(token)); //In successive token evaluations, the symbol is already replaced so we should use the default accessor
                }
            };

            //Act
            var result = evaluator.Evaluate(new Parser(expression).Parse());

            //Assert
            Assert.Equal("8", result.Value);
        }
        public void Evaluate_IntExpressions_Correctly(string expression, int expected)
        {
            //Arrange
            var parser    = new Parser(expression);
            var evaluator = new IntEvaluator();

            //Act
            Token t = evaluator.Evaluate(parser.Parse());

            //Assert
            Assert.Equal(expected, int.Parse(t.Value));
        }