示例#1
0
文件: Shallow.cs 项目: rezn/state.cs
		public static void Test()
		{
			var machine = new Region( "history" );

			var initial = new PseudoState( "initial", PseudoStateKind.Initial, machine );
			var shallow = new CompositeState( "shallow", machine );
			var deep = new SimpleState( "deep", machine );
			var final = new FinalState( "final", machine );

			var s1 = new SimpleState( "s1", shallow );
			var s2 = new SimpleState( "s2", shallow );

			new Transition( initial, shallow );
			new Transition( new PseudoState( "shallow", PseudoStateKind.ShallowHistory, shallow ), s1 );
			new Transition<String>( s1, s2, c => c.Equals( "move" ) );
			new Transition<String>( shallow, deep, c => c.Equals( "go deep" ) );
			new Transition<String>( deep, shallow, c => c.Equals( "go shallow" ) );
			new Transition<String>( s2, final, c => c.Equals( "end" ) );

			var state = new State();

			machine.Initialise( state );

			Trace.Assert( machine.Process( state, "move" ) );
			Trace.Assert( machine.Process( state, "go deep" ) );
			Trace.Assert( machine.Process( state, "go shallow" ) );
			Trace.Assert( !machine.Process( state, "go shallow" ) );
			Trace.Assert( machine.Process( state, "end" ) );
			Trace.Assert( machine.IsComplete( state ) );
		}
示例#2
0
		public static void Test()
		{
			try
			{
				var main = new Region<State>( "muximise1" );

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

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

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

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

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

				new Transition<State>( initial, ortho );

				new Transition<State>( i1, s1 );
				new Transition<State>( i2, s2 );

				new Transition<State>( ortho, final ); // This should happen once all regions in ortho are complete?

				new Transition<State, String>( s1, f1, ( s, c ) => c == "complete1" );
				new Transition<State, String>( s2, f2, ( s, c ) => c == "complete2" );

				new Transition<State, String>( ortho, simple, ( s, c ) => c == "jump" );
				new Transition<State, String>( simple, ortho, ( s, c ) => c == "back" );

				var state = new State();

				main.Initialise( state );

				main.Process( state, "complete1" );
				main.Process( state, "complete2" );

				Trace.Assert( main.IsComplete( state ) );

			}
			catch( Exception x )
			{
				Trace.Fail( x.Message );
			}
		}