示例#1
0
        public void TestPolishNotation3()
        {
            List <Token> source = new List <Token>()
            {
                new TokenOperand()
                {
                    Value = "2"
                },
                new TokenOperation()
                {
                    Value = "+", Priority = 10
                },
                new TokenOperand()
                {
                    Value = "3"
                },
                new TokenOperation()
                {
                    Value = "*", Priority = 20
                },
                new TokenOperand()
                {
                    Value = "8"
                },
            };
            Alu           alu    = new Alu();
            Stack <Token> temp   = new Stack <Token>();
            Queue <Token> actual = new Queue <Token>();

            alu.GetPolishNotation(source, temp, actual);
            Queue <Token> expected = new Queue <Token>();

            expected.Enqueue(new TokenOperand()
            {
                Value = "2"
            });
            expected.Enqueue(new TokenOperand()
            {
                Value = "3"
            });
            expected.Enqueue(new TokenOperand()
            {
                Value = "8"
            });
            expected.Enqueue(new TokenOperation()
            {
                Value = "*"
            });
            expected.Enqueue(new TokenOperation()
            {
                Value = "+"
            });
            Assert.AreEqual(expected, actual);
        }