public void Accept(Minus command) { var comparableCommand = _second as Minus; _isEqual = command.TargetName == comparableCommand.TargetName && command.FirstSource == comparableCommand.FirstSource && command.SecondSource == comparableCommand.SecondSource; }
public void Accept(Minus command) { if (!_conditions.Peek()) return; var firstValue = _variables[command.FirstSource]; var secondValue = _variables[command.SecondSource]; _variables[command.TargetName] = firstValue - secondValue; }
public void Accept(Minus 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(Minus command) { _builder.AppendLine($"{command.TargetName} = {command.FirstSource} - {command.SecondSource}"); }
private AddCommandMutation GetMutationForMinus(ICommandsList commands, Minus 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.TuneMinus(targetDeclarationIndex, firstSourceDeclarationIndex, secondSourceDeclarationIndex, indexToAdd); return new AddCommandMutation(random, commands); }
public void AddMinus() { const string code = @"int ione ione = 5 int itwo itwo = 2 int three int four int five"; const int indexToAdd = 6; var commandToAdd = new Minus("four", "ione", "itwo"); var commands = GenerateCommands(code); var mutation = GetMutationForMinus(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 GetMutationForMinus(ICommandsList commands, int replaceIndex, Minus command) { var random = new ReplaceRandom(); var targetDeclarationIndex = GetDeclarationIndexOfVariable(command.TargetName, commands); var firstSourceDeclarationIndex = GetDeclarationIndexOfVariable(command.FirstSource, commands); var secondSourceDeclarationIndex = GetDeclarationIndexOfVariable(command.SecondSource, commands); random.TuneMinus(replaceIndex, targetDeclarationIndex, firstSourceDeclarationIndex, secondSourceDeclarationIndex); return new ReplaceCommandMutation(random, commands); }
public void ReplaceMinus() { 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 Minus("ithree", "itwo", "ione"); var commands = GenerateCommands(code); var mutation = GetMutationForMinus(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)); }