示例#1
0
        public void Parser_correct_parses_digit_with_comma()
        {
            var    parser     = new Parser();
            string inputValue = "23,5";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            Assert.Collection(result, item => AssertExpressionUnit.Equal(new NumberExpressionUnit("23,5", "23.5"), item));
        }
示例#2
0
        public void Parser_parses_digit_with_unary_minus()
        {
            var    parser     = new Parser();
            string inputValue = "-8";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("-", "~"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("8"), item));
        }
示例#3
0
        public void Parser_parses_digit_with_dot()
        {
            var    parser     = new Parser();
            string inputValue = "23.5";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            var expectedItem = new NumberExpressionUnit("23.5");

            Assert.Collection(result, item => AssertExpressionUnit.Equal(expectedItem, item));
        }
示例#4
0
        public void Parser_parses_digit_and_operation()
        {
            var    parser     = new Parser();
            string inputValue = "3+2";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("3"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("+"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2"), item));
        }
        public void NotationConverter_converts_one_digit_to_RPN()
        {
            var notationConverter = new NotationConverter();
            var inputValue        = new List <ExpressionUnit>
            {
                new NumberExpressionUnit("2.00")
            };

            var result = notationConverter.ConvertToReversePolishNotation(inputValue, _mathOperationsContainer);

            var expectedItem = new NumberExpressionUnit("2.00");

            Assert.Collection(result, item => AssertExpressionUnit.Equal(expectedItem, item));
        }
        public void NotationConverter_converts_digit_with_unary_minus_to_RPN()
        {
            var notationConverter = new NotationConverter();
            var inputValue        = new List <ExpressionUnit>()
            {
                new OperationExpressionUnit("-", "~"),
                new NumberExpressionUnit("8.00")
            };

            var result = notationConverter.ConvertToReversePolishNotation(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("8.00"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("-", "~"), item));
        }
示例#7
0
        public void Parser_parses_digit_with_unary_minus_and_sub_operation_in_brackets()
        {
            var    parser     = new Parser();
            string inputValue = "-(8-2)";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("-", "~"), item),
                              item => AssertExpressionUnit.Equal(new LeftBracketExpressionUnit(), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("8"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("-"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2"), item),
                              item => AssertExpressionUnit.Equal(new RightBracketExpressionUnit(), item));
        }
示例#8
0
        public void Parser_parses_digit_and_operation_with_branches()
        {
            var    parser     = new Parser();
            string inputValue = "3.1*(2.7+5)";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("3.1"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("*"), item),
                              item => AssertExpressionUnit.Equal(new LeftBracketExpressionUnit(), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2.7"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("+"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("5"), item),
                              item => AssertExpressionUnit.Equal(new RightBracketExpressionUnit(), item));
        }
示例#9
0
        public void Parser_parses_first_operand_in_brackets_and_binary_operation()
        {
            var    parser     = new Parser();
            string inputValue = "(8+2)*2";

            var result = parser.Parse(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new LeftBracketExpressionUnit(), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("8"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("+"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2"), item),
                              item => AssertExpressionUnit.Equal(new RightBracketExpressionUnit(), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("*"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2"), item));
        }
        public void NotationConverter_converts_two_digit_and_operation_with_brackets_to_RPN()
        {
            var notationConverter = new NotationConverter();
            var inputValue        = new List <ExpressionUnit>()
            {
                new LeftBracketExpressionUnit(),
                new NumberExpressionUnit("3.00"),
                new OperationExpressionUnit("+"),
                new NumberExpressionUnit("2.00"),
                new RightBracketExpressionUnit()
            };

            var result = notationConverter.ConvertToReversePolishNotation(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("3.00"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2.00"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("+"), item));
        }
        public void NotationConverter_converts_higher_priority_unary_operation_and_lower_priority_binary_operation_to_RPN()
        {
            var notationConverter = new NotationConverter();
            var inputValue        = new List <ExpressionUnit>()
            {
                new OperationExpressionUnit("-", "~"),
                new NumberExpressionUnit("8.00"),
                new OperationExpressionUnit("+"),
                new NumberExpressionUnit("2.00"),
            };

            var result = notationConverter.ConvertToReversePolishNotation(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("8.00"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("-", "~"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2.00"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("+"), item));
        }
        public void NotationConverter_converts_expression_with_first_priority_operation_to_RPN()
        {
            var notationConverter = new NotationConverter();
            var inputValue        = new List <ExpressionUnit>()
            {
                new NumberExpressionUnit("4.00"),
                new OperationExpressionUnit("+"),
                new NumberExpressionUnit("2.00"),
                new OperationExpressionUnit("*"),
                new NumberExpressionUnit("3.00")
            };

            var result = notationConverter.ConvertToReversePolishNotation(inputValue, _mathOperationsContainer);

            Assert.Collection(result,
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("4.00"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("2.00"), item),
                              item => AssertExpressionUnit.Equal(new NumberExpressionUnit("3.00"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("*"), item),
                              item => AssertExpressionUnit.Equal(new OperationExpressionUnit("+"), item));
        }