Ejemplo n.º 1
0
        public void CountOfListAsCondition()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("if count of shipRoute[] > 0 wait");

            Assert.IsTrue(command is ConditionalCommand);
            ConditionalCommand conditionalCommand = (ConditionalCommand)command;

            Assert.IsTrue(conditionalCommand.Condition is ComparisonVariable);
            ComparisonVariable comparison = (ComparisonVariable)conditionalCommand.Condition;

            Assert.IsTrue(comparison.a is ListAggregateVariable);
            ListAggregateVariable listAggregate = (ListAggregateVariable)comparison.a;

            Assert.AreEqual(PropertyAggregate.COUNT, listAggregate.aggregation);
            Assert.IsTrue(listAggregate.expectedList is ListIndexVariable);
            ListIndexVariable listIndex = (ListIndexVariable)listAggregate.expectedList;

            Assert.IsTrue(listIndex.expectedList is InMemoryVariable);
            InMemoryVariable listVariable = (InMemoryVariable)listIndex.expectedList;

            Assert.AreEqual("shipRoute", listVariable.variableName);
            Assert.IsTrue(comparison.b is StaticVariable);
            StaticVariable comparisonVariable = (StaticVariable)comparison.b;

            Assert.AreEqual(0f, comparisonVariable.GetValue().GetValue());
        }
Ejemplo n.º 2
0
        public void AssignVariableIndexToStaticList()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("assign myList[0] to [\"one\", \"two\", \"three\"]");

            Assert.IsTrue(command is ListVariableAssignmentCommand);
            ListVariableAssignmentCommand assignmentCommand = (ListVariableAssignmentCommand)command;

            Assert.IsTrue(assignmentCommand.list.expectedList is InMemoryVariable);
            InMemoryVariable listName = (InMemoryVariable)assignmentCommand.list.expectedList;

            Assert.AreEqual("myList", listName.variableName);
            List <Variable> listIndexes = CastList(assignmentCommand.list.index.GetValue()).GetTypedValue().GetValues();

            Assert.AreEqual(1, listIndexes.Count);
            Assert.AreEqual(0, CastNumber(listIndexes[0].GetValue()).GetTypedValue());
            Primitive list = assignmentCommand.value.GetValue();

            Assert.AreEqual(Return.LIST, list.GetPrimitiveType());
            List <Variable> listItems = CastList(list).GetTypedValue().GetValues();

            Assert.AreEqual(3, listItems.Count);
            Assert.AreEqual("one", CastString(listItems[0].GetValue()).GetTypedValue());
            Assert.AreEqual("two", CastString(listItems[1].GetValue()).GetTypedValue());
            Assert.AreEqual("three", CastString(listItems[2].GetValue()).GetTypedValue());
        }
        public void GetValue(int expected)
        {
            IConstant <int> variable = new InMemoryVariable <int>(expected);
            var             actual   = variable.GetValue();

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void GetValue_ObjectIsSameInstance()
        {
            var expected = new object();
            IConstant <object> variable = new InMemoryVariable <object>(expected);
            var actual = variable.GetValue();

            Assert.That(actual, Is.SameAs(expected));
        }
        public void SetValueMakesRoundTrip(int expected)
        {
            IVariable <int> variable = new InMemoryVariable <int>();

            variable.SetValue(expected);
            var actual = variable.GetValue();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void HaltsAfterFailure()
        {
            var n      = new InMemoryVariable <int>(0);
            var child  = new ReturnXNode(NodeStatus.FAILURE);
            var node   = new RetryNode(child, n);
            var status = node.Tick();

            Assert.That(status, Is.EqualTo(NodeStatus.FAILURE));
            Assert.That(child.Halts, Is.EqualTo(1));
        }
Ejemplo n.º 7
0
        public void ReturnsSuccessImmediately()
        {
            var n      = new InMemoryVariable <int>(0);
            var child  = new ReturnXNode(NodeStatus.SUCCESS);
            var node   = new RetryNode(child, n);
            var status = node.Tick();

            Assert.That(status, Is.EqualTo(NodeStatus.SUCCESS));
            Assert.That(child.Ticks, Is.EqualTo(1));
        }
Ejemplo n.º 8
0
        public void HaltsAfterSuccess()
        {
            var n      = new InMemoryVariable <int>(0);
            var child  = new ReturnXNode(NodeStatus.SUCCESS);
            var node   = new RetryNode(child, n);
            var status = node.Tick();

            Assert.That(status, Is.EqualTo(NodeStatus.SUCCESS));
            Assert.That(child.Halts, Is.EqualTo(1));
        }
Ejemplo n.º 9
0
        public void ReturnsFailureImmediately()
        {
            var n      = new InMemoryVariable <int>(0);
            var child  = new ReturnXNode(NodeStatus.FAILURE);
            var node   = new RepeatNode(child, n);
            var status = node.Tick();

            Assert.That(status, Is.EqualTo(NodeStatus.FAILURE));
            Assert.That(child.Ticks, Is.EqualTo(1));
        }
Ejemplo n.º 10
0
        public void SimpleVariableCondition()
        {
            var command = ParseCommand("if {a} set the \"rotors\" height to 5");

            Assert.IsTrue(command is ConditionalCommand);
            ConditionalCommand conditionalCommand = (ConditionalCommand)command;

            Assert.IsTrue(conditionalCommand.Condition is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)conditionalCommand.Condition;

            Assert.AreEqual("a", variable.variableName);
        }
        public void PrintCommandVariable()
        {
            var command = ParseCommand("print {a}");

            Assert.IsTrue(command is PrintCommand);
            PrintCommand printCommand = (PrintCommand)command;

            Assert.IsTrue(printCommand.variable is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)printCommand.variable;

            Assert.AreEqual("a", variable.variableName);
        }
        public void PrintCommandVariable()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("print {a}");

            Assert.IsTrue(command is PrintCommand);
            PrintCommand printCommand = (PrintCommand)command;

            Assert.IsTrue(printCommand.variable is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)printCommand.variable;

            Assert.AreEqual("a", variable.variableName);
        }
        public void AssignVariableCaseIsPreserved()
        {
            var command = ParseCommand("assign \"a\" to {variableName}");

            Assert.IsTrue(command is VariableAssignmentCommand);
            VariableAssignmentCommand assignCommand = (VariableAssignmentCommand)command;

            Assert.AreEqual("a", assignCommand.variableName);
            Assert.IsTrue(assignCommand.variable is InMemoryVariable);
            InMemoryVariable memoryVariable = (InMemoryVariable)assignCommand.variable;

            Assert.AreEqual("variableName", memoryVariable.variableName);
        }
        public void VariableSelector()
        {
            var command = ParseCommand("turn on the [a] sirens");

            Assert.IsTrue(command is BlockCommand);
            BlockCommand bc = (BlockCommand)command;

            Assert.IsTrue(bc.entityProvider is SelectorEntityProvider);
            SelectorEntityProvider sep = (SelectorEntityProvider)bc.entityProvider;

            Assert.IsTrue(sep.selector is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)sep.selector;

            Assert.AreEqual("a", variable.variableName);
            Assert.AreEqual(BlockType.SOUND, sep.blockType);
        }
        public void ImplicitVariableSelector()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("turn on the $a");

            Assert.IsTrue(command is BlockCommand);
            BlockCommand bc = (BlockCommand)command;

            Assert.IsTrue(bc.entityProvider is SelectorEntityProvider);
            SelectorEntityProvider sep = (SelectorEntityProvider)bc.entityProvider;

            Assert.IsTrue(sep.selector is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)sep.selector;

            Assert.AreEqual("a", variable.variableName);
        }
Ejemplo n.º 16
0
        public void AssignVariableIndexToVariable()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("assign myList[0] to \"value\"");

            Assert.IsTrue(command is ListVariableAssignmentCommand);
            ListVariableAssignmentCommand assignmentCommand = (ListVariableAssignmentCommand)command;

            Assert.IsTrue(assignmentCommand.list.expectedList is InMemoryVariable);
            InMemoryVariable listName = (InMemoryVariable)assignmentCommand.list.expectedList;

            Assert.AreEqual("myList", listName.variableName);
            List <Variable> listIndexes = CastList(assignmentCommand.list.index.GetValue()).GetTypedValue().GetValues();

            Assert.AreEqual(1, listIndexes.Count);
            Assert.AreEqual(0, CastNumber(listIndexes[0].GetValue()).GetTypedValue());
            Primitive value = assignmentCommand.value.GetValue();

            Assert.AreEqual("value", CastString(value).GetTypedValue());
        }
        public void VariableSelectorWithIndex()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("turn on the $mySirens[0]");

            Assert.IsTrue(command is BlockCommand);
            BlockCommand bc = (BlockCommand)command;

            Assert.IsTrue(bc.entityProvider is IndexEntityProvider);
            IndexEntityProvider iep         = (IndexEntityProvider)bc.entityProvider;
            List <Variable>     listIndexes = CastList(iep.index.GetValue()).GetTypedValue().GetValues();

            Assert.AreEqual(1, listIndexes.Count);
            Assert.AreEqual(0f, listIndexes[0].GetValue().GetValue());
            Assert.IsTrue(iep.provider is SelectorEntityProvider);
            SelectorEntityProvider variableSelector = (SelectorEntityProvider)iep.provider;

            Assert.IsTrue(variableSelector.selector is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)variableSelector.selector;
        }
Ejemplo n.º 18
0
        public void AssignListAtIndexValuesToAnotherList()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("assign myList[1, 2, 3] to [0]");

            Assert.IsTrue(command is ListVariableAssignmentCommand);
            ListVariableAssignmentCommand assignmentCommand = (ListVariableAssignmentCommand)command;

            Assert.IsTrue(assignmentCommand.list.expectedList is InMemoryVariable);
            InMemoryVariable listName = (InMemoryVariable)assignmentCommand.list.expectedList;

            Assert.AreEqual("myList", listName.variableName);
            List <Variable> listIndexes = CastList(assignmentCommand.list.index.GetValue()).GetTypedValue().GetValues();

            Assert.AreEqual(3, listIndexes.Count);
            Assert.AreEqual(1, CastNumber(listIndexes[0].GetValue()).GetTypedValue());
            Assert.AreEqual(2, CastNumber(listIndexes[1].GetValue()).GetTypedValue());
            Assert.AreEqual(3, CastNumber(listIndexes[2].GetValue()).GetTypedValue());
            List <Variable> assignedValue = CastList(assignmentCommand.value.GetValue()).GetTypedValue().GetValues();

            Assert.AreEqual(1, assignedValue.Count);
            Assert.AreEqual(0f, assignedValue[0].GetValue().GetValue());
        }