Beispiel #1
0
        public void RPNInterpreterTest6()
        {
            //substraction of 1 negative 1 positive
            string         expression   = "-1-2";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(-3, result);
        }
Beispiel #2
0
        public void RPNInterpreterTest5()
        {
            //substraction of 2 negative numbers
            string         expression   = "-1-(-2)"; //check if no parantheses is illegal
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(1, result);
        }
Beispiel #3
0
        public void RPNInterpreterTest2()
        {
            //addition of 2 negative numbers
            string         expression   = "-1-2";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(-3, result);
        }
Beispiel #4
0
        /// ///////////////////////////////////MULTIPLICATION///////////////////////////////////////////////////////////
        public void RPNInterpreterTest7()
        {
            //multiplication of 2 positive numbers
            string         expression   = "1*2";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(2, result);
        }
Beispiel #5
0
        /// ////////////////////////////////////////////////////////////////////TRIGONOMETRY/////////////////////////////////////////


        public void RPNInterpreterTest28()
        {
            //test
            //trignomatery
            string         expression   = " sin(0)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(0, result);
        }
Beispiel #6
0
        public void RPNInterpreterLogarithm10()
        {
            //test
            //log functions
            string         expression   = " (log(100/10)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(1, result);
        }
Beispiel #7
0
        public void RPNInterpreterTest15()
        {
            //test
            //mul by 0
            string         expression   = "10*0";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(0, result);
        }
Beispiel #8
0
        public void RPNInterpreterSerial5()
        {
            //test
            //multiple expression
            string         expression   = "2/2*3+1";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(4, result);
        }
Beispiel #9
0
        public void RPNInterpreterTest22()
        {
            //test
            //negative power of a negative positive num
            string         expression   = "-2^(-2)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(0.25, result);
        }
Beispiel #10
0
        public void RPNInterpreterTest20()
        {
            //test
            //power of a positive num
            string         expression   = "2^(4)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(16, result);
        }
Beispiel #11
0
        public void RPNInterpreterTest18()
        {
            //test
            //square root of a positive num
            string         expression   = "25^(1/2)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(5, result);
        }
Beispiel #12
0
        /// ///////////////////////////////////////////////////// POWER FUNCTIONS //////////////////////////////////////


        public void RPNInterpreterTest16()
        {
            //test
            //squrae of a neg num
            string         expression   = "-2^2";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();
            double         result       = RPN.compute(parsedValues);

            Assert.AreEqual(4, result);
        }
Beispiel #13
0
        public void RPNInterpreterLogarithm9()
        {
            //test
            //log functions
            string         expression   = " (log(100)/*2)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();

            try
            {
                double result = RPN.compute(parsedValues);
                Assert.Fail("Expected exception");
            }
            catch (InvalidOperationException) { }
        }
Beispiel #14
0
        public void RPNInterpreterSerial25()
        {
            //test
            //multiple  expressions
            string         expression   = "1hh";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();

            try
            {
                double result = RPN.compute(parsedValues);
                Assert.Fail("Expected exception");
            }
            catch (ArgumentException) { }
        }
Beispiel #15
0
        public void RPNInterpreterSerial9()
        {
            //test
            //multiple  expressions
            string         expression   = "+1+1+1+1*0-1/-1/1";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();

            try
            {
                double result = RPN.compute(parsedValues);
                Assert.Fail("Expected exception");
            }
            catch (InvalidOperationException) { }
        }
Beispiel #16
0
        public void RPNInterpreterTest19()
        {
            //test
            //square root of a negative num
            string         expression   = "-25^(1/2)";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();

            try
            {
                double result = RPN.compute(parsedValues);
                Assert.Fail("Expected exception");
            }
            catch (ArgumentException) { }
        }
Beispiel #17
0
        /// ///////////////////////////////////SUBSTRACT///////////////////////////////////////////////////////////
        public void RPNInterpreterTest4()
        {
            //substraction of 2 positive numbers
            string        expression   = "1-2";
            Parser        parser       = new Parser();
            List <string> parsedValues = parser.parse(expression);

            foreach (string s in parsedValues)
            {
                Console.WriteLine(s);
            }
            RPNInterpreter RPN    = new RPNInterpreter();
            double         result = RPN.compute(parsedValues);

            Assert.AreEqual(-1, result);
        }
Beispiel #18
0
        public void RPNInterpreterTest14()
        {
            //test
            //divide by 0
            string         expression   = "10/0";
            Parser         parser       = new Parser();
            List <string>  parsedValues = parser.parse(expression);
            RPNInterpreter RPN          = new RPNInterpreter();

            try
            {
                double result = RPN.compute(parsedValues);
                Assert.Fail("Expected exception");
            }
            catch (ArgumentException) { }
        }
Beispiel #19
0
        public void RPNInterpreterTrig04()
        {
            //test
            //trignomatery
            string         expression           = " sin(tan(cos(1.0472)))";
            Parser         parser               = new Parser();
            List <string>  parsedValues         = parser.parse(expression);
            RPNInterpreter RPN                  = new RPNInterpreter();
            double         result               = RPN.compute(parsedValues);
            Boolean        boolx                = false;
            double         acceptableDifference = 0.1;

            if (Math.Abs(result - 0.519) <= acceptableDifference)
            {
                boolx = true;
            }
            Assert.IsTrue(boolx);
        }
Beispiel #20
0
        public void RPNInterpreterTrig07()
        {
            //test
            //trignomatery
            string         expression           = " log(100+100) /25";
            Parser         parser               = new Parser();
            List <string>  parsedValues         = parser.parse(expression);
            RPNInterpreter RPN                  = new RPNInterpreter();
            double         result               = RPN.compute(parsedValues);
            Boolean        boolx                = false;
            double         acceptableDifference = 0.1;

            if (Math.Abs(result - 83.0539) <= acceptableDifference)
            {
                boolx = true;
            }
            //Assert.IsTrue(boolx);
            Assert.AreEqual(-0.817, result);
        }