public double parseProtocol(string line)
        {
            double firstValue  = double.MaxValue;
            double secondValue = double.MaxValue;
            double result      = double.MaxValue;

            string[] values = line.Split(':');
            if (values.Length != 3)
            {
                throw new Exception("No such a protocol exists");
            }
            try
            {
                firstValue  = Convert.ToDouble(values[1]);
                secondValue = Convert.ToDouble(values[2]);
            }
            catch (Exception)
            {
                throw new ArgumentException("Wrong arguments!!");
            }
            switch (values[0])
            {
            case "+":
                result = instance.Add(firstValue, secondValue);
                break;

            case "-":
                result = instance.Sub(firstValue, secondValue);
                break;

            case "/":
                result = instance.Div(firstValue, secondValue);
                break;

            case "*":
                result = instance.Mult(firstValue, secondValue);
                break;

            default:
                throw new ArgumentException("No such an operation");
            }
            return(result);
        }
Exemple #2
0
 public void DivTest()
 {
     Assert.AreEqual(1, _mathService.Div(1, 1));
     Assert.AreEqual(0, _mathService.Div(1, 2));
     Assert.AreEqual(1, _mathService.Div(2, 2));
 }