Exemplo n.º 1
0
        public void TestCollectionConcatenation()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace n1 = CreateNameSpace(test, "N1");
            Collection c1 = CreateCollection(n1, "C", "Integer", 10 );
            Variable v1 = CreateVariable(n1, "V1", "C");
            Variable v2 = CreateVariable(n1, "V2", "C");
            Variable v3 = CreateVariable(n1, "V3", "C");

            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action a1 = CreateAction(rc1, "V1 <- [1, 2, 3] + [4, 5, 6]");
            Action a2 = CreateAction(rc1, "V2 <- [] + [4, 5, 6]");
            Action a3 = CreateAction(rc1, "V3 <- [1, 2, 3] + []");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);
            runner.Cycle();

            {
                ListValue value = v1.Value as ListValue;
                Assert.IsNotNull(value);
                Assert.AreEqual(6, value.Val.Count);
            }
            {
                ListValue value = v2.Value as ListValue;
                Assert.IsNotNull(value);
                Assert.AreEqual(3, value.Val.Count);
            }
            {
                ListValue value = v3.Value as ListValue;
                Assert.IsNotNull(value);
                Assert.AreEqual(3, value.Val.Count);
            }
        }
        public void TestCollectionConcatenation()
        {
            Dictionary dictionary = CreateDictionary("Test");
            NameSpace nameSpace = CreateNameSpace(dictionary, "NameSpace");

            Structure structure = CreateStructure(nameSpace, "ModelElement");
            StructureElement structElem = CreateStructureElement(structure, "Value", "Boolean");
            structElem.setDefault("True");

            Collection collection = CreateCollection(nameSpace, "Coll", "ModelElement", 10);
            collection.Type = structure;
            collection.setMaxSize(3);
            collection.Default = "[]";

            Variable variable = CreateVariable(nameSpace, "V", "Coll");

            RuleCondition ruleCondition = CreateRuleAndCondition(nameSpace, "Test");
            Action action = CreateAction(ruleCondition, "V <- V + [ModelElement{Value => True}] ");

            RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary);
            visitor.visit(nameSpace);

            Util.IsThereAnyError isThereAnyError = new Util.IsThereAnyError();
            Assert.AreEqual(0, isThereAnyError.ErrorsFound.Count);
            Assert.AreEqual("[]", variable.Value.LiteralName);

            Runner runner = new Runner(false);
            runner.Cycle();
            Assert.AreEqual("[" + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName);

            runner.Cycle();
            Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName);

            runner.Cycle();
            Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName);

            // In this case, the new collection cannot be placed in the variable
            runner.Cycle();
            Assert.AreEqual(1, action.Messages.Count);
            Assert.AreEqual(ElementLog.LevelEnum.Error, action.Messages[0].Level);
        }
        public void TestUncacheFunctionBasedOnInnerFunctionCall()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace n1 = CreateNameSpace(test, "N1");
            Collection c = CreateCollection(n1, "C", "Integer", 10);
            Variable a = CreateVariable(n1, "a", "C");
            a.setDefaultValue("[1]");
            Variable b = CreateVariable(n1, "b", "C");
            b.setDefaultValue("[10]");

            Function f = CreateFunction(n1, "f", "C");
            Case always_f = CreateCase(f, "Always", "g() + h()");

            Function g = CreateFunction(n1, "g", "C");
            Case always_g = CreateCase(g, "Always", "a");

            Function h = CreateFunction(n1, "h", "C");
            Case always_h = CreateCase(h, "Always", "b");

            RuleCondition updateGlobalVariables = CreateRuleAndCondition(n1, "Update Global variables");
            Action act1 = CreateAction(updateGlobalVariables, "a <- a + [2]");
            Action act2 = CreateAction(updateGlobalVariables, "b <- b + [20]");

            Compiler.Compile_Synchronous(true);

            Expression expression = new Parser().Expression(test, "N1.f()");
            ListValue value = expression.GetExpressionValue(new InterpretationContext(), null) as ListValue;

            Assert.IsNotNull(value);
            Assert.AreEqual(2, value.Val.Count);

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);
            runner.CheckForCompatibleChanges = true;
            runner.Cycle();

            value = expression.GetExpressionValue(new InterpretationContext(), null) as ListValue;

            Assert.IsNotNull(value);
            Assert.AreEqual(4, value.Val.Count);
        }
Exemplo n.º 4
0
        public void TestRefactorStructureName()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace n1 = CreateNameSpace(test, "N1");
            Collection collection = CreateCollection(n1, "Col", "Integer", 10);
            Variable v = CreateVariable(n1, "V", "Col");
            v.setDefaultValue("[]");
            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action a1 = CreateAction(rc1, "INSERT 1 IN V");
            RuleCondition rc2 = CreateRuleAndCondition(n1, "Rule2");
            Action a2 = CreateAction(rc2, "INSERT 2 IN V");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);
            runner.CheckForCompatibleChanges = true;
            runner.Cycle();

            ListValue listValue = v.Value as ListValue;
            Assert.IsNotNull(listValue);
            Assert.AreEqual(2, listValue.Val.Count);
            Assert.AreEqual(0, a1.Messages.Count);
            Assert.AreEqual(0, a2.Messages.Count);
        }
Exemplo n.º 5
0
        public void TestStabilize()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace n1 = CreateNameSpace(test, "N1");
            Variable v1 = CreateVariable(n1, "V", "Double");
            v1.setDefaultValue("0.0");

            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action a1 = CreateAction(rc1, "V <- STABILIZE (LAST v IN VALUES) / 2.0 INITIAL_VALUE 100.0 STOP_CONDITION  PREVIOUS - CURRENT < 10.0 ");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);
            runner.Cycle();

            DoubleValue value = v1.Value as DoubleValue;
            Assert.IsNotNull(value);
            Assert.AreEqual(6.25, value.Val);
        }
Exemplo n.º 6
0
        public void TestSubRulesPriority()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace n1 = CreateNameSpace(test, "N1");
            Variable v1 = CreateVariable(n1, "V", "Integer");
            v1.setDefaultValue("0");
            Variable v2 = CreateVariable(n1, "V2", "Integer");
            v2.setDefaultValue("0");
            // Priority is Processing
            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action a1 = CreateAction(rc1, "V2 <- V2 + 1");
            // Priority is Update out
            RuleCondition rc2 = CreateRuleAndCondition(rc1, "Rule2");
            rc2.EnclosingRule.setPriority(acceptor.RulePriority.aUpdateOUT);
            Action a2 = CreateAction(rc2, "V <- V + 1");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);
            runner.Cycle();

            IntValue value = v1.Value as IntValue;
            Assert.IsNotNull(value);
            Assert.AreEqual(1, value.Val);

            value = v2.Value as IntValue;
            Assert.IsNotNull(value);
            Assert.AreEqual(1, value.Val);
        }
        public void TestUncacheFunctionOfFunction()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace n1 = CreateNameSpace(test, "N1");

            Variable v = CreateVariable(n1, "Var", "Boolean");
            v.setDefaultValue("True");

            Function F1 = CreateFunction(n1, "FunOfVar", "Integer");
            Case cas1_1 = CreateCase(F1, "Var is true", "1", "Var");
            Case cas1_2 = CreateCase(F1, "Var is false", "2");

            Function F2 = CreateFunction(n1, "FunOfFun", "Boolean");
            Case cas2_1 = CreateCase(F2, "Value", "FunOfVar() == 2");

            RuleCondition rc = CreateRuleAndCondition(n1, "Rule1");
            Action a = CreateAction(rc, "Var <- False");

            Compiler.Compile_Synchronous(true);

            Expression expression = new Parser().Expression(test, "N1.FunOfFun()");
            IValue value = expression.GetExpressionValue(new InterpretationContext(), null);

            Assert.AreEqual(value, System.BoolType.False);

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);
            runner.CheckForCompatibleChanges = true;
            runner.Cycle();

            value = expression.GetExpressionValue(new InterpretationContext(), null);

            Assert.AreEqual(value, System.BoolType.True);
        }