예제 #1
0
        public StateType AddSimpleType(string id)
        {
            if(null != GetStateType(id))
            {
                throw new CompilerException(ErrorCode.TypeRedefinition, "type '" + id + "' is already defined.");
            }

            var stype = new SimpleStateType(id);
            _types[id] = stype;

            TraceVerbose("type '{0}' added.", id);

            return stype;
        }
예제 #2
0
        public void SMG_03_StateCondition()
        {
            TraceFlags.ShowDepencencyAnalysis = true;

            var sm = new StateMachine();
            var stype = new SimpleStateType("State");
            stype.AddStateNames(new[] { "A", "B", "C" });
            var s = sm.AddVariable("s", stype);
            var t = sm.AddVariable("t", stype);

            var c = new StateCondition(s);
            c.SetPreStates("A,B");
            c.SetPostStates("C");

            var e1 = sm.AddEvent("e1");

            var trigger = new Trigger(e1, c);
            sm.AddTrigger(trigger);

            var gc1 = new StateCondition(s);
            gc1.SetPreStates("A");
            // gc1.SetPostStates("C");
            sm.AddGuard(gc1, GuardType.LEAVE, "g1");

            var gc2 = new StateCondition(s);
            gc2.SetPreStates("C");
            sm.AddGuard(gc2, GuardType.ENTER, "g2");

            {
                var c1 = new StateCondition(t);
                c1.SetPreStates("A");

                var c2 = new StateCondition(s);
                c2.SetPreStates("A");
            }

            sm.Calculate();

            // sm.Dump();

            var e = sm.Events.First();
            Assert.AreEqual("e1", e.Name);
            Assert.AreEqual(2, e.Triggers.Count);

            var t1 = e.Triggers[0];
            var t2 = e.Triggers[1];

            Assert.AreEqual(2, t1.Guards.Count);
            Assert.AreEqual(1, t2.Guards.Count);

            Assert.IsTrue(t1.Guards.Any(g => g.Name == "g1"));
            Assert.IsTrue(t1.Guards.Any(g => g.Name == "g2"));
            Assert.IsTrue(t2.Guards.Any(g => g.Name == "g2"));
        }