Ejemplo n.º 1
0
        public void ImplicitSelectorUsedInAggregateCondition()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("if any battery ratio < 0.75 turn on the generators");

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

            Assert.IsTrue(conditionalCommand.Condition is AggregateConditionVariable);
            AggregateConditionVariable condition = (AggregateConditionVariable)conditionalCommand.Condition;

            Assert.IsTrue(condition.entityProvider is AllEntityProvider);
            Assert.AreEqual(Block.BATTERY, condition.entityProvider.GetBlockType());
            Assert.AreEqual(AggregationMode.ANY, condition.aggregationMode);
            Assert.IsTrue(condition.blockCondition is BlockPropertyCondition);
            BlockPropertyCondition propertyCondition = (BlockPropertyCondition)condition.blockCondition;

            Assert.AreEqual(Property.RATIO + "", propertyCondition.property.propertyType());

            Assert.IsTrue(conditionalCommand.conditionMetCommand is BlockCommand);
            BlockCommand metCommand = (BlockCommand)conditionalCommand.conditionMetCommand;

            Assert.IsTrue(metCommand.entityProvider is AllEntityProvider);
            Assert.AreEqual(Block.GENERATOR, metCommand.entityProvider.GetBlockType());
        }
        public void AdditionUsedAsBlockConditionVariable()
        {
            var command = ParseCommand("if the \"rotor\" angle > {a} + 30 set the \"rotor\" angle to {a}");

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

            Assert.IsTrue(assignment.Condition is AggregateConditionVariable);
            AggregateConditionVariable condition = (AggregateConditionVariable)assignment.Condition;

            Assert.IsTrue(condition.blockCondition is BlockPropertyCondition);
            BlockPropertyCondition blockCondition = (BlockPropertyCondition)condition.blockCondition;

            Assert.IsTrue(blockCondition.comparisonValue is OperandVariable);
        }