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

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

            Assert.AreEqual(1d, RPC.InfixCalculation("1 ^ 2 * 3"));
            Assert.AreEqual(8d, RPC.InfixCalculation("1 * 2 ^ 3"));
        }
示例#3
0
        public void InfixTestComplexExpressions()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

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

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

            Assert.AreEqual(2d, RPC.InfixCalculation("abs ( 2 - 4 )"));
            Assert.AreEqual(3d, RPC.InfixCalculation("sqrt ( 9 )"));
        }
示例#5
0
        public void InfixTestXBeforePlus()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

            Assert.AreEqual(7d, RPC.InfixCalculation("1 + 2 * 3"));
            Assert.AreEqual(5d, RPC.InfixCalculation("1 * 2 + 3"));
            Assert.AreEqual(33d, RPC.InfixCalculation("5 + ( 1 + 2 * 3 ) * 4"));
        }
示例#6
0
        public void InfixTestShouldGive14()
        {
            var RPC = new ReversePolishCalculator();
            RPC.InitOperations();

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

            Assert.AreEqual(14d, RPC.Calculation("5 1 2 + 4 * + 3 -"));
        }
示例#8
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 /"));
        }
示例#9
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"));
        }