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); }
static void Main(string[] args) { var input = Console.ReadLine(); while (input != "exit") { var op5 = new PowerOperation(); var op4 = new DivideOperation(op5); var op3 = new MultiplyOperation(op4); var op2 = new SubstractOperation(op3); var op1 = new AddOperation(op2); Command command; try { command = new Command(input); } catch (Exception e) { Console.WriteLine(e); throw; } var result = op1.Calculate(command); Console.Write(result == null ? $"Operation {command.Operation} is not supported" : $"{command} = {result} \n"); input = Console.ReadLine(); } }
/// <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 void AddOpp() { var t = new Table(); var reader = new TestReader(null, new Record(1, 2, 3, 4, 5, 6, 7)); var add = new AddOperation(t, reader); add.Execute(); Assert.AreEqual(1, t.Count); Assert.AreEqual(new Record(1, 2, 3, 4, 5, 6, 7), t[1]); reader = new TestReader(null, new Record("abc", "def", 11, 12, 13, 14, 15)); add = new AddOperation(t, reader); add.Execute(); Assert.AreEqual(2, t.Count); Assert.AreEqual(new Record(1, 2, 3, 4, 5, 6, 7), t[1]); Assert.AreEqual(new Record("abc", "def", 11, 12, 13, 14, 15), t[2]); // TODO: Check hints sent to reader reader = new TestReader(1, new Record("x", "y", "z", 100, 101, 102, 103, "www")); add = new AddOperation(t, reader); add.Execute(); Assert.AreEqual(3, t.Count); Assert.AreEqual(new Record(1, 2, 3, 4, 5, 6, 7), t[1]); Assert.AreEqual(new Record("x", "y", "z", 100, 101, 102, 103, "www"), t[2]); Assert.AreEqual(new Record("abc", "def", 11, 12, 13, 14, 15), t[3]); }
public void Solutions_DivideOperator_Test() { //Try to represent the equation ((5+1) x 3) - 4 IEquation node1 = new AddOperation(new Integer(5), new Integer(1)); IEquation node2 = new MultiplyOperation(node1, new Integer(3)); IEquation equation1 = new MinusOperation(node2, new Integer(4)); //Try to represent the equation 1 + 2 +3 IEquation node3 = new AddOperation(new Integer(1), new Integer(2)); IEquation equation2 = new AddOperation(node3, new Integer(3)); Solutions solutions = new Solutions(); solutions.Add(equation1); solutions.Add(equation2); IEquation equation3 = new Integer(14); Solutions new_solutions = solutions / equation3; Assert.AreEqual(2, new_solutions.Count); Assert.AreEqual(1, new_solutions[0].Value); Assert.AreEqual((decimal)6 / (decimal)14, new_solutions[1].Value); new_solutions = solutions / new Integer(3); Assert.AreEqual(2, new_solutions.Count); Assert.AreEqual((decimal)14 / (decimal)3, new_solutions[0].Value); Assert.AreEqual(2, new_solutions[1].Value); }
private void StartSubMenuSelectEmployeeOper(AddOperation addOperation) { var workData = GetWorkData(addOperation); switch (addOperation) { case AddOperation.AddDirector: Director addDirector = new Director(workData.name, workData.monthSalary, workData.bonus, workData.position); directorRepository.AddEmployee <Director>(addDirector, Settings.directorsFile); ShowDirectorMenu(); break; case AddOperation.AddProger: Proger addProger = new Proger(workData.name, workData.monthSalary, workData.position); directorRepository.AddEmployee <Proger>(addProger, Settings.progersFile); ShowDirectorMenu(); break; case AddOperation.AddFreelancer: Freelancer addFreelancer = new Freelancer(workData.name, workData.monthSalary, workData.position); directorRepository.AddEmployee <Freelancer>(addFreelancer, Settings.freelancerFile); ShowDirectorMenu(); break; default: ShowDirectorMenu(); break; } }
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); }
void IAssetMenuOperations.Add() { List <string> selectedPaths = GetSelectedPaths.ForOperation( mAssetSelection, mAssetStatusCache, AssetMenuOperations.Add); if (mIsGluonMode) { GluonAddoperation.Add( mViewHost, mProgressControls, mGuiMessage, selectedPaths.ToArray(), false, RefreshAsset.VersionControlCache); return; } AddOperation.Run( mWorkspaceWindow, mProgressControls, null, null, selectedPaths, false, mNewIncomingChangesUpdater, RefreshAsset.VersionControlCache); }
public void LHOPerationRHDouble() { Operation lh = new AddOperation(7, 11); Operation op = new AddOperation(lh, 13); Assert.AreEqual(31, op.Evaluate()); }
public void LHDoubleRHOperation() { Operation rh = new AddOperation(7, 11); Operation op = new AddOperation(13, rh); Assert.AreEqual(31, op.Evaluate()); }
private IOperation GetOperationByName(string name) { IOperation operation = null; switch (name) { case "+": operation = new AddOperation(); break; case "-": operation = new SubOperation(); break; case "*": operation = new MultiOperation(); break; case "/": operation = new DivisionOperation(); break; case "^": operation = new ExpOperation(); break; default: break; } return(operation); }
public void AddOperation_Test() { AddOperation op = new AddOperation(new Integer(2), new Integer(4)); Assert.AreEqual(6, op.Value); Assert.AreEqual("2 + 4", op.ToString()); }
public override IBuildIntention <IAddOperation> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = AddOperation.Create(); return(new BuildIntention <IAddOperation>(toBuild, () => { maker.Build(Left.GetOrThrow().ConvertElementOrThrow(context), Right.GetOrThrow().ConvertElementOrThrow(context)); })); }
public void TwoOperations() { Operation lh = new AddOperation(7, 11); Operation rh = new AddOperation(13, 19); Operation op = new AddOperation(lh, rh); Assert.AreEqual(50, op.Evaluate()); }
public void AddNumbers() { AddOperation op = AddOperation.Instance; Assert.AreEqual(1 + 2, op.Apply(1, 2)); Assert.AreEqual(1.2 + 3.4, op.Apply(1.2, 3.4)); Assert.AreEqual(1 + 2.3, op.Apply(1, 2.3)); Assert.AreEqual(1.2 + 3, op.Apply(1.2, 3)); }
public Closoure() { var xKey = new NameKey("x"); var x = MemberDefinition.CreateAndBuild(xKey, new NumberType(), false); var yKey = new NameKey("y"); var y = MemberDefinition.CreateAndBuild(yKey, new NumberType(), false); var methodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> { new Scope.IsStatic(x, false) }); var innerMethodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> { new Scope.IsStatic(y, false) }, methodScope); Module = ModuleDefinition.CreateAndBuild( Scope.CreateAndBuild( new List <Scope.IsStatic>() { new Scope.IsStatic(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), false), false) }), new[] { AssignOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), MethodType.CreateAndBuild( new NumberType(), new NumberType()), x, methodScope, new ICodeElement[] { ReturnOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), new NumberType(), y, innerMethodScope, new ICodeElement[] { AssignOperation.CreateAndBuild( AddOperation.CreateAndBuild( MemberReference.CreateAndBuild(x), MemberReference.CreateAndBuild(y)), MemberReference.CreateAndBuild(x)), ReturnOperation.CreateAndBuild( MemberReference.CreateAndBuild(x)) }, new ICodeElement[0], false) ) }, new ICodeElement[0], false), MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), false))) }, new NameKey("closoure")); }
private HlslTreeNode CreateDotProduct2AddNode(Instruction instruction) { var vector1 = GetInputComponents(instruction, 1, 2); var vector2 = GetInputComponents(instruction, 2, 2); var add = GetInputComponents(instruction, 3, 1)[0]; var dp2 = new AddOperation( new MultiplyOperation(vector1[0], vector2[0]), new MultiplyOperation(vector1[1], vector2[1])); return(new AddOperation(dp2, add)); }
public void Equation_Test2() { //Try to represent the equation 1 + 2 -3 IEquation node1 = new AddOperation(new Integer(1), new Integer(2)); Assert.AreEqual(3, node1.Value); AddOperation equation = new AddOperation(node1, new Integer(3)); Assert.AreEqual(6, equation.Value); Assert.AreEqual("1 + 2 + 3", equation.ToString()); }
static UserRightsCollection() { Rights = new List <IRight>(); Add = new AddOperation(); Rights.Add(Add); Delete = new DeleteOperation(); Rights.Add(Delete); View = new ViewOperation(); Rights.Add(View); Admin = new AdminRight(); Rights.Add(Admin); }
public static void Main(string[] args) { AddOperation add = new AddOperation(); var addResult = add.Execute(2, 5); SubstractOperation subsctract = new SubstractOperation(); var substractResult = subsctract.Execute(5, 2); Console.WriteLine($"Add result: {addResult}"); Console.WriteLine($"Substract result: {substractResult}"); Console.ReadKey(); }
public void CalculateTest() { var operation = new AddOperation { A = 2, B = 4 }; operation.Calculate(); Assert.IsTrue(operation.Result != null); Assert.IsTrue(operation.Result.Value == 6); }
public override HlslTreeNode Reduce() { Factor1.Outputs.Remove(this); Factor2.Outputs.Remove(this); var multiplication = new MultiplyOperation(Factor1, Factor2); var addition = new AddOperation(multiplication, Addend); Replace(addition); return(addition.Reduce()); }
public void AddOperation_Calculate_Success() { var operation = new AddOperation(); var input = new OperationInput <int>() { Num1 = 1, Num2 = 3 }; var output = operation.Do(input); Assert.IsNotNull(output); Assert.IsInstanceOfType(output, typeof(OperationOutput <int>)); Assert.AreEqual(((OperationOutput <int>)output).Result, 4); }
protected override bool _Evaluate(out double deltaTime, out double deltaPenalty) { // Pick random order: int ind = StaticRandom.Next(0, State.UnScheduledOrders.Count); // Evaluate the addition: addOp = new AddOperation(State, ind); bool possible = addOp.Evaluate(); deltaTime = addOp.DeltaTime; deltaPenalty = addOp.DeltaPenalty; return(possible); }
public Closoure() { var xKey = new NameKey("x"); var x = MemberDefinition.CreateAndBuild(xKey, new NumberType(), Access.ReadWrite); var yKey = new NameKey("y"); var y = MemberDefinition.CreateAndBuild(yKey, new NumberType(), Access.ReadWrite); var methodScope = Scope.CreateAndBuild(new List <IsStatic> { new IsStatic(x, false) }); var innerMethodScope = Scope.CreateAndBuild(new List <IsStatic> { new IsStatic(y, false) }); RootScope = Model.Instantiated.RootScope.CreateAndBuild( Scope.CreateAndBuild( new List <IsStatic>() { new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), Access.ReadWrite), false) }), new [] { AssignOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( MethodType.CreateAndBuild( new NumberType(), new NumberType()), x, methodScope, new ICodeElement[] { ReturnOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), y, innerMethodScope, new ICodeElement[] { AssignOperation.CreateAndBuild( AddOperation.CreateAndBuild( MemberReference.CreateAndBuild(x), MemberReference.CreateAndBuild(y)), MemberReference.CreateAndBuild(x)), ReturnOperation.CreateAndBuild(MemberReference.CreateAndBuild(x)) }, Array.Empty <ICodeElement>()) ) }, Array.Empty <ICodeElement>()), MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), Access.ReadWrite))) }, EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>())); }
private Task <Cart> BuildCartAsync(XDocument XMLDocument, List <Rules> Rules, List <Models.Inventory> ItemsInventory) { Cart Cart = new Cart(); try { Cart.AddedInventory = new List <Models.Inventory>(); var InventoryItems = Request.Cookies["InventoryItems"]; if (InventoryItems != null) { var ItemCodes = InventoryItems.Value.Split(new string[] { "+" }, StringSplitOptions.None); foreach (var item in ItemCodes) { var Inventory = Fleets.Line.Helpers.Inventory.GetInventoryItem(XMLDocument, item); if (!Cart.AddedInventory.Any(x => x.ProductId.ToUpper() == item.ToUpper())) { if (Inventory != null) { Cart.AddedInventory.Add(Inventory); } } else { Cart.AddedInventory.Where(x => x.ProductId.ToUpper() == item.ToUpper()).ToList().ForEach(s => s.Quantity += 1); } } //Add promotion rules Dictionary <string, string> PromotionRules = new Dictionary <string, string>(); foreach (var rule in Rules) { PromotionRules.Add(rule.Key, rule.Value); } //Call promotion operations AddOperation Operations = new AddOperation(); var InventoryScales = Operations.ApplyScale(ItemsInventory, InventoryItems.Value); if (InventoryScales.Any()) { var InventoryRules = Operations.ApplyRules(ItemsInventory, InventoryItems.Value, PromotionRules, InventoryScales); Cart.OperationResult = InventoryRules; } } } catch (Exception ex) { throw ex; } return(Task.FromResult(Cart)); }
/// <summary> /// Adds the specified aggregate. /// </summary> /// <param name="aggregate">The aggregate.</param> public void Add(T aggregate) { var op = new AddOperation(_domains, aggregate, _logger); var tx = Transaction.Current; if (tx == null) { op.OnCommit(); } else { tx.EnlistVolatile(op, EnlistmentOptions.None); } }
public void ResetOperations() { if (AddOperation != null) { AddOperation.ResetEvents(); } AddOperation = null; if (RemoveOperation != null) { RemoveOperation.ResetEvents(); } RemoveOperation = null; SearchOperation = null; }
public void Equation_Test1() { //Try to represent the equation ((5+1) x 3) - 4 IEquation node1 = new AddOperation(new Integer(5), new Integer(1)); Assert.AreEqual(6, node1.Value); MultiplyOperation node2 = new MultiplyOperation(node1, new Integer(3)); Assert.AreEqual(18, node2.Value); MinusOperation equation = new MinusOperation(node2, new Integer(4)); Assert.AreEqual(14, equation.Value); Assert.AreEqual("((5 + 1) x 3) - 4", equation.ToString()); }
public void Equation_Test3() { //Try to represent the equation ((6 / 3) + 2) x 5 IEquation node1 = new DivideOperation(new Integer(6), new Integer(3)); Assert.AreEqual(2, node1.Value); IEquation node2 = new AddOperation(node1, new Integer(2)); Assert.AreEqual(4, node2.Value); IEquation equation = new MultiplyOperation(node2, new Integer(5)); Assert.AreEqual(20, equation.Value); Assert.AreEqual("((6 / 3) + 2) x 5", equation.ToString()); }