public void Accept(Plus command) { var comparableCommand = _second as Plus; _isEqual = command.TargetName == comparableCommand.TargetName && command.FirstSource == comparableCommand.FirstSource && command.SecondSource == comparableCommand.SecondSource; }
public void Accept(Plus command) { if (!_conditions.Peek()) return; var firstValue = _variables[command.FirstSource]; var secondValue = _variables[command.SecondSource]; _variables[command.TargetName] = firstValue + secondValue; }
public void Accept(Plus command) { if (!_variables.ContainsKey(command.FirstSource) || !_variables.ContainsKey(command.SecondSource) || !_variables.ContainsKey(command.TargetName) || _variables[command.FirstSource]==null || _variables[command.SecondSource]==null) { _isExecutable = false; return; } var firstValue = _variables[command.FirstSource]; var secondValue = _variables[command.SecondSource]; _variables[command.TargetName] = firstValue + secondValue; }
public void Accept(Plus command) { _builder.AppendLine($"{command.TargetName} = {command.FirstSource} + {command.SecondSource}"); }
private AddCommandMutation GetMutationForPlus(ICommandsList commands, Plus command, int indexToAdd) { var random = new AddRandom(); var targetDeclarationIndex = GetDeclarationIndexOfVariable(command.TargetName, commands); var firstSourceDeclarationIndex = GetDeclarationIndexOfVariable(command.FirstSource, commands); var secondSourceDeclarationIndex = GetDeclarationIndexOfVariable(command.SecondSource, commands); random.TunePlus(targetDeclarationIndex, firstSourceDeclarationIndex, secondSourceDeclarationIndex, indexToAdd); return new AddCommandMutation(random, commands); }
public void AddPlus() { const string code = @"int ione ione = 5 int itwo itwo = 2 int three int four int five"; const int indexToAdd = 6; var commandToAdd = new Plus("four", "ione", "itwo"); var commands = GenerateCommands(code); var mutation = GetMutationForPlus(commands, commandToAdd, indexToAdd); mutation.Transform(); const string resultCode = @"int ione ione = 5 int itwo itwo = 2 int three int four four = ione + itwo int five"; var resultCommands = GenerateCommands(resultCode); Assert.IsTrue(AreCollectionsEquals(commands, resultCommands)); }
private ReplaceCommandMutation GetMutationForPlus(ICommandsList commands, int replaceIndex, Plus command) { var random = new ReplaceRandom(); var targetDeclarationIndex = GetDeclarationIndexOfVariable(command.TargetName, commands); var firstSourceDeclarationIndex = GetDeclarationIndexOfVariable(command.FirstSource, commands); var secondSourceDeclarationIndex = GetDeclarationIndexOfVariable(command.SecondSource, commands); random.TunePlus(replaceIndex, targetDeclarationIndex, firstSourceDeclarationIndex, secondSourceDeclarationIndex); return new ReplaceCommandMutation(random, commands); }
public void ReplacePlus() { const string code = @"int ione ione = 5 int itwo itwo = 2 int ithree ithree = ione itwo = ithree + ione"; const int indexToReplace = 6; var commandToReplace = new Plus("ithree", "itwo", "ione"); var commands = GenerateCommands(code); var mutation = GetMutationForPlus(commands, indexToReplace, commandToReplace); mutation.Transform(); const string resultCode = @"int ione ione = 5 int itwo itwo = 2 int ithree ithree = ione ithree = itwo + ione"; var resultCommands = GenerateCommands(resultCode); Assert.IsTrue(AreCollectionsEquals(commands, resultCommands)); }