public void GetOperationElements_InvalidOperationString_ThrowsIncorrectOperationStringException()
        {
            var expressionTransformer = new ExpressionTransformer();

            TestDelegate t = () => expressionTransformer.GetOperationElements("2!2");

            Assert.Throws<IncorrectOperationStringException>(t);
        }
예제 #2
0
        public void SortElementsInOnpOrder_validOperationElements_ElementsInONPQueue(string expression, IEnumerable<string> expectedValues)
        {
            var algorithm = new OnpAlgorithm();
            var expressionTransformer = new ExpressionTransformer();

            var result = algorithm.SortElementsInOnpOrder(expressionTransformer.GetOperationElements(expression));

            Assert.AreEqual(expectedValues, result.Select(r => r.Value));
        }
        public void GetOperationElements_ValidOperationString_ElementsInQueue()
        {
            var expressionTransformer = new ExpressionTransformer();
            var expectation = new OperationElementsHelper
            {
                { OperationElementType.Number,"3" },
                { OperationElementType.Operator, "+"},
                { OperationElementType.Number, "2"}
            }.Cast<OperationElement>();

            var result = expressionTransformer.GetOperationElements("3+2");

            Assert.AreEqual(expectation.Select(r => r.ToTestValue()), result.Select(r => r.ToTestValue()));
        }
예제 #4
0
 public Calculator(ExpressionTransformer expressionTransformer, IOnpAlgorithm onpAlgorithm)
 {
     this.expressionTransformer = expressionTransformer;
     this.onpAlgorithm = onpAlgorithm;
 }