예제 #1
0
        private static void CalculateReversePolishNotation()
        {
            // var input = "3, 4, 5, *, +"; // 23
            // var input = "4, 13, 5, /, +"; // 6
            // var input = "2, 1, +, 3, *"; // 9
            var input = "10, 6, 9, 3, +, -11, *, /, *, 17, +, 5, +"; // 22

            Console.WriteLine($"Input: {input}");

            var result = new ReversePolishNotationCalculator().CalculateReversePolishNotation(input);

            Console.WriteLine($"Reverse Polish notation calculation result: {string.Join(",", result)}");
        }
 public void ReversePolishNotationCalculatorTestCases()
 {
     Assert.That(ReversePolishNotationCalculator.Calc(new [] { "1", "2", "3", "*", "+", "2", "-" }), Is.EqualTo(5));
     Assert.That(ReversePolishNotationCalculator.Calc(new [] { "1", "0", "1", "0", "+", "+", "+" }), Is.EqualTo(2));
     Assert.That(ReversePolishNotationCalculator.Calc(new [] { "2", "5", "*", "6", "*", "10", "+" }), Is.EqualTo(70));
 }