コード例 #1
0
        public void Soma_com_dois_operandos()
        {
            var converter = new InfixToPostfixConverter();
            var result    = converter.Convert("2 + 2");

            result.Should().Be("2 2 +");
        }
コード例 #2
0
        public void Expressao_complexa()
        {
            var converter = new InfixToPostfixConverter();
            var result    = converter.Convert("3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3");

            result.Should().Be("3 4 2 * 1 5 - 2 3 ^ ^ / +");
        }
コード例 #3
0
        public void Maior_precedencia_com_associatividade_direita_para_esquerda()
        {
            var converter = new InfixToPostfixConverter();
            var result    = converter.Convert("4 * 5 ^ 2");

            result.Should().Be("4 5 2 ^ *");
        }
コード例 #4
0
        public void Soma_com_parentesis_e_multiplicacao()
        {
            var converter = new InfixToPostfixConverter();
            var result    = converter.Convert("(2 + 2) * 4");

            result.Should().Be("2 2 + 4 *");
        }
コード例 #5
0
        public void Soma_e_multiplicacao()
        {
            var converter = new InfixToPostfixConverter();
            var result    = converter.Convert("2 + 2 * 4");

            result.Should().Be("2 2 4 * +");
        }
コード例 #6
0
        public void ConversionTest(string infixExpression, string expected)
        {
            var    postfixList       = InfixToPostfixConverter.Convert(infixExpression);
            string postfixExpression = "";

            foreach (var unit in postfixList)
            {
                postfixExpression += unit + " ";
            }
            Assert.AreEqual(expected, postfixExpression);
        }