Exemplo n.º 1
0
        private void TestDirectInputNotAvailable()
        {
            //Arrange
            var variable = new CosmosVariable("#available", null);

            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    $"\n\t{variable.Name} = ##touche.disponible .\n");

            //Act
            interpreter.Execute().Should().BeTrue();

            //Assert
            parser.Variables[variable.Name].Value.Should().Be(false.AsCosmosBoolean());
        }
Exemplo n.º 2
0
        private void TestDirectInputEmpty()
        {
            //Arrange
            var variable = new CosmosVariable("#input", null);

            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    "\n\t#input = ##touche .\n" + BuildAfficherSnippet("touche:##touche"));

            //Act
            interpreter.Execute().Should().BeTrue();

            //Assert
            parser.Variables[variable.Name].Value.Should().BeNull();
            testConsole.Content.Should().Match("touche:<NÉANT>");
        }
Exemplo n.º 3
0
        private void TestInputGeneric(CosmosTypedValue expected)
        {
            //Arrange
            var variable = new CosmosVariable("#input", null);

            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    BuildInputSnippet(variable));
            testConsole.Input.Push($"{expected}");

            //Act
            interpreter.Execute();

            //Assert
            parser.Variables[variable.Name].Value.Should().Be(expected);
        }
Exemplo n.º 4
0
        public void TestStaticLoop5Times()
        {
            //Arrange
            var       varName    = "#counter";
            var       variable   = new CosmosVariable(varName, 0.AsCosmosNumber());
            const int iterations = 5;

            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    BuildStaticLoopSnippet(iterations, $"\t{varName} = {varName} +1."));

            //Act
            interpreter.Execute();

            //Assert
            parser.Variables.Should().ContainKey(varName).WhichValue.Value.Should().Be(5.AsCosmosNumber());
        }
Exemplo n.º 5
0
        protected string BuildAllocationSnippet(CosmosVariable variable)
        {
            string value = null;

            if (variable.Value != null)
            {
                value = variable.Value.ToString();
                //auto add string delimiters ""
                if (variable.Value.IsString)
                {
                    value = $"\"{value}\"";
                }
            }



            return(BuildAllocationSnippet(variable.Name, value));
        }
Exemplo n.º 6
0
        public void TestDynamicLoop2()
        {
            //Arrange
            var total      = 6.AsCosmosNumber();
            var varName    = "#counter";
            var variable   = new CosmosVariable(varName, 0.AsCosmosNumber());
            var iterations = new CosmosVariable($"#loops", total);

            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    BuildDynamicLoopSnippet(iterations, $"\t{varName} = {varName} +1.", 1) +
                                    BuildAfficherSnippet(varName));

            //Act
            interpreter.Execute();

            //Assert
            parser.Variables.Should().ContainKey(varName).WhichValue.Value.Should().BeEquivalentTo(total);
            testConsole.Content.Should().Be(total.ToString());
        }
Exemplo n.º 7
0
        private void TestDirectInputFilled()
        {
            //Arrange
            var variable = new CosmosVariable("#input", null);

            testConsole.Input.Push("A");
            testConsole.Input.Push("B");
            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    "\n\t#input = ##touche .\n" +
                                    BuildAfficherSnippet("#input") +
                                    BuildAfficherSnippet("##touche") +
                                    BuildAfficherSnippet("##touche"));

            //Act
            interpreter.Execute().Should().BeTrue();

            //Assert
            testConsole.Content.Should().Match("BA<NÉANT>");
        }
Exemplo n.º 8
0
        private void TestBoolean(string expression, bool expectedResult)
        {
            //Arrange
            var variable = new CosmosVariable($"#test", expectedResult.AsCosmosBoolean());

            BuildSnippetInterpreter(BuildAllocationSnippet(variable.Name, expression));

            //Act
            using (new AssertionScope())
            {
                interpreter.Execute().Should().BeTrue();
                parser.Errors.Should().BeEmpty();
            }


            //Assert
            parser.Variables.
            Should().ContainKey(variable.Name).
            WhichValue.Should().BeEquivalentTo(variable, expression + " should be " + expectedResult);
        }
Exemplo n.º 9
0
        protected string BuildDynamicLoopSnippet(CosmosVariable iterations, string content, int version = 0)
        {
            var result = new StringBuilder();

            result.Append(BuildAllocationSnippet(iterations));
            result.Append(Repeter);
            if (version == 0)
            {
                result.Append($"le nombre de fois correspondant à la valeur enregistrée dans la zone mémoire {iterations.Name}\n");
            }
            else if (version == 1)
            {
                result.Append($"autant de fois qu'il y a de {iterations.Name}\n");
            }

            result.Append("\t" + content);
            result.Append($"\n\t>>\n");

            return(result.ToString());
        }
Exemplo n.º 10
0
        private void TestFakeReadKey()
        {
            //Arrange
            var variable = new CosmosVariable("#press", null);

            //testConsole.Input.Push("A");
            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    $"\n\tAttendre la prochaine touche et la stocker dans {variable.Name} .\n");

            //Act
            new Thread(() =>
            {
                Thread.Sleep(800);
                testConsole.Input.Push("A");
            }).Start();
            interpreter.Execute().Should().BeTrue();

            //Assert
            parser.Variables[variable.Name].Value.Should().Be("A".AsCosmosString());
        }
Exemplo n.º 11
0
        public void TestWhileLoopVariableBoolExpression()
        {
            //Arrange
            const string printedResult = "1";
            var          condition     = true.AsCosmosBoolean();
            var          varName       = "#condition";
            var          variable      = new CosmosVariable(varName, condition);

            BuildSnippetInterpreter(BuildAllocationSnippet(variable) +
                                    BuildWhileLoopSnippet(varName,
                                                          $"\t\t{varName}={!condition}.\n" +
                                                          $"\t{BuildAfficherSnippet(printedResult)}") +
                                    BuildAfficherSnippet(varName));

            //Act
            interpreter.Execute();

            //Assert
            parser.Variables.Should().ContainKey(varName).WhichValue.Value.Should().BeEquivalentTo(!condition);
            testConsole.Content.Should().Be(printedResult + false.AsCosmosBoolean());
        }
Exemplo n.º 12
0
 public EmptyVariableException(CosmosVariable variable, Cosmos.VariableContext variableContext) :
     base(variableContext, $"La variable {variable.Name} n'a pas de valeur définie")
 {
 }
Exemplo n.º 13
0
 protected string BuildInputSnippet(CosmosVariable destination)
 {
     return($"\tRécupérer la saisie et la stocker dans la zone mémoire nommée {destination.Name}.\n");
 }