Пример #1
0
        public void InfixTestNothingAndNull()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(0d, RPC.InfixCalculate(""));
            Assert.AreEqual(0d, RPC.InfixCalculate(null));
        }
Пример #2
0
        public void InfixTestPowBeforeX()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(1d, RPC.InfixCalculate("1 ^ 2 * 3"));
            Assert.AreEqual(8d, RPC.InfixCalculate("1 * 2 ^ 3"));
        }
Пример #3
0
        public void InfixTestComplexExpressions()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(2d, RPC.InfixCalculate("( 2 + 2 ) - 2"));
            Assert.AreEqual(9d, RPC.InfixCalculate("( ( 3 - 2 ) + 2 ) * 3"));
            Assert.AreEqual(6d, RPC.InfixCalculate("( ( 3 * 3 ) + ( 5 - 2 ) ) / 2"));
        }
Пример #4
0
        public void InfixTestAllOperaters()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(4d, RPC.InfixCalculate("2 + 2"));
            Assert.AreEqual(1d, RPC.InfixCalculate("3 - 2"));
            Assert.AreEqual(9d, RPC.InfixCalculate("3 * 3"));
            Assert.AreEqual(1d, RPC.InfixCalculate("3 / 3"));
            Assert.AreEqual(81d, RPC.InfixCalculate("3 ^ 4"));
        }
Пример #5
0
        public void TestAllOperaters()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(4d, RPC.Calculate("2 2 +"));
            Assert.AreEqual(1d, RPC.Calculate("3 2 -"));
            Assert.AreEqual(9d, RPC.Calculate("3 3 *"));
            Assert.AreEqual(1d, RPC.Calculate("3 3 /"));
            Assert.AreEqual(81d, RPC.Calculate("3 4 ^"));
        }
Пример #6
0
        public void InfixTestXBeforePlus()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(7d, RPC.InfixCalculate("1 + 2 * 3"));
            Assert.AreEqual(5d, RPC.InfixCalculate("1 * 2 + 3"));
            Assert.AreEqual(33d, RPC.InfixCalculate("5 + ( 1 + 2 * 3 ) * 4"));
        }
Пример #7
0
        public void InfixTestShouldGive14()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(14d, RPC.InfixCalculate("( 5 + ( ( 1 + 2 ) * 4 ) ) - 3"));
        }
Пример #8
0
        public void TestShouldGive14()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(14d, RPC.Calculate("5 1 2 + 4 * + 3 -"));
        }
Пример #9
0
        public void TestComplexExpressions()
        {
            var RPC = new ReversePolishCalculator();

            Assert.AreEqual(2d, RPC.Calculate("2 2 + 2 -"));
            Assert.AreEqual(9d, RPC.Calculate("3 2 - 2 + 3 *"));
            Assert.AreEqual(6d, RPC.Calculate("3 3 * 5 2 - + 2 /"));
        }
Пример #10
0
        private static void Main(string[] args)
        {
            var RPC = new ReversePolishCalculator();

            while (true)
            {
                var s = Console.ReadLine();
                if (s == "quit")
                    break;
                Console.WriteLine("= " + RPC.Calculate(s));
            }
        }