示例#1
0
        public void TestShouldGive14()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(14d, RPC.Calculation("5 1 2 + 4 * + 3 -"));
        }
示例#2
0
        public void TestComplexExpressions()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(2d, RPC.Calculation("2 2 + 2 -"));
            Assert.AreEqual(9d, RPC.Calculation("3 2 - 2 + 3 *"));
            Assert.AreEqual(6d, RPC.Calculation("3 3 * 5 2 - + 2 /"));
        }
示例#3
0
        public void TestNothingAndNull()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(0d, RPC.Calculation(""));
            Assert.AreEqual(0d, RPC.Calculation(null));
        }
示例#4
0
        public void TestAllOperaters()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(4d, RPC.Calculation("2 2 +"));
            Assert.AreEqual(1d, RPC.Calculation("3 2 -"));
            Assert.AreEqual(9d, RPC.Calculation("3 3 *"));
            Assert.AreEqual(1d, RPC.Calculation("3 3 /"));
            Assert.AreEqual(81d, RPC.Calculation("3 4 ^"));

            Assert.AreEqual(2d, RPC.Calculation("2 4 - abs"));
            Assert.AreEqual(3d, RPC.Calculation("9 sqrt"));
        }