public static GenericOperation CreateOperation(string oprator) { GenericOperation operation = null; switch (oprator) { case "+": operation = new AddOperation(); break; case "-": operation = new SubOperation(); break; case "*": operation = new MulOperation(); break; case "/": operation = new DivOperation(); break; default: throw new System.ArgumentException(string.Format("{0} operation is not defined.", oprator)); // break; } return(operation); }
/// <summary> /// 实例化方法 /// </summary> /// <param name="sign">运算符</param> /// <returns>返回运算法则</returns> public static Operation CreateOperation(string sign) { Operation opera = null; switch (sign) { case "+": opera = new AddOperation(); break; case "-": opera = new SubOperation(); break; case "*": opera = new MulOperation(); break; case "/": opera = new DivOperation(); break; default: throw new System.Exception("暂未添加此功能!"); } return(opera); }
public static Operation CreateOperation(string strOp) { Operation op; switch (strOp) { case "+": op = new AddOperation(); break; case "-": op = new SubOperation(); break; case "*": op = new MulOperation(); break; case "/": op = new DivOperation(); break; case "%": op = new ModuloOperation(); break; default: return(null); } return(op); }
public void CalculateTest() { var operation = new DivOperation { A = 2, B = 8 }; operation.Calculate(); Assert.IsTrue(operation.Result != null); Assert.IsTrue(operation.Result.Value == 0.25); }
public void ZeroDevisionTest() { try { var operation = new DivOperation { A = 2, B = 0 }; operation.Calculate(); throw new AssertFailedException("Деление на ноль невозможно"); } catch (ArgumentException) { } }
private IMSILConstruction CreateDivOperation(IASTNode node) { var divOperator = new DivOperation(); return(divOperator); }