Ejemplo n.º 1
0
        public void TestMethod1()
        {
            var expression1 = ToyExpressionParser.ParseExpression("1.5 + 2");
            var expression2 = ToyExpressionParser.ParseExpression("  (1.5+2)  ");

            Assert.AreEqual("(1.5 + 2)", expression1.ToString());
            Assert.AreEqual("(1.5 + 2)", expression2.ToString());
        }
Ejemplo n.º 2
0
        public void TestMethod4()
        {
            var expression = ToyExpressionParser.ParseExpression(" - (- 2) ");

            Assert.AreEqual("2", expression.Reduce(null).ToString());

            expression = ToyExpressionParser.ParseExpression(" + (+ 2) ");
            Assert.AreEqual("2", expression.Reduce(null).ToString());
        }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     while (true)
     {
         Console.Write("<<< ");
         var input = Console.ReadLine();
         try
         {
             var expression = ToyExpressionParser.ParseExpression(input);
             Console.Write(">>> ");
             Console.WriteLine(expression.Reduce(null));
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
         Console.WriteLine();
     }
 }
Ejemplo n.º 4
0
        public void TestMethod3()
        {
            var expression = ToyExpressionParser.ParseExpression("(.5 + 1 - 2)*(-2)");

            Assert.AreEqual("1", expression.Reduce(null).ToString());
        }
Ejemplo n.º 5
0
        public void TestMethod2()
        {
            var expression = ToyExpressionParser.ParseExpression("1*2+3/4");

            Assert.AreEqual("((1 * 2) + (3 / 4))", expression.ToString());
        }