22from agents import Direction
33from agents import Agent
44from agents import ReflexVacuumAgent , ModelBasedVacuumAgent , TrivialVacuumEnvironment , compare_agents ,\
5- RandomVacuumAgent , TableDrivenVacuumAgent
5+ RandomVacuumAgent , TableDrivenVacuumAgent , TableDrivenAgentProgram , RandomAgentProgram
66
77
88random .seed ("aima-python" )
@@ -54,6 +54,21 @@ def test_add():
5454 assert l1 .direction == Direction .U
5555 assert l2 .direction == Direction .D
5656
57+ def test_RandomAgentProgram () :
58+ #create a list of all the actions a vacuum cleaner can perform
59+ list = ['Right' , 'Left' , 'Suck' , 'NoOp' ]
60+ # create a program and then an object of the RandomAgentProgram
61+ program = RandomAgentProgram (list )
62+
63+ agent = Agent (program )
64+ # create an object of TrivialVacuumEnvironment
65+ environment = TrivialVacuumEnvironment ()
66+ # add agent to the environment
67+ environment .add_thing (agent )
68+ # run the environment
69+ environment .run ()
70+ # check final status of the environment
71+ assert environment .status == {(1 , 0 ): 'Clean' , (0 , 0 ): 'Clean' }
5772
5873def test_RandomVacuumAgent () :
5974 # create an object of the RandomVacuumAgent
@@ -68,6 +83,34 @@ def test_RandomVacuumAgent() :
6883 assert environment .status == {(1 ,0 ):'Clean' , (0 ,0 ) : 'Clean' }
6984
7085
86+ def test_TableDrivenAgent () :
87+ #create a table that would consist of all the possible states of the agent
88+ loc_A , loc_B = (0 , 0 ), (1 , 0 )
89+
90+ table = {((loc_A , 'Clean' ),): 'Right' ,
91+ ((loc_A , 'Dirty' ),): 'Suck' ,
92+ ((loc_B , 'Clean' ),): 'Left' ,
93+ ((loc_B , 'Dirty' ),): 'Suck' ,
94+ ((loc_A , 'Dirty' ), (loc_A , 'Clean' )): 'Right' ,
95+ ((loc_A , 'Clean' ), (loc_B , 'Dirty' )): 'Suck' ,
96+ ((loc_B , 'Clean' ), (loc_A , 'Dirty' )): 'Suck' ,
97+ ((loc_B , 'Dirty' ), (loc_B , 'Clean' )): 'Left' ,
98+ ((loc_A , 'Dirty' ), (loc_A , 'Clean' ), (loc_B , 'Dirty' )): 'Suck' ,
99+ ((loc_B , 'Dirty' ), (loc_B , 'Clean' ), (loc_A , 'Dirty' )): 'Suck'
100+ }
101+ # create an program and then an object of the TableDrivenAgent
102+ program = TableDrivenAgentProgram (table )
103+ agent = Agent (program )
104+ # create an object of the TrivialVacuumEnvironment
105+ environment = TrivialVacuumEnvironment ()
106+ # add agent to the environment
107+ environment .add_thing (agent )
108+ # run the environment
109+ environment .run ()
110+ # check final status of the environment
111+ assert environment .status == {(1 , 0 ): 'Clean' , (0 , 0 ): 'Clean' }
112+
113+
71114def test_ReflexVacuumAgent () :
72115 # create an object of the ReflexVacuumAgent
73116 agent = ReflexVacuumAgent ()
0 commit comments