Exemplo n.º 1
0
        public void TestShouldGive14()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(14d, RPC.Calculation("5 1 2 + 4 * + 3 -"));
        }
Exemplo n.º 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 /"));
        }
Exemplo n.º 3
0
        public void TestNothingAndNull()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(0d, RPC.Calculation(""));
            Assert.AreEqual(0d, RPC.Calculation(null));
        }
Exemplo n.º 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"));
        }