예제 #1
0
        public void ImplicitSelectorUsedInAggregateConditionWithNot()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("if not all of the batteries ratio < 0.75 turn on the generators");

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

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

            Assert.AreEqual(UniOperand.NOT, variable.operand);
            Assert.IsTrue(variable.a is AggregateConditionVariable);
            AggregateConditionVariable condition = (AggregateConditionVariable)variable.a;

            Assert.IsTrue(condition.entityProvider is AllEntityProvider);
            Assert.AreEqual(Block.BATTERY, condition.entityProvider.GetBlockType());
            Assert.AreEqual(AggregationMode.ALL, 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 AssignSin()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("assign a to sin 1.5708");

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

            Assert.IsTrue(assignment.variable is UniOperandVariable);
            UniOperandVariable variable = (UniOperandVariable)assignment.variable;

            Assert.AreEqual(UniOperand.SIN, variable.operand);
            Assert.AreEqual(1f, CastNumber(variable.GetValue()).GetValue());
        }
        public void AssignACos()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("assign a to acos 1.5708");

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

            Assert.IsTrue(assignment.variable is UniOperandVariable);
            UniOperandVariable variable = (UniOperandVariable)assignment.variable;

            Assert.AreEqual(UniOperand.ACOS, variable.operand);
            Assert.AreEqual((float)Math.Acos(1.5708f), CastNumber(variable.GetValue()).GetValue());
        }
        public void AssignSquareRootValueVector()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("assign a to sqrt \"9:0:0\" + 2");

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

            Assert.IsTrue(assignment.variable is BiOperandVariable);
            BiOperandVariable variable = (BiOperandVariable)assignment.variable;

            Assert.AreEqual(BiOperand.ADD, variable.operand);
            Assert.IsTrue(variable.a is UniOperandVariable);
            UniOperandVariable operation = (UniOperandVariable)variable.a;

            Assert.AreEqual(UniOperand.SQRT, operation.operand);
            Assert.AreEqual(Return.VECTOR, operation.a.GetValue().GetPrimitiveType());
            Assert.AreEqual(Return.NUMERIC, variable.a.GetValue().GetPrimitiveType());
            Assert.AreEqual(5f, CastNumber(variable.GetValue()).GetValue());
        }