Пример #1
0
        public void AddsTwoNumbers()
        {
            // Arrange
            var adding = new AddExpression(new ConstantExpression(1), new ConstantExpression(1));

            // Act
            var result = adding.Solve(new Context());

            // Assert
            Assert.Equal(2, result);
        }
Пример #2
0
        public void DoesLittleBitMoreComplicatedCalculation()
        {
            // Arrange
            var adding            = new AddExpression(new ConstantExpression(1), new ConstantExpression(1));
            var subtracting       = new SubtractExpression(new ConstantExpression(4), new ConstantExpression(2));
            var subtractingResult = new SubtractExpression(adding, subtracting);

            // Act
            var result = subtractingResult.Solve(null);

            // Assert
            Assert.Equal(0, result);
        }
Пример #3
0
        public void CalculatesExpressionWithVariable()
        {
            // Arrange
            var adding            = new AddExpression(new ConstantExpression(1), new Variable("n"));
            var subtracting       = new SubtractExpression(new ConstantExpression(4), new Variable("n"));
            var subtractingResult = new SubtractExpression(adding, subtracting);
            var n       = 3;
            var context = new Context();

            context.SetVariable("n", new ConstantExpression(n));

            // Act
            var result = subtractingResult.Solve(context);

            // Assert
            Assert.Equal((1 + n) - (4 - n), result);
            Assert.Equal(3, result);
        }