Inheritance: ICommandSetter
Esempio n. 1
0
        public void AddGetRandom()
        {
            const string code = @"int ione
                                  ione = 5
                                  int itwo
                                  itwo = 2
                                  int three
                                  int four
                                  int five";
            const int indexToAdd = 6;
            var commandToAdd = new GetRandom("three", "itwo");
            var commands = GenerateCommands(code);
            var mutation = GetMutationForGetRandom(commands, commandToAdd, indexToAdd);

            mutation.Transform();

            const string resultCode = @"int ione
                                        ione = 5
                                        int itwo
                                        itwo = 2
                                        int three
                                        int four
                                        three = random itwo
                                        int five";
            var resultCommands = GenerateCommands(resultCode);
            Assert.IsTrue(AreCollectionsEquals(commands, resultCommands));
        }
 public void Accept(GetRandom command)
 {
     _builder.AppendLine($"{command.TargetName} = random {command.MaxValueName}");
 }
Esempio n. 3
0
        public void Accept(GetRandom command)
        {
            if (!_conditions.Peek()) return;

            _variables[command.TargetName] = _executorToolset.GetRandom(_variables[command.MaxValueName].Value);
        }
Esempio n. 4
0
 private AddCommandMutation GetMutationForGetRandom(ICommandsList commands, GetRandom command, int indexToAdd)
 {
     var random = new AddRandom();
     var targetDeclarationIndex = GetDeclarationIndexOfVariable(command.TargetName, commands);
     var sourceDeclarationIndex = GetDeclarationIndexOfVariable(command.MaxValueName, commands);
     random.TuneGetRandom(targetDeclarationIndex, sourceDeclarationIndex, indexToAdd);
     return new AddCommandMutation(random, commands);
 }
 public void Accept(GetRandom command)
 {
     var comparableCommand = _second as GetRandom;
     _isEqual = command.TargetName == comparableCommand.TargetName &&
                command.MaxValueName == comparableCommand.MaxValueName;
 }
Esempio n. 6
0
 private ReplaceCommandMutation GetMutationForGetRandom(ICommandsList commands, int replaceIndex, GetRandom command)
 {
     var random = new ReplaceRandom();
     var targetDeclarationIndex = GetDeclarationIndexOfVariable(command.TargetName, commands);
     var sourceDeclarationIndex = GetDeclarationIndexOfVariable(command.MaxValueName, commands);
     random.TuneGetRandom(replaceIndex, targetDeclarationIndex, sourceDeclarationIndex);
     return new ReplaceCommandMutation(random, commands);
 }
Esempio n. 7
0
        public void ReplaceGetRandom()
        {
            const string code = @"int ione
                                  ione = 5
                                  int itwo
                                  itwo = 2
                                  int ithree
                                  ithree = ione
                                  itwo = random ione";
            const int indexToReplace = 6;
            var commandToReplace = new GetRandom("ithree", "ione");
            var commands = GenerateCommands(code);
            var mutation = GetMutationForGetRandom(commands, indexToReplace, commandToReplace);

            mutation.Transform();

            const string resultCode = @"int ione
                                        ione = 5
                                        int itwo
                                        itwo = 2
                                        int ithree
                                        ithree = ione
                                        ithree = random ione";
            var resultCommands = GenerateCommands(resultCode);
            Assert.IsTrue(AreCollectionsEquals(commands, resultCommands));
        }
Esempio n. 8
0
        public void Accept(GetRandom command)
        {
            if (!_variables.ContainsKey(command.TargetName) ||
                !_variables.ContainsKey(command.MaxValueName) ||
                _variables[command.MaxValueName] == null)
            {
                _isExecutable = false;
                return;
            }

            _variables[command.TargetName] = _executorToolset.GetRandom(_variables[command.MaxValueName].Value);
        }