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

            result.Should().Be("2 2 +");
        }
Exemple #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 ^ ^ / +");
        }
Exemple #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 ^ *");
        }
Exemple #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 *");
        }
Exemple #5
0
        public void Soma_e_multiplicacao()
        {
            var converter = new InfixToPostfixConverter();
            var result    = converter.Convert("2 + 2 * 4");

            result.Should().Be("2 2 4 * +");
        }
        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);
        }