public void ComplexExpressionCorrectCalculation() { var operationProvider = new BasicOperationProvider(); var converter = new PostfixConverterSortStation(operationProvider); var executor = new PostfixExecutor(operationProvider); var input = @"4 * 5 - 27 / 3"; var calculator = new Calculator(converter, executor); var result = calculator.Calculate(input); Assert.Equal(11, result); }
public void TwoNumbersAdditionCorrectResult() { var postfix = @"2 2 +"; var provider = new Mock<IOperationProvider>(); provider.Setup(m => m.IsOperation(@"+")).Returns(true); provider.Setup(m => m.GetOperation(@"+")).Returns(new AddOperation()); var executor = new PostfixExecutor(provider.Object); var result = executor.Execute(postfix); Assert.Equal(4, result); }
public void DivisionByZeroExceptionThrow() { var operationProvider = new BasicOperationProvider(); var converter = new PostfixConverterSortStation(operationProvider); var executor = new PostfixExecutor(operationProvider); var input = @"13 / 0"; var calculator = new Calculator(converter, executor); Assert.Throws(typeof(DivideByZeroException), () => { calculator.Calculate(input); }); }
public void MissingOperandExpressionExceptionThrow() { var operationProvider = new BasicOperationProvider(); var converter = new PostfixConverterSortStation(operationProvider); var executor = new PostfixExecutor(operationProvider); var input = @"2 + + 7"; var calculator = new Calculator(converter, executor); Assert.Throws(typeof(IncorrectExpressionException), () => { calculator.Calculate(input); }); }
public void ComplexExpressionCorrectResult() { var postfix = @"4 6 2 / +"; var provider = new Mock<IOperationProvider>(); provider.Setup(m => m.IsOperation(@"/")).Returns(true); provider.Setup(m => m.IsOperation(@"+")).Returns(true); provider.Setup(m => m.GetOperation(@"/")).Returns(new DivOperation()); provider.Setup(m => m.GetOperation(@"+")).Returns(new AddOperation()); var executor = new PostfixExecutor(provider.Object); var result = executor.Execute(postfix); Assert.Equal(7, result); }