public static Operation CreateOperate(OperationType type) { Operation oper = null; switch (type) { case OperationType.ADD: oper = new OperationAdd(); break; case OperationType.SUB: oper = new OperationSub(); break; case OperationType.MUL: oper = new OperationMul(); break; case OperationType.DIV: oper = new OperationDiv(); break; } return(oper); }
public static Operation createOperate(string operate) { Operation opera = null; switch (operate) { case "+": { opera = new OperationAdd(); } break; case "-": { opera = new OperationSub(); } break; case "*": { opera = new OperationMul(); } break; case "/": { opera = new OperationDiv(); } break; default: break; } return(opera); }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { double num1 = 0; double num2 = 0; Operator _OP = null; if (!double.TryParse(TB_Number1.Text, out num1)) { MessageBox.Show("Input Error Number1 :" + TB_Number1.Text, "錯誤"); return; } if (!double.TryParse(TB_Number2.Text, out num2)) { MessageBox.Show("Input Error Number2 :" + TB_Number2.Text, "錯誤"); return; } string _Operators = Operators.Text; if (_Operators.Trim() == "") { MessageBox.Show("Select Error Operators :" + Operators.Text, "錯誤"); return; } else { if (_Operators == "+") { _OP = new OperationAdd(); } else if (_Operators == "-") { _OP = new OperationSub(); } else if (_Operators == "*") { _OP = new OperationMul(); } else if (_Operators == "/") { _OP = new OperationDiv(); } } _OP.NumberA = num1; _OP.NumberB = num2; double result = _OP.GetResult(); Result_Cal.Text = result.ToString(); } catch (Exception ex) { MessageBox.Show("The ex is: " + ex.ToString()); } }
/** * @param operation * @return */ public static Operation createOperation(string operation) { // TODO implement here Operation oper = null; if (operation == "+") { oper = new OperationAdd(); } return(oper); }
public void GetResultTest(double numberA, double numberB, double result) { OperationAdd add = new OperationAdd(); add.NumberA = numberA; add.NumberB = numberB; //var add = new Mock<OperationAdd>(); //add.Setup(a => a.NumberA).Returns(numberA); //add.Setup(a => a.NumberB).Returns(numberB); Assert.Equal(add.GetResult(), result); }
public void TripplePushAndPops() { Operation op1 = new OperationAdd(); op1.SetLeft(new Operand(1)); op1.SetRight(new Operand(1)); Operation op2 = new OperationSubtract(); op2.SetLeft(new Operand(1)); op2.SetRight(new Operand(1)); stack.Push(op1); stack.Push(op2); Assert.AreEqual(0, stack.Pop().GetValue().Result()); Assert.AreEqual(2, stack.Pop().GetValue().Result()); }
/// <summary> /// 返回具体运算类实例 /// SimpleFactory.CreateOperation() /// </summary> /// <param name="opt">+、-、*、/</param> /// <returns></returns> public static Operation CreateOperation(string opt) { Operation operate = null; switch (opt) { case "+": case "加": operate = new OperationAdd(); break; case "-": operate = new OperationSub(); break; } return(operate); }
public static Operation createOperate(string operate) { Operation oper = null; if (operate == "+"){ oper = new OperationAdd(); } else if (operate == "-"){ oper = new OperationSub(); } else if (operate == "*"){ oper = new OperationMul(); } else if (operate == "/"){ oper = new OperationDiv(); } return oper; }
public static Operation CreateOperation(double operationOne, double operationTwo, string operate) { Operation operation = null; switch (operate) { case "+": operation = new OperationAdd(operationOne, operationTwo, operate); break; case "-": operation = new OperationSubtract(operationOne, operationTwo, operate); break; case "*": operation = new OperationMulitply(operationOne, operationTwo, operate); break; case "/": operation = new OperationDivide(operationOne, operationTwo, operate); break; default: Console.WriteLine("非简单运算符"); break; } return operation; }
//工厂:顾名思义,生产对象 //根据传入的参数,判断选择生成相应的对象 public static Operation CreateOperate(string operate) { Operation ope = null; switch (operate) { case "+": ope = new OperationAdd(); break; case "-": ope = new OperationSub(); break; default: break; } return(ope); }
public static Operation CreationOperation(string operate) { Operation oper = null; switch (operate) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return oper; }
public static Operation createOperation(string operation) { Operation oper = null; switch (operation) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; case "SquareRoot": oper = new OperationSquareRoot(); break; case ".": oper = new OperationPoint(); break; case "+/-": oper = new OperationPosAndNeg(); break; default: break; } return(oper); }
public static Operation createOperate(string operate) { Operation oper = null; if (operate == "+") { oper = new OperationAdd(); } else if (operate == "-") { oper = new OperationSub(); } else if (operate == "*") { oper = new OperationMul(); } else if (operate == "/") { oper = new OperationDiv(); } return(oper); }
public static Operation GetOperation(string operate) { Operation operation = null; switch (operate) { case "+": operation = new OperationAdd(); break; case "-": operation = new OperationSub(); break; case "*": operation = new OperationMul(); break; case "/": operation = new OperationDiv(); break; } return(operation); }
public static Operation createOperator(string inputOperator) { Operation oper = null; switch (inputOperator) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return(oper); }
public static MyOperation createOperate(string operate) { MyOperation oper = null; switch (operate) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return(oper); }