Beispiel #1
0
        public static void Run()
        {
            var model = new StateMachine <Instance>("model");

            var initial = new PseudoState <Instance>("initial", model);

            var choice   = new PseudoState <Instance>("choice", model, PseudoStateKind.Choice);
            var junction = new PseudoState <Instance>("junction", model, PseudoStateKind.Junction);

            var finalState = new FinalState <Instance>("final", model);

            initial.To(choice);
            choice.To(junction).When(i => i.Int1 == 0).Effect(i => i.Int1 = 1);
            choice.To(finalState).Else();
            junction.To(choice).When(i => i.Int2 == 0).Effect(i => i.Int2 = 2);

            model.Validate();

            var instance = new Instance("else");

            model.Initialise(instance);

            Trace.Assert(model.IsComplete(instance));
            Trace.Assert(instance.Int1 == 1);
            Trace.Assert(instance.Int2 == 2);
        }
Beispiel #2
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");

			var initial = new PseudoState<Instance>("initial", model);

			var choice = new PseudoState<Instance>("choice", model, PseudoStateKind.Choice);
			var junction = new PseudoState<Instance>("junction", model, PseudoStateKind.Junction);

			var finalState = new FinalState<Instance>("final", model);

			initial.To(choice);
			choice.To(junction).When(i => i.Int1 == 0).Effect(i => i.Int1 = 1);
			choice.To(finalState).Else();
			junction.To(choice).When(i => i.Int2 == 0).Effect(i => i.Int2 = 2);

			model.Validate();

			var instance = new Instance("else");

			model.Initialise(instance);

			Trace.Assert(model.IsComplete(instance));
			Trace.Assert(instance.Int1 == 1);
			Trace.Assert(instance.Int2 == 2);
		}
Beispiel #3
0
        public static void Run()
        {
            var model     = new StateMachine <Instance>("model");
            var initial   = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var junction1 = new PseudoState <Instance>("junction1", model, PseudoStateKind.Junction);
            var junction2 = new PseudoState <Instance>("junction2", model, PseudoStateKind.Junction);

            var pass = new State <Instance>("success", model);
            var fail = new State <Instance>("error", model);

            initial.To(junction1);

            junction1.To(junction2).When(i => i.Int1 == 0).Effect(i => i.Int1++);
            junction1.To(fail).Else();
            junction2.To(pass).When(i => i.Int1 == 0).Effect(i => i.Int1++);
            junction2.To(fail).Else();

            model.Validate();

            var instance = new Instance("static");

            model.Initialise(instance);

            Trace.Assert(pass == instance.GetCurrent(model.DefaultRegion));

            Trace.Assert(2 == instance.Int1);
        }
Beispiel #4
0
		public static void Run () {

			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var junction1 = new PseudoState<Instance>("junction1", model, PseudoStateKind.Junction);
			var junction2 = new PseudoState<Instance>("junction2", model, PseudoStateKind.Junction);

			var pass = new State<Instance>("success", model);
			var fail = new State<Instance>("error", model);

			initial.To(junction1);

			junction1.To(junction2).When(i => i.Int1 == 0).Effect(i => i.Int1++);
			junction1.To(fail).Else();
			junction2.To(pass).When(i => i.Int1 == 0).Effect(i => i.Int1++);
			junction2.To(fail).Else();

			model.Validate();

			var instance = new Instance("static");

			model.Initialise(instance);

			Trace.Assert(pass == instance.GetCurrent(model.DefaultRegion));

			Trace.Assert(2 == instance.Int1);
		}
Beispiel #5
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var target = new State<Instance>("state", model).Entry(i => i.Int1++).Exit(i => i.Int2++);

			initial.To(target);

			target.To().When<string>(m => m == "internal").Effect(i => i.Int3++);
			target.To(target).When<string>(m => m == "external").Effect(i => i.Int3++);

			var instance = new Instance("internal");

			model.Validate();

			model.Initialise(instance);

			model.Evaluate(instance, "internal");

			Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
			Trace.Assert(1 == instance.Int1);
			Trace.Assert(0 == instance.Int2);
			Trace.Assert(1 == instance.Int3);

			model.Evaluate(instance, "external");

			Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
			Trace.Assert(2 == instance.Int1);
			Trace.Assert(1 == instance.Int2);
			Trace.Assert(2 == instance.Int3);
		}
Beispiel #6
0
		public static void Run () {
			var model = new StateMachine<Instance>("history");

			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var shallow = new State<Instance>("shallow", model);
			var deep = new State<Instance>("deep", model);
			var end = new FinalState<Instance>("final", model);

			var s1 = new State<Instance>("s1", shallow);
			var s2 = new State<Instance>("s2", shallow);

			initial.To(shallow);
			new PseudoState<Instance>("shallow", shallow, PseudoStateKind.ShallowHistory).To(s1);
			s1.To(s2).When<string>(c => c == "move");
			shallow.To(deep).When<string>(c => c == "go deep");
			deep.To(shallow).When<string>(c => c == "go shallow");
			s2.To(end).When<string>(c => c == "end");

			model.Validate();

			var instance = new Instance("history");

			model.Initialise(instance);

			model.Evaluate(instance, "move");
			model.Evaluate(instance, "go deep");
			model.Evaluate(instance, "go shallow");
			model.Evaluate(instance, "end");

			Trace.Assert(model.IsComplete(instance));
		}
Beispiel #7
0
        public static void Run()
        {
            var model   = new StateMachine <Instance>("compTest");
            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);

            var activity1 = new State <Instance>("activity1", model);
            var activity2 = new State <Instance>("activity2", model);
            var activity3 = new State <Instance>("activity3", model);
            var junction1 = new PseudoState <Instance>("junction1", model, PseudoStateKind.Junction);
            var junction2 = new PseudoState <Instance>("junction2", model, PseudoStateKind.Junction);
            var end       = new FinalState <Instance>("end", model);

            var subInitial = new PseudoState <Instance>("subInitial", activity2, PseudoStateKind.Initial);
            var subEnd     = new FinalState <Instance>("subEnd", activity2);

            subInitial.To(subEnd);
            initial.To(activity1);
            activity1.To(activity2);
            activity2.To(junction1);
            junction1.To(junction2).Else();
            junction2.To(activity3).Else();
            activity3.To(end);

            model.Validate();

            var instance = new Instance("transitions");

            model.Initialise(instance);

            Trace.Assert(model.IsComplete(instance));
        }
Beispiel #8
0
		public static void Run () {
			var model = new StateMachine<Instance>("compTest");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);

			var activity1 = new State<Instance>("activity1", model);
			var activity2 = new State<Instance>("activity2", model);
			var activity3 = new State<Instance>("activity3", model);
			var junction1 = new PseudoState<Instance>("junction1", model, PseudoStateKind.Junction);
			var junction2 = new PseudoState<Instance>("junction2", model, PseudoStateKind.Junction);
			var end = new FinalState<Instance>("end", model);

			var subInitial = new PseudoState<Instance>("subInitial", activity2, PseudoStateKind.Initial);
			var subEnd = new FinalState<Instance>("subEnd", activity2);

			subInitial.To(subEnd);
			initial.To(activity1);
			activity1.To(activity2);
			activity2.To(junction1);
			junction1.To(junction2).Else();
			junction2.To(activity3).Else();
			activity3.To(end);

			model.Validate();

			var instance = new Instance("transitions");
			model.Initialise(instance);

			Trace.Assert(model.IsComplete(instance));
		}
Beispiel #9
0
        public static void Run()
        {
            var model        = new StateMachine <Instance>("model");
            var initial1     = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var myComposite1 = new State <Instance>("composite1", model);
            var state3       = new State <Instance>("state3", model);
            var initial2     = new PseudoState <Instance>("initial", myComposite1, PseudoStateKind.Initial);
            var state1       = new State <Instance>("state1", myComposite1);
            var state2       = new State <Instance>("state2", myComposite1);

            initial1.To(myComposite1);
            initial2.To(state1);
            myComposite1.To(state3).When <string>(c => c == "a");
            state1.To(state2).When <string>(c => c == "a");

            model.Validate();

            var instance = new Instance("brice");

            model.Initialise(instance);

            model.Evaluate(instance, "a");

            Trace.Assert(instance.GetCurrent(myComposite1.DefaultRegion) == state2);
        }
Beispiel #10
0
        public static void Run()
        {
            var model   = new StateMachine <Instance>("model");
            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var target  = new State <Instance>("state", model).Entry(i => i.Int1++).Exit(i => i.Int2++);

            initial.To(target);

            target.To().When <string>(m => m == "internal").Effect(i => i.Int3++);
            target.To(target).When <string>(m => m == "external").Effect(i => i.Int3++);

            var instance = new Instance("internal");

            model.Validate();

            model.Initialise(instance);

            model.Evaluate(instance, "internal");

            Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
            Trace.Assert(1 == instance.Int1);
            Trace.Assert(0 == instance.Int2);
            Trace.Assert(1 == instance.Int3);

            model.Evaluate(instance, "external");

            Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
            Trace.Assert(2 == instance.Int1);
            Trace.Assert(1 == instance.Int2);
            Trace.Assert(2 == instance.Int3);
        }
Beispiel #11
0
        public static void Run()
        {
            var model = new StateMachine <Instance>("history");

            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var shallow = new State <Instance>("shallow", model);
            var deep    = new State <Instance>("deep", model);
            var end     = new FinalState <Instance>("final", model);

            var s1 = new State <Instance>("s1", shallow);
            var s2 = new State <Instance>("s2", shallow);

            initial.To(shallow);
            new PseudoState <Instance>("shallow", shallow, PseudoStateKind.ShallowHistory).To(s1);
            s1.To(s2).When <string>(c => c == "move");
            shallow.To(deep).When <string>(c => c == "go deep");
            deep.To(shallow).When <string>(c => c == "go shallow");
            s2.To(end).When <string>(c => c == "end");

            model.Validate();

            var instance = new Instance("history");

            model.Initialise(instance);

            model.Evaluate(instance, "move");
            model.Evaluate(instance, "go deep");
            model.Evaluate(instance, "go shallow");
            model.Evaluate(instance, "end");

            Trace.Assert(model.IsComplete(instance));
        }
Beispiel #12
0
		public static void Run () {

			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var stateA = new State<Instance>("stateA", model);
			var choice = new PseudoState<Instance>("choice", model, PseudoStateKind.Choice);

			initial.To(stateA);

			stateA.To(choice).When<string>(message => message == "choose");

			choice.To(stateA).Effect(instance => instance.Int1++);
			choice.To(stateA).Effect(instance => instance.Int2++);
			choice.To(stateA).Effect(instance => instance.Int3++);

			model.Validate();

			var instance1 = new Instance("instance1");

			model.Initialise(instance1);

			for (var i = 0; i < 99; i++) {
				model.Evaluate(instance1, "choose");
			}

			Trace.Assert(99 == (instance1.Int1 + instance1.Int2 + instance1.Int3));

			Runtime.Extensions.RandomSelector = randRobin;

			var instance2 = new Instance("instance2");

			model.Initialise(instance2);

			for (var i = 0; i < 99; i++) {
				model.Evaluate(instance2, "choose");
			}

			model.Evaluate(instance2, "end");

			Trace.Assert(33 == instance2.Int1);
			Trace.Assert(33 == instance2.Int2);
			Trace.Assert(33 == instance2.Int3);
		}
Beispiel #13
0
        public static void Run()
        {
            var model   = new StateMachine <Instance>("model");
            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var state1  = new State <Instance>("state1", model);
            var state2  = new State <Instance>("state2", model);

            var regionA  = new Region <Instance>("regionA", state1);
            var initialA = new PseudoState <Instance>("initialA", regionA, PseudoStateKind.Initial);
            var state3   = new State <Instance>("state3", regionA);
            var state8   = new State <Instance>("state8", regionA);

            var regionB  = new Region <Instance>("regionB", state1);
            var initialB = new PseudoState <Instance>("initialB", regionB, PseudoStateKind.Initial);
            var state4   = new State <Instance>("state4", regionB);
            var state5   = new State <Instance>("state5", regionB);

            var regionBa  = new Region <Instance>("regionBa", state4);
            var initialBa = new PseudoState <Instance>("initialBa", regionBa, PseudoStateKind.Initial);
            var state6    = new State <Instance>("state6", regionBa);

            var regionBb  = new Region <Instance>("regionBb", state4);
            var initialBb = new PseudoState <Instance>("initialBb", regionBb, PseudoStateKind.Initial);
            var state7    = new State <Instance>("state7", regionBb);

            initial.To(state1);
            initialA.To(state3);
            initialB.To(state4);
            initialBa.To(state6);
            initialBb.To(state7);

            state3.To(state2).When <string>(c => c == "event2");
            state3.To(state8).When <string>(c => c == "event1");
            state7.To(state5).When <string>(c => c == "event2");
            state7.To(state5).When <string>(c => c == "event1");

            model.Validate();

            var instance = new Instance("p3pp3r");

            model.Initialise(instance);

            model.Evaluate(instance, "event2");

            Trace.Assert(state2 == instance.GetCurrent(model.DefaultRegion), instance.GetCurrent(model.DefaultRegion).ToString());
            Trace.Assert(state4 == instance.GetCurrent(regionB));
        }
Beispiel #14
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var state1 = new State<Instance>("state1", model);
			var state2 = new State<Instance>("state2", model);

			var regionA = new Region<Instance>("regionA", state1);
			var initialA = new PseudoState<Instance>("initialA", regionA, PseudoStateKind.Initial);
			var state3 = new State<Instance>("state3", regionA);
			var state8 = new State<Instance>("state8", regionA);

			var regionB = new Region<Instance>("regionB", state1);
			var initialB = new PseudoState<Instance>("initialB", regionB, PseudoStateKind.Initial);
			var state4 = new State<Instance>("state4", regionB);
			var state5 = new State<Instance>("state5", regionB);

			var regionBa = new Region<Instance>("regionBa", state4);
			var initialBa = new PseudoState<Instance>("initialBa", regionBa, PseudoStateKind.Initial);
			var state6 = new State<Instance>("state6", regionBa);

			var regionBb = new Region<Instance>("regionBb", state4);
			var initialBb = new PseudoState<Instance>("initialBb", regionBb, PseudoStateKind.Initial);
			var state7 = new State<Instance>("state7", regionBb);

			initial.To(state1);
			initialA.To(state3);
			initialB.To(state4);
			initialBa.To(state6);
			initialBb.To(state7);

			state3.To(state2).When<string>(c => c == "event2");
			state3.To(state8).When<string>(c => c == "event1");
			state7.To(state5).When<string>(c => c == "event2");
			state7.To(state5).When<string>(c => c == "event1");

			model.Validate();

			var instance = new Instance("p3pp3r");
			model.Initialise(instance);

			model.Evaluate(instance, "event2");

			Trace.Assert(state2 == instance.GetCurrent(model.DefaultRegion), instance.GetCurrent(model.DefaultRegion).ToString() );
			Trace.Assert(state4 == instance.GetCurrent(regionB));
		}
Beispiel #15
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model);
			var stateA = new State<Instance>("stateA", model);
			var terminate = new PseudoState<Instance>("terminate", model, PseudoStateKind.Terminate);

			initial.To(stateA);
			stateA.To(terminate).When<string>(message => message == "1");

			model.Validate();

			var instance = new Instance("terminate");

			model.Initialise(instance);

			Trace.Assert(!model.Evaluate(instance, "2"));
			Trace.Assert(model.Evaluate(instance, "1"));
			Trace.Assert(!model.Evaluate(instance, "1"));
			Trace.Assert(instance.IsTerminated);
		}
Beispiel #16
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var stateA = new State<Instance>("stateA", model).Exit(i => i.Int1 += 1);
			var stateB = new State<Instance>("stateB", model).Entry(i => i.Int1 += 2);

			initial.To(stateA);
			stateA.To(stateB).When<string>(message => message == "move").Effect(i => i.Int1 += 4);

			model.Validate();

			var instance = new Instance("callbacks");

			model.Initialise(instance);

			model.Evaluate(instance, "move");

			Trace.Assert(1 == (1 & instance.Int1));
			Trace.Assert(2 == (2 & instance.Int1));
			Trace.Assert(4 == (4 & instance.Int1));
		}
Beispiel #17
0
        public static void Run()
        {
            var model     = new StateMachine <Instance>("model");
            var initial   = new PseudoState <Instance>("initial", model);
            var stateA    = new State <Instance>("stateA", model);
            var terminate = new PseudoState <Instance>("terminate", model, PseudoStateKind.Terminate);

            initial.To(stateA);
            stateA.To(terminate).When <string>(message => message == "1");

            model.Validate();

            var instance = new Instance("terminate");

            model.Initialise(instance);

            Trace.Assert(!model.Evaluate(instance, "2"));
            Trace.Assert(model.Evaluate(instance, "1"));
            Trace.Assert(!model.Evaluate(instance, "1"));
            Trace.Assert(instance.IsTerminated);
        }
Beispiel #18
0
        public static void Run()
        {
            // create the state machine model elements
            var model   = new StateMachine <Instance>("model");
            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var stateA  = new State <Instance>("stateA", model);
            var stateB  = new State <Instance>("stateB", model).Exit(i => i.Int1++);

            var bInitial = new PseudoState <Instance>("bInitial", stateB);
            var bStateI  = new State <Instance>("bStateI", stateB);
            var bStateII = new State <Instance>("bStateII", stateB);

            // create the state machine model transitions
            initial.To(stateA);
            stateA.To(stateB).When <string>(message => message == "move");

            bInitial.To(bStateI);

            stateB.To(bStateII, TransitionKind.Local).When <string>(message => message == "local");
            stateB.To(bStateII, TransitionKind.External).When <string>(message => message == "external");
            model.Validate();

            // create a state machine instance
            var instance = new Instance("local");

            // initialise the model and instance
            model.Initialise(instance);

            // send the machine instance a message for evaluation, this will trigger the transition from stateA to stateB
            model.Evaluate(instance, "move");

            model.Evaluate(instance, "local");

            Trace.Assert(0 == instance.Int1);

            model.Evaluate(instance, "external");

            Trace.Assert(1 == instance.Int1);
        }
Beispiel #19
0
        public static void Run()
        {
            var model   = new StateMachine <Instance>("model");
            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var stateA  = new State <Instance>("stateA", model).Exit(i => i.Int1 += 1);
            var stateB  = new State <Instance>("stateB", model).Entry(i => i.Int1 += 2);

            initial.To(stateA);
            stateA.To(stateB).When <string>(message => message == "move").Effect(i => i.Int1 += 4);

            model.Validate();

            var instance = new Instance("callbacks");

            model.Initialise(instance);

            model.Evaluate(instance, "move");

            Trace.Assert(1 == (1 & instance.Int1));
            Trace.Assert(2 == (2 & instance.Int1));
            Trace.Assert(4 == (4 & instance.Int1));
        }
Beispiel #20
0
		public static void Run () {
			// create the state machine model elements
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var stateA = new State<Instance>("stateA", model);
			var stateB = new State<Instance>("stateB", model).Exit(i => i.Int1++);

			var bInitial = new PseudoState<Instance>("bInitial", stateB);
			var bStateI = new State<Instance>("bStateI", stateB);
			var bStateII = new State<Instance>("bStateII", stateB);

			// create the state machine model transitions
			initial.To(stateA);
			stateA.To(stateB).When<string>(message => message == "move");

			bInitial.To(bStateI);

			stateB.To(bStateII, TransitionKind.Local).When<string>(message => message == "local");
			stateB.To(bStateII, TransitionKind.External).When<string>(message => message == "external");
			model.Validate();

			// create a state machine instance
			var instance = new Instance("local");

			// initialise the model and instance
			model.Initialise(instance);

			// send the machine instance a message for evaluation, this will trigger the transition from stateA to stateB
			model.Evaluate(instance, "move");

			model.Evaluate(instance, "local");

			Trace.Assert(0 == instance.Int1);

			model.Evaluate(instance, "external");

			Trace.Assert(1 == instance.Int1);
		}
Beispiel #21
0
		public static void Run () {

			var model = new StateMachine<Instance>("model");
			var initial1 = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var myComposite1 = new State<Instance>("composite1", model);
			var state3 = new State<Instance>("state3", model);
			var initial2 = new PseudoState<Instance>("initial", myComposite1, PseudoStateKind.Initial);
			var state1 = new State<Instance>("state1", myComposite1);
			var state2 = new State<Instance>("state2", myComposite1);

			initial1.To(myComposite1);
			initial2.To(state1);
			myComposite1.To(state3).When<string>(c => c == "a");
			state1.To(state2).When<string>(c => c == "a");

			model.Validate();

			var instance = new Instance("brice");
			model.Initialise(instance);

			model.Evaluate(instance, "a");

			Trace.Assert(instance.GetCurrent(myComposite1.DefaultRegion) == state2);
		}
Beispiel #22
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");

			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var ortho = new State<Instance>("ortho", model);
			var simple = new State<Instance>("simple", model);
			var final = new FinalState<Instance>("final", model);

			var r1 = new Region<Instance>("r1", ortho);
			var r2 = new Region<Instance>("r2", ortho);

			var i1 = new PseudoState<Instance>("initial", r1, PseudoStateKind.ShallowHistory);
			var i2 = new PseudoState<Instance>("initial", r2, PseudoStateKind.ShallowHistory);

			var s1 = new State<Instance>("s1", r1);
			var s2 = new State<Instance>("s2", r2);

			var f1 = new FinalState<Instance>("f1", r1);
			var f2 = new FinalState<Instance>("f2", r2);

			initial.To(ortho);

			i1.To(s1);
			i2.To(s2);

			ortho.To(final); // This should happen once all regions in ortho are complete?

			s1.To(f1).When<string>(c => c == "complete1");
			s2.To(f2).When<string>(c => c == "complete2");

			ortho.To(simple).When<string>(c => c == "jump");
			simple.To(ortho).When<string>(c => c == "back");

			model.Validate();

			var instance = new Instance("muximise");
			model.Initialise(instance);
			/*
console.log("simple.isSimple = " + simple.isSimple());
console.log("simple.isComposite = " + simple.isComposite());
console.log("simple.isOrthogonal = " + simple.isOrthogonal());

console.log("model.isSimple = " + model.isSimple());
console.log("model.isComposite = " + model.isComposite());
console.log("model.isOrthogonal = " + model.isOrthogonal());

console.log("ortho.isSimple = " + ortho.isSimple());
console.log("ortho.isComposite = " + ortho.isComposite());
console.log("ortho.isOrthogonal = " + ortho.isOrthogonal());
*/

			Trace.Assert(simple.IsSimple);
			Trace.Assert(!model.IsSimple);
			Trace.Assert(!ortho.IsSimple);

			Trace.Assert(!simple.IsComposite);
			Trace.Assert(model.IsComposite);
			Trace.Assert(ortho.IsComposite);

			Trace.Assert(!simple.IsOrthogonal);
			Trace.Assert(!model.IsOrthogonal);
			Trace.Assert(ortho.IsOrthogonal);

			model.Evaluate(instance, "complete1");
			model.Evaluate(instance, "complete2");

			Trace.Assert(model.IsComplete(instance));
		}
Beispiel #23
0
        public static void Run()
        {
            var model = new StateMachine <Instance>("model");

            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var ortho   = new State <Instance>("ortho", model);
            var simple  = new State <Instance>("simple", model);
            var final   = new FinalState <Instance>("final", model);

            var r1 = new Region <Instance>("r1", ortho);
            var r2 = new Region <Instance>("r2", ortho);

            var i1 = new PseudoState <Instance>("initial", r1, PseudoStateKind.ShallowHistory);
            var i2 = new PseudoState <Instance>("initial", r2, PseudoStateKind.ShallowHistory);

            var s1 = new State <Instance>("s1", r1);
            var s2 = new State <Instance>("s2", r2);

            var f1 = new FinalState <Instance>("f1", r1);
            var f2 = new FinalState <Instance>("f2", r2);

            initial.To(ortho);

            i1.To(s1);
            i2.To(s2);

            ortho.To(final);             // This should happen once all regions in ortho are complete?

            s1.To(f1).When <string>(c => c == "complete1");
            s2.To(f2).When <string>(c => c == "complete2");

            ortho.To(simple).When <string>(c => c == "jump");
            simple.To(ortho).When <string>(c => c == "back");

            model.Validate();

            var instance = new Instance("muximise");

            model.Initialise(instance);

            /*
             * console.log("simple.isSimple = " + simple.isSimple());
             * console.log("simple.isComposite = " + simple.isComposite());
             * console.log("simple.isOrthogonal = " + simple.isOrthogonal());
             *
             * console.log("model.isSimple = " + model.isSimple());
             * console.log("model.isComposite = " + model.isComposite());
             * console.log("model.isOrthogonal = " + model.isOrthogonal());
             *
             * console.log("ortho.isSimple = " + ortho.isSimple());
             * console.log("ortho.isComposite = " + ortho.isComposite());
             * console.log("ortho.isOrthogonal = " + ortho.isOrthogonal());
             */

            Trace.Assert(simple.IsSimple);
            Trace.Assert(!model.IsSimple);
            Trace.Assert(!ortho.IsSimple);

            Trace.Assert(!simple.IsComposite);
            Trace.Assert(model.IsComposite);
            Trace.Assert(ortho.IsComposite);

            Trace.Assert(!simple.IsOrthogonal);
            Trace.Assert(!model.IsOrthogonal);
            Trace.Assert(ortho.IsOrthogonal);

            model.Evaluate(instance, "complete1");
            model.Evaluate(instance, "complete2");

            Trace.Assert(model.IsComplete(instance));
        }