コード例 #1
0
ファイル: test_fsm_agent.py プロジェクト: lbkelly/j_acezero
    def test_single_transition_multiple_active_states(self):
        """ Tests that a single transition is executed when there are multiple
        active states. """
        class State1(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State3

        class State2(StateAgent):
            pass

        class State3(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State1

        state1 = State1()
        state2 = State2()
        state3 = State3()

        agent = StateAgent([state1, state3, state2], initial=[State1, State2])
        self.assertItemsEqual(agent.active_states, [state1, state2])

        # Trigger transition request in State1 then check transition to State3
        agent.process_state(0, 0)
        self.assertItemsEqual(agent.active_states, [state2, state3])

        # Trigger transition request in State3 then check transition to State1
        agent.process_state(0, 0)
        self.assertItemsEqual(agent.active_states, [state2, state1])
コード例 #2
0
ファイル: test_fsm_agent.py プロジェクト: lbkelly/j_acezero
    def test_multiple_transitions(self):
        """ Tests that multiple transitions can be executed at once. """
        class State1(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State2

        class State2(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State3

        class State3(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State4

        class State4(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State1

        state1 = State1()
        state2 = State2()
        state3 = State3()
        state4 = State4()

        agent = StateAgent([state1, state3, state2, state4],
                           initial=[State1, State3])
        self.assertItemsEqual(agent.active_states, [state1, state3])

        # Trigger transition request in both State1 and State3
        agent.process_state(0, 0)
        self.assertItemsEqual(agent.active_states, [state2, state4])

        # Trigger transition request in State2 and State4 and check transition
        agent.process_state(0, 0)
        self.assertItemsEqual(agent.active_states, [state1, state3])
コード例 #3
0
ファイル: test_fsm_agent.py プロジェクト: lbkelly/j_acezero
    def test_single_transition_single_active_state(self):
        """ Tests that states can request transitions successfully. """
        class State1(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State3

        class State2(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State1

        class State3(StateAgent):
            def process_state(self, t, dt):
                StateAgent.process_state(self, t, dt)
                self.transition_request = State2

        state1 = State1()
        state2 = State2()
        state3 = State3()

        agent = StateAgent([state2, state3, state1])
        self.assertEqual(agent.active_states, [state2])

        # Trigger transition request in State2 then check transition to State1
        agent.process_state(0, 0)
        self.assertEqual(agent.active_states, [state1])

        # Trigger transition request in State1 then check transition to State3
        agent.process_state(0, 0)
        self.assertEqual(agent.active_states, [state3])

        # Trigger transition request in State3 then check transition to State2
        agent.process_state(0, 0)
        self.assertEqual(agent.active_states, [state2])

        # Trigger another transition request in State2
        agent.process_state(0, 0)
        self.assertEqual(agent.active_states, [state1])
コード例 #4
0
ファイル: test_fsm_agent.py プロジェクト: lbkelly/j_acezero
 def process_state(self, t, dt):
     StateAgent.process_state(self, t, dt)
     self.transition_request = State3