Exemplo n.º 1
0
        public void Test_Printing_Instructions_For_Long_Expressions()
        {
            var expression   = new MathExpression("7/2+14*9-5-15*500");
            var instructions = new StringBuilder();

            instructions.AppendLine("PUSH 7");
            instructions.AppendLine("PUSH 2");
            instructions.AppendLine("DIVIDE");
            instructions.AppendLine("PUSH 14");
            instructions.AppendLine("ADD");
            instructions.AppendLine("PUSH 9");
            instructions.AppendLine("MULTIPLY");
            instructions.AppendLine("PUSH 5");
            instructions.AppendLine("SUBTRACT");
            instructions.AppendLine("PUSH 15");
            instructions.AppendLine("SUBTRACT");
            instructions.AppendLine("PUSH 500");
            instructions.AppendLine("MULTIPLY");
            instructions.AppendLine("PRINT");

            StringAssert.AreEqualIgnoringCase(
                expression.createProgramInstructions().ToString(),
                instructions.ToString()
                );
        }
Exemplo n.º 2
0
        public void Test_Printing_Instructions_For_Single_Value()
        {
            var expression   = new MathExpression("13");
            var instructions = new StringBuilder();

            instructions.AppendLine("PUSH 13");
            instructions.AppendLine("PRINT");

            StringAssert.AreEqualIgnoringCase(
                expression.createProgramInstructions().ToString(),
                instructions.ToString()
                );
        }
 static void Main(string[] args)
 {
     Console.WriteLine("Welcome");
     while (true)
     {
         Console.WriteLine("Enter your math expressions:");
         string         expressionText = Console.ReadLine();
         MathExpression expression;
         try
         {
             expression = new MathExpression(expressionText);
             Console.WriteLine(expression.createProgramInstructions());
         }
         catch (Exception)
         {
             Console.WriteLine("Invalid Expression");
         }
     }
 }