示例#1
0
 public void SimpleAddition()
 {
     double value;
       _calculator = new Calc();
       _calculator.ParseString("1+1");
       value = _calculator.Result();
       Assert.AreEqual(value, (double)2);
 }
示例#2
0
 public void ComplexParen()
 {
     double value;
       _calculator = new Calc();
       _calculator.ParseString("2*(1+1)");
       value = _calculator.Result();
       Assert.AreEqual(value, (double)4);
 }
示例#3
0
 public void ParseStringWithSimpleParse()
 {
     double value;
       _calculator = new Calc();
       _calculator.ParseString("5 + ");
       _calculator.Parse("5");
       value = _calculator.Result();
       Assert.AreEqual(value, (double)10);
 }
示例#4
0
        static void Main(string[] args)
        {
            Calc _calculator = new Calc();
              string equation;
              double lastResult = 0;

              while (true)
              {
            Console.WriteLine("Input your equation.");
            equation = Console.ReadLine().Trim();
            if (!_calculator.Operators.ContainsKey(equation[0]))
              _calculator.Clear();
            _calculator.ParseString(equation);
            lastResult = _calculator.Result();
            Console.WriteLine("= " + lastResult.ToString());
              }
        }
示例#5
0
 public void NoOperatorParseString()
 {
     _calculator = new Calc();
       _calculator.ParseString("5 5");
       _calculator.Result();
 }