示例#1
0
 private static void ExecuteTests()
 {
     xCoord.unitTest();
     xAABB2.UnitTest();
     XEventsUnitTests.UnitTest();
     XStateMachineUnitTest.UnitTest();
 }
示例#2
0
        public static void UnitTest()
        {
            GameTime t = new GameTime();

            sUnitTest = new XStateMachineUnitTest();
            var sm = new XStateMachine <eTriggers>(eTriggers.None);

            //sm.Log( "empty" );

            txStateID s1 = sm.CreateState(null);

            sm.SetStartingState(s1);
            sm.Update(eTriggers.None);

            sm.CreateTransition(s1, s1, eTriggers.Jump, sUnitTest.Cb1);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            sm.CreateTransition(s1, s1, eTriggers.Poke, sUnitTest.Cb2);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            //Console.WriteLine( "test removal" );
            sm.RemoveTransition(s1, eTriggers.Jump);

            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            // sm.RemoveTransition( s1, eTriggers.Jump );  // correctly asserts missing trigger
            sm.RemoveTransition(s1, eTriggers.Poke);

            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);

            sm.RemoveState(s1, txStateID.kNone);

            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Poke);

            // sm.SetStartingState( txStateID.kNone );  // correctly asserts illegal starting state

            // sm.CreateTransition( s1, txStateID.kNone, sUnitTest.Cb2, eTriggers.Jump );  // asserts correctly s1 not found
            // sm.CreateTransition( txStateID.kNone, txStateID.kNone, sUnitTest.Cb2, eTriggers.Jump );  // asserts correctly kNone not found

            //Console.WriteLine( "testing non trivial transitions and static callbacks" );

            txStateID s2 = sm.CreateState(Cb3);
            txStateID s3 = sm.CreateState(sUnitTest.Cb2State);

            sm.SetStartingState(s2);

            sm.CreateTransition(s2, s3, eTriggers.Jump, sUnitTest.Cb1);
            sm.CreateTransition(s3, s2, eTriggers.Poke, sUnitTest.Cb1);

            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Poke);
            sm.Update(eTriggers.None);
            sm.ProcessTrigger(eTriggers.Jump);
            sm.ProcessTrigger(eTriggers.Poke);
            sm.Update(eTriggers.None);

            //sm.Log();

            //Console.WriteLine( "testing non trivial remove state" );

            // sm.RemoveState( s2, s2 );  // correctly asserts can't name same state
            sm.RemoveState(s2, s3);

            //sm.Log();

            //Console.WriteLine( "testing non trivial remove state, not the current" );

            txStateID s4 = sm.CreateState(sUnitTest.Cb2State);

            sm.CreateTransition(s3, s4, eTriggers.Poke, sUnitTest.Cb1);
            sm.CreateTransition(s4, s3, eTriggers.Poke, sUnitTest.Cb1);

            //sm.Log();

            sm.RemoveState(s4, s3);

            //sm.Log();
        }