Exemplo n.º 1
0
        public void TestOfInfixToPostfix()
        {
            string infix           = "2 * 3 ^ 4";
            string expectedPostfix = "2 3 4 ^ *";
            string postfix         = RPNCalculator.InfixToPostfix(infix);

            Assert.That(postfix, Is.EqualTo(expectedPostfix));
        }
Exemplo n.º 2
0
        public void TestOfPostfixEvaluator2()
        {
            string infix   = "2 * 3 ^ x";
            string postfix = RPNCalculator.InfixToPostfix(infix, 2);
            double result  = RPNCalculator.PostfixEvaluator(postfix);

            Assert.That(result, Is.EqualTo(18));
        }
        public void InfixToPostfix_PassInfix_ReturnsPostfix()
        {
            //Arrange
            var inputValue    = new string[] { "(", "20", "+", "50", ")", "*", "(", "30", "+", "20", ")" };
            var expectedValue = new string[] { "20", "50", "+", "30", "20", "+", "*" };

            //Act
            var postfix = RPNCalculator.InfixToPostfix(inputValue);

            //Assert
            Assert.Equal(postfix, expectedValue);
        }
Exemplo n.º 4
0
        public void InfixToPostfixTest()
        {
            Assert.AreEqual(RPNCalculator.InfixToPostfix("2 + 3"), "2 3 +");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("6 - 2"), "6 2 -");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("12 * 5"), "12 5 *");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("3 ^ 2"), "3 2 ^");

            Assert.AreEqual(RPNCalculator.InfixToPostfix("2 + 3 - 2"), "2 3 + 2 -");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("5 * 4 / 9"), "5 4 * 9 /");

            Assert.AreEqual(RPNCalculator.InfixToPostfix("2 + 3 * 5"), "2 3 5 * +");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("5 * 3 + 1"), "5 3 * 1 +");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("2 * 3 + 8 / 4"), "2 3 * 8 4 / +");

            Assert.AreEqual(RPNCalculator.InfixToPostfix("7 * ( 2 + 3 )"), "7 2 3 + *");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("2 * ( 3 + 8 ) / 4"), "2 3 8 + * 4 /");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("9 / ( ( 4 + 2 ) * 3 )"), "9 4 2 + 3 * /");

            Assert.AreEqual(RPNCalculator.InfixToPostfix("2 ^ 3 ^ 4"), "2 3 4 ^ ^");
            Assert.AreEqual(RPNCalculator.InfixToPostfix("4 * 9 ^ 6"), "4 9 6 ^ *");
        }