public Calculator(IPostfixBuilder postfixBuilder,
                   IPostfixCalculator postfixCalculator, IEquationParser equationParser)
 {
     _postfixBuilder    = postfixBuilder;
     _postfixCalculator = postfixCalculator;
     _equationParser    = equationParser;
 }
Esempio n. 2
0
        public void EvaluateExpression_Should_ThrowArgumentNullException_When_PassedNull()
        {
            this.postfixCalculator =
                new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object);

            Assert.ThrowsException <ArgumentNullException>(() => this.postfixCalculator.EvaluateExpression(null));
        }
Esempio n. 3
0
        public void EvaluateExpression_Should_ThrowInvalidMathematicalExpressionException_When_PassedEmptyCollection()
        {
            this.postfixCalculator =
                new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object);

            Assert.ThrowsException <InvalidMathematicalExpressionException>(
                () => this.postfixCalculator.EvaluateExpression(new List <string>()));
        }
Esempio n. 4
0
        public void EvaluateExpression_Should_ThrowInvalidMathematicaExpressionException_When_Passed_StringEnumerableWhitInvalidElement()
        {
            const string token = "Pesho";
            var          args  = new List <string> {
                token
            };

            this.operationTableMock.Setup(x => x.Contains(token)).Returns(false);

            this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object);

            Assert.ThrowsException <InvalidMathematicalExpressionException>(() => this.postfixCalculator
                                                                            .EvaluateExpression(args));
        }
Esempio n. 5
0
        public void EvaluateExpression_Should_ThrowInvalidOperationException_When_OperationCannotBeExecuted()
        {
            const string operation = "+";
            var          args      = new List <string> {
                operation
            };

            var operationStub = new Mock <IOperation>();

            this.operationTableMock.Setup(x => x.Contains(operation)).Returns(true);
            this.opeartionFacotryMock.Setup(x => x.CreateOperation(operation)).Returns(operationStub.Object);

            this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object);

            Assert.ThrowsException <InvalidOperationException>(() => this.postfixCalculator
                                                               .EvaluateExpression(args));
        }
Esempio n. 6
0
        public void EvaluateExpression_Should_InvokeCreateOperation_When_Passed_StringEnumerableContainigOperation()
        {
            const string operation = "+";

            this.operationTableMock.Setup(x => x.Contains(operation)).Returns(true);
            this.opeartionFacotryMock.Setup(x => x.CreateOperation(operation)).Throws <NotImplementedException>();

            this.postfixCalculator =
                new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object);

            try
            {
                this.postfixCalculator.EvaluateExpression(new List <string> {
                    "2", "2", operation
                });
            }
            catch (NotImplementedException) { }

            this.opeartionFacotryMock.Verify(x => x.CreateOperation(operation), Times.Once);
        }
Esempio n. 7
0
 public Expression(IExpressionParser parser, IInfixToPostfixConverter postfixConverter, IPostfixCalculator postfixCalculator)
 {
     this.parser            = parser;
     this.postfixConverter  = postfixConverter;
     this.postfixCalculator = postfixCalculator;
 }