コード例 #1
0
        public void SumPositiveAndNegativeInteger()
        {
            var rpn    = parser.Parse("1+(-6)");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(-5));
        }
コード例 #2
0
        public void SubtractionDouble()
        {
            var rpn    = parser.Parse("5.1-8.2");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(3.1));
        }
コード例 #3
0
        public void FactorialInteger()
        {
            var rpn    = parser.Parse("6!");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(720));
        }
コード例 #4
0
        public void SubtractionInteger()
        {
            var rpn    = parser.Parse("6-4");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(2));
        }
コード例 #5
0
        public void CompoundExpression2Double()
        {
            var rpn    = parser.Parse("9/6/2/10");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(0.075));
        }
コード例 #6
0
        public void CompoundDegreeDouble()
        {
            var rpn    = parser.Parse("2.5^1.8^1.1");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(5.7498521724779302));
        }
コード例 #7
0
        public void CompoundExpressionDouble()
        {
            var rpn    = parser.Parse("-2.8+7.1-5.9+(7.4+8)*(9.2^7*(5.1-3+Foo(-10))-4.123)+45.2378+(-2.321)+((4.908)^(1)*(6)-(2)+(9))");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(-215233591));
        }
コード例 #8
0
        public void ParenthesisDouble()
        {
            var rpn    = parser.Parse("(6.0+4.3)*5.2");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(53.56));
        }
コード例 #9
0
        public void MultiplySumInteger()
        {
            var rpn    = parser.Parse("6+4*5");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(26));
        }
コード例 #10
0
        public void OneNegativeDouble()
        {
            var rpn    = parser.Parse("-6.1");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(-6.1));
        }
コード例 #11
0
        public void SumDouble()
        {
            var rpn    = parser.Parse("6.356+4.9");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(11.256));
        }
コード例 #12
0
        public void CompoundExpression4Integer()
        {
            var rpn    = parser.Parse("-2+7-5+(7+8)*(9^7*(5-3+Foo(-10))-4)");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(-215233665));
        }
コード例 #13
0
        public void OneInteger()
        {
            var rpn    = parser.Parse("6");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(6));
        }
コード例 #14
0
        public void CompoundExpressionInteger()
        {
            var rpn    = parser.Parse("-2+7-5+(7+8)*(9^7*(5-3+Foo(-10))-4)+45+(-2)+((4)^(1)*(6)-(2)+(9))");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(-215233591));
        }
コード例 #15
0
        public void CompoundExpression3Integer()
        {
            var rpn    = parser.Parse("((4)^(1)*(6)-(2)+(9))");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(31));
        }
コード例 #16
0
        public void CompoundDegreeInteger()
        {
            var rpn    = parser.Parse("2^3^4");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(2417851639229258349412352.0));
        }
コード例 #17
0
        public void UserFunctionInteger()
        {
            var rpn    = parser.Parse("6+Foo(5)");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(16));
        }
コード例 #18
0
        public void ParenthesisInteger()
        {
            var rpn    = parser.Parse("(6+4)*5");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(50));
        }
コード例 #19
0
        public void CompoundExpression3Double()
        {
            var rpn    = parser.Parse("9/(6*5+4)/2/10");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(0.0132352941176471));
        }
コード例 #20
0
        public void MultiplySumDouble()
        {
            var rpn    = parser.Parse("6.0+4.3*5.2");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(28.36));
        }
コード例 #21
0
        public void OneDouble()
        {
            var rpn    = parser.Parse("6.4");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(6.4));
        }
コード例 #22
0
        public void SumPositiveAndNegativeDouble()
        {
            var rpn    = parser.Parse("1.3+(-6.4)");
            var result = RPNCalculator.Calculate(rpn);

            Assert.AreEqual(0, result.CompareTo(-5.1));
        }
コード例 #23
0
        public void MultiplicationCalculationGivesRightResults()
        {
            var values        = new string[] { "2", "3", "*" };
            var rpnCalculator = new RPNCalculator(values);

            var result = rpnCalculator.Calculate();

            Assert.AreEqual(result, 6);
        }
コード例 #24
0
        public void PercentageCalculationGivesRightResults()
        {
            var values        = new string[] { "2", "%" };
            var rpnCalculator = new RPNCalculator(values);

            var result = rpnCalculator.Calculate();

            Assert.AreEqual(result, decimal.Parse(0.02.ToString()));
        }
コード例 #25
0
        public void FactorialCalculationGivesRightResults()
        {
            var values        = new string[] { "4", "!" };
            var rpnCalculator = new RPNCalculator(values);

            var result = rpnCalculator.Calculate();

            Assert.AreEqual(result, 24);
        }
コード例 #26
0
        public void DivisionCalculationGivesRightResults()
        {
            var values        = new string[] { "2", "3", "/" };
            var rpnCalculator = new RPNCalculator(values);

            var result = rpnCalculator.Calculate();

            Assert.AreEqual(result, decimal.Parse(1.5.ToString()));
        }
コード例 #27
0
        public void DecimalCalculationGivesRightResults()
        {
            var values        = new string[] { "2.5", "3.5", "+" };
            var rpnCalculator = new RPNCalculator(values);

            var result = rpnCalculator.Calculate();

            Assert.AreEqual(result, 6);
        }
コード例 #28
0
        public void CalculateTest()
        {
            Assert.AreEqual(RPNCalculator.Calculate("2 3 +"), 5);
            Assert.AreEqual(RPNCalculator.Calculate("5 4 *"), 20);
            Assert.AreEqual(RPNCalculator.Calculate("4 2 /"), 2);
            Assert.AreEqual(RPNCalculator.Calculate("11 3 -"), 8);
            Assert.AreEqual(RPNCalculator.Calculate("6 2 ^"), 36);

            Assert.AreEqual(RPNCalculator.Calculate("3 1 7 + *"), 24);
            Assert.AreEqual(RPNCalculator.Calculate("5 3 8 12 + * -"), -55);
            Assert.AreEqual(RPNCalculator.Calculate("4 2 + 9 *"), 54);
            Assert.AreEqual(RPNCalculator.Calculate("3 1 - 7 *"), 14);
        }
コード例 #29
0
        public void Calculate_TwoOperationsInsideWithSamePriorityBrackets_SholdReturnSuccess()
        {
            //arrange

            var    calculator  = new RPNCalculator();
            string input       = "4*(5+2-1)";
            var    rightAnswer = 24;

            //act
            var answer = calculator.Calculate(input);

            //assert
            double eps = 0.000001;

            Assert.True(Math.Abs(rightAnswer - answer) < eps);
        }
コード例 #30
0
        public void Calculate_TwoOperationsWithLargerPriorityInSecondOperation_SholdReturnSuccess()
        {
            //arrange

            var    calculator  = new RPNCalculator();
            string input       = "4+5*2";
            double rightAnswer = 14;

            //act
            var answer = calculator.Calculate(input);

            //assert
            double eps = 0.000001;

            Assert.True(Math.Abs(rightAnswer - answer) < eps);
        }