예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your expression: ");
            var userInput = Console.ReadLine();

            while (!string.IsNullOrEmpty(userInput))
            {
                Console.WriteLine("Convert as reversed polish notation or as usual polish notation? (RPN/PN): ");
                switch (Console.ReadLine()?.ToLower())
                {
                case "rpn":
                {
                    try
                    {
                        Console.WriteLine($"Converted expression: \n{PolishNotationConverter.ConvertRpn(userInput)}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }

                    break;
                }

                case "pn":
                {
                    try
                    {
                        Console.WriteLine($"Converted expression: \n{PolishNotationConverter.ConvertPn(userInput)}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }

                    break;
                }

                default: Console.WriteLine("Invalid command."); break;
                }

                Console.WriteLine("Enter your expression: ");
                userInput = Console.ReadLine();
            }
        }
예제 #2
0
 public void ConvertToPolishNotationCorrectly(string expression, string expected) =>
 PolishNotationConverter.ConvertPn(expression).Should().Be(expected);
예제 #3
0
 public void ThrowOnInvalidBracketSequence(string invalidExpression)
 {
     Assert.Throws <InvalidExpressionException>(() => PolishNotationConverter.ConvertPn(invalidExpression));
 }
예제 #4
0
 public void BeAbleToConvertFunctions() =>
 PolishNotationConverter.ConvertPn("x ^ y / (-5 * z) + 10 + func(a, b, c) / 3")
 .Should().Be("+ + / ^ x y * -5 z 10 / func a b c 3");