Esempio n. 1
0
        public void Input_SumAndThenSum()
        {
            // Arrange
            var input = "1 2 3 * + ";
            var sut = new ExpressionParser();

            // Act
            IExpression actual = sut.Parse(input);

            var v = new Visitor.Visitor();
            ((BinaryExpression)actual).Accept(v);

            // Assert
            Assert.AreEqual(7, actual.Eval());
            Assert.AreEqual("1 + 2 * 3", v.ToString());
        }
Esempio n. 2
0
        public void Input_SumAndThenSum()
        {
            // Arrange
            var input = "1 2 3 * + ";
            var sut   = new ExpressionParser();

            // Act
            IExpression actual = sut.Parse(input);

            var v = new Visitor.Visitor();

            ((BinaryExpression)actual).Accept(v);

            // Assert
            Assert.AreEqual(7, actual.Eval());
            Assert.AreEqual("1 + 2 * 3", v.ToString());
        }
        public void Eval_When_Sum_OneVariableAndOneConstants5and3_MustReturn_8()
        {
            // Arrange
            var sut = new SumExpression(new AssignmentExpression(
                                            new VariableExpression("P"),
                                            new ConstantExpression(5)),
                                        new ConstantExpression(3));
            var v = new Visitor.Visitor();

            sut.Accept(v);

            // Act
            var actual = sut.Eval();


            // Assert
            Assert.AreEqual(expected: 8, actual: actual);
            Assert.AreEqual("(P = 5) + 3", v.ToString());
        }
        public void Eval_When_Sum_OneVariableAndOneConstants5and3_MustReturn_8()
        {
            // Arrange
            var sut = new SumExpression(new AssignmentExpression(
                                                new VariableExpression("P"),
                                                new ConstantExpression(5)),
                                            new ConstantExpression(3));
            var v = new Visitor.Visitor();
            sut.Accept(v);

            // Act
            var actual = sut.Eval();

            // Assert
            Assert.AreEqual(expected: 8, actual: actual);
            Assert.AreEqual("(P = 5) + 3", v.ToString());
        }