state pattern thatfor given inputthe machine transitions to the correct subsequent state python includes very solid unit-testing frameworknot surprisingly called unittest to test our generic state machinewe could use the following codeimport unittest class genericstatepatterntest(unittest testcase)def setup(self)self state_machine statemachine(def teardown(self)pass def test_state_machine_initializes_correctly(self)self assertisinstance(self state_machine stateconcretestate def test_switch_from_state_ _to_state_ (self)self state_machine switch(self assertisinstance(self state_machine stateconcretestate def test_switch_from_state _to_state (self)self state_machine switch(self state_machine switch(self assertisinstance(self state_machine stateconcretestate if __name__ ='__main__'unittest main(play around with the options for asserts and see what other interesting tests you can come up with we will now return to the problem of the player character either running or walkingas we discussed in the beginning of this we will implement the same functionality from beforebut this time we will use the state pattern