public void ToStringExpressionShouldCopyOperatorToStringExpression()
 {
     var integerExpression = new IntegerExpression("2");
     integerExpression.Operator = Operator.Plus;
     var result = _converter.ToStringExpression(integerExpression);
     Assert.AreEqual(integerExpression.Operator, result.Operator);
 }
 public void ToStringExpressionShouldConvertIntegerExpressionToStringExpression()
 {
     var integerExpression = new IntegerExpression("2");
     var result = _converter.ToStringExpression(integerExpression);
     Assert.IsInstanceOfType(result, typeof(StringExpression));
     Assert.AreEqual("2", result.Compile().Result);
 }
        public void MergeWithNextWithPlusOperatorShouldSetNextPointer()
        {
            var exp1 = new IntegerExpression("1");
            exp1.Operator = Operator.Plus;
            var exp2 = new IntegerExpression("2");
            exp1.Next = exp2;

            var result = exp1.MergeWithNext();

            Assert.IsNull(result.Next);
        }
        public void MergeWithNextWithPlusOperatorShouldCalulateSumCorrectly()
        {
            var exp1 = new IntegerExpression("1");
            exp1.Operator = Operator.Plus;
            var exp2 = new IntegerExpression("2");
            exp1.Next = exp2;

            var result = exp1.MergeWithNext();

            Assert.AreEqual(3d, result.Compile().Result);
        }
        public void ShouldCompileTwoInterExpressionsToCorrectResult()
        {
            var exp1 = new IntegerExpression("2");
            exp1.Operator = Operator.Plus;
            _graph.Add(exp1);
            var exp2 = new IntegerExpression("2");
            _graph.Add(exp2);

            var result = _expressionCompiler.Compile(_graph.Expressions);

            Assert.AreEqual(4d, result.Result);
        }
        public void CompileShouldCalculateMultipleExpressionsAccordingToPrecedence()
        {
            var exp1 = new IntegerExpression("2");
            exp1.Operator = Operator.Multiply;
            _graph.Add(exp1);
            var exp2 = new IntegerExpression("2");
            exp2.Operator = Operator.Plus;
            _graph.Add(exp2);
            var exp3 = new IntegerExpression("2");
            exp3.Operator = Operator.Multiply;
            _graph.Add(exp3);
            var exp4 = new IntegerExpression("2");
            _graph.Add(exp4);

            var result = _expressionCompiler.Compile(_graph.Expressions);

            Assert.AreEqual(8d, result.Result);
        }