public void DeleteDeclarationCommand()
        {
            var precommands =
               new StringBuilder()
                   // зададим константы
                   .AppendLine("int zero")
                   .AppendLine("int one")
                   .AppendLine("one = 1")
                   .AppendLine("zero = 0")
                   .AppendLine("if zero then")
                   .AppendLine("one = 1")
                   .AppendLine("if one then")
                   .AppendLine("stop")
                   .AppendLine("endif")
                   .AppendLine("endif");

            var commands = new Parser().ProcessCommands(precommands.ToString()).ToArray();
            var newCommands = new DeleteCommandMutation(new SpecialRandom(1)).Transform(commands);
            Assert.AreEqual(newCommands.Length,5);

            Assert.AreEqual((newCommands[0] as NewInt).Name,"zero");
            Assert.AreEqual((newCommands[1] as SetValue).TargetName,"zero");
            Assert.AreEqual((newCommands[2] as Condition).ConditionName, "zero");
            Assert.IsTrue(newCommands[3] is Stop);
            Assert.IsTrue(newCommands[4] is CloseCondition);
        }
        public void DeclareFewInt()
        {
            var executor = new ValidationExecutor();
            var commands =
               new StringBuilder()
                   .AppendLine("int a")
                   .AppendLine("int a");

            var parsedcommands = new Parser().ProcessCommands(commands.ToString());
            Assert.IsFalse(executor.Execute(parsedcommands, new ExecutorToolset(new Random())));
        }
        public void InitNotDeclaredInt()
        {
            var executor = new ValidationExecutor();
            var commands =
                new StringBuilder()
                    .AppendLine("b = 1")
                    .AppendLine("if b then")
                    .AppendLine("stop")
                    .AppendLine("endif");

            var parsedcommands = new Parser().ProcessCommands(commands.ToString());
            Assert.IsFalse(executor.Execute(parsedcommands, new ExecutorToolset(new Random())));
        }
        public void LonelyEndIf()
        {
            var executor = new ValidationExecutor();
            var commands=
                new StringBuilder(@"
                    int a
                    endif
                    a = 1
                        ");

            var parsedcommands = new Parser().ProcessCommands(commands.ToString());

            Assert.IsFalse(executor.Execute(parsedcommands, new ExecutorToolset(new Random())));
        }
        public void ConditionIgnoreTest()
        {
            var executor = new ValidationExecutor();
            var commands =
               new StringBuilder()
                   .AppendLine("int b")
                   .AppendLine("b = -1")
                   .AppendLine("if b then")
                   .AppendLine("print a")
                   .AppendLine("endif");

            var parsedcommands = new Parser().ProcessCommands(commands.ToString());
            Assert.IsFalse(executor.Execute(parsedcommands, new ExecutorToolset(new Random())));
        }
        public void DeleteCloneValueSetterNotInit()
        {
            var precommands =
                new StringBuilder()
                    // зададим константы
                    .AppendLine("int zero")
                    .AppendLine("one = 1")
                    .AppendLine("zero = one")
                    .AppendLine("if zero then")
                    .AppendLine("stop")
                    .AppendLine("endif");

            var commands = new Parser().ProcessCommands(precommands.ToString()).ToArray();
            var newCommands = new DeleteCommandMutation(new SpecialRandom(1)).Transform(commands);
            Assert.AreEqual(newCommands.Length, 2);
            Assert.AreEqual((newCommands[0] as NewInt).Name, "zero");
            Assert.IsTrue(newCommands[1] is Stop);
        }
Beispiel #7
0
        protected void Check(string commands, IExecutorToolset executorToolset, params int[] values)
        {
            var parsedCommands = new Parser().ProcessCommands(commands).ToArray();
            var output =
                new Executor().Execute(parsedCommands, executorToolset)
                    .Replace("\r\n", "\n")
                    .Split('\n')
                    .Where(item => !string.IsNullOrEmpty(item))
                    .Select(int.Parse)
                    .ToList();

            Assert.AreEqual(values.Count(), output.Count());

            for (var i = 0; i < values.Count(); i++)
            {
                Assert.AreEqual(values[i], output[i]);
            }
        }
        public void DeleteEndIfWithNestedEndIf()
        {
            var precommands =
               new StringBuilder()
                   // зададим константы
                   .AppendLine("int zero")
                   .AppendLine("int one")
                   .AppendLine("one = 1")
                   .AppendLine("int two")
                   .AppendLine("zero = 0")
                   .AppendLine("two = 2")
                   .AppendLine("if zero then")
                   .AppendLine("one = 1")
                   .AppendLine("if one then")
                   .AppendLine("if two then")
                   .AppendLine("endif")
                   .AppendLine("stop")
                   .AppendLine("endif")
                   .AppendLine("endif");

            var commands = new Parser().ProcessCommands(precommands.ToString()).ToArray();
            var newCommands = new DeleteCommandMutation(new SpecialRandom(12)).Transform(commands);

            Assert.AreEqual(newCommands.Length, 12);
            Assert.AreEqual((newCommands[6] as Condition).ConditionName, "zero");
            Assert.AreEqual((newCommands[7] as SetValue).TargetName, "one");
            Assert.AreEqual((newCommands[8] as Condition).ConditionName, "two");
            Assert.IsTrue(newCommands[9] is CloseCondition);
            Assert.IsTrue(newCommands[10] is Stop);
            Assert.IsTrue(newCommands[11] is CloseCondition);
        }
        public void DeleteStop()
        {
            var precommands =
                new StringBuilder()
                    // зададим константы
                    .AppendLine("int zero")
                    .AppendLine("zero = 0")
                    .AppendLine("stop");

            var commands = new Parser().ProcessCommands(precommands.ToString()).ToArray();
            var newCommands = new DeleteCommandMutation(new SpecialRandom(2)).Transform(commands);
            Assert.AreEqual(newCommands.Length, 2);
            Assert.AreEqual((newCommands[0] as NewInt).Name, "zero");
            Assert.AreEqual((newCommands[1] as SetValue).TargetName,"zero");
        }
 public void DeleteSetterShouldNotDeleteDeclaration()
 {
     var precommands =
         new StringBuilder()
             // зададим константы
             .AppendLine("int zero")
             .AppendLine("int one")
             .AppendLine("one = 1")
             .AppendLine("zero = 0")
             .AppendLine("if zero then")
             .AppendLine("stop")
             .AppendLine("endif");
     var commands = new Parser().ProcessCommands(precommands.ToString()).ToArray();
     var newCommands = new DeleteCommandMutation(new SpecialRandom(2)).Transform(commands);
     Assert.AreEqual(newCommands.Length,6);
     Assert.AreEqual((newCommands[1] as NewInt).Name, "one");
     Assert.AreEqual((newCommands[2] as SetValue).TargetName, "zero");
 }
 public void DeleteNotInitializationSetter()
 {
     var precommands =
         new StringBuilder()
             // зададим константы
             .AppendLine("int zero")
             .AppendLine("zero = 0")
             .AppendLine("zero = 0")
             .AppendLine("if zero then")
             .AppendLine("stop")
             .AppendLine("endif");
     var commands = new Parser().ProcessCommands(precommands.ToString()).ToArray();
     var newCommands = new DeleteCommandMutation(new SpecialRandom(2)).Transform(commands);
     Assert.AreEqual(newCommands.Length, 5);
     Assert.AreEqual((newCommands[2] as Condition).ConditionName, "zero");
     Assert.AreEqual((newCommands[1] as SetValue).TargetName,"zero");
 }
        public void MinusUsingNotInitInt()
        {
            var executor = new ValidationExecutor();
            var commands =
                new StringBuilder()
                    .AppendLine("int b")
                    .AppendLine("b = 1")
                    .AppendLine("int a")
                    .AppendLine("int c")
                    .AppendLine("c = a - b");

            var parsedcommands = new Parser().ProcessCommands(commands.ToString());
            Assert.IsFalse(executor.Execute(parsedcommands, new ExecutorToolset(new Random())));
        }